Skip to content

Commit bf24db5

Browse files
committed
feat(macie-account): support aws v6
1 parent 88a88a6 commit bf24db5

File tree

6 files changed

+57
-27
lines changed

6 files changed

+57
-27
lines changed

modules/macie-account/README.md

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,20 @@ This module creates following resources.
1111

1212
| Name | Version |
1313
|------|---------|
14-
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.5 |
15-
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 4.14 |
14+
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.12 |
15+
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 6.12 |
1616

1717
## Providers
1818

1919
| Name | Version |
2020
|------|---------|
21-
| <a name="provider_aws"></a> [aws](#provider\_aws) | 5.48.0 |
21+
| <a name="provider_aws"></a> [aws](#provider\_aws) | 6.13.0 |
2222

2323
## Modules
2424

2525
| Name | Source | Version |
2626
|------|--------|---------|
27-
| <a name="module_resource_group"></a> [resource\_group](#module\_resource\_group) | tedilabs/misc/aws//modules/resource-group | ~> 0.10.0 |
27+
| <a name="module_resource_group"></a> [resource\_group](#module\_resource\_group) | tedilabs/misc/aws//modules/resource-group | ~> 0.12.0 |
2828

2929
## Resources
3030

@@ -39,13 +39,12 @@ This module creates following resources.
3939

4040
| Name | Description | Type | Default | Required |
4141
|------|-------------|------|---------|:--------:|
42-
| <a name="input_discovery_result_repository"></a> [discovery\_result\_repository](#input\_discovery\_result\_repository) | (Optional) The configuration for discovery result location and encryption of the macie account. A `discovery_result_repository` block as defined below.<br> (Optional) `s3_bucket` - A configuration for the S3 bucket in which Amazon Macie exports the data discovery results. `s3_bucket` as defined below.<br> (Required) `name` - The name of the S3 bucket in which Amazon Macie exports the data classification results.<br> (Optional) `key_prefix` - The key prefix for the specified S3 bucket.<br> (Required) `sse_kms_key` - The ARN of the AWS KMS key to be used to encrypt the data. | <pre>object({<br> s3_bucket = optional(object({<br> name = string<br> key_prefix = optional(string, "")<br> sse_kms_key = string<br> }))<br> })</pre> | `{}` | no |
42+
| <a name="input_discovery_result_repository"></a> [discovery\_result\_repository](#input\_discovery\_result\_repository) | (Optional) The configuration for discovery result location and encryption of the macie account. A `discovery_result_repository` block as defined below.<br/> (Optional) `s3_bucket` - A configuration for the S3 bucket in which Amazon Macie exports the data discovery results. `s3_bucket` as defined below.<br/> (Required) `name` - The name of the S3 bucket in which Amazon Macie exports the data classification results.<br/> (Optional) `key_prefix` - The key prefix for the specified S3 bucket.<br/> (Required) `sse_kms_key` - The ARN of the AWS KMS key to be used to encrypt the data. | <pre>object({<br/> s3_bucket = optional(object({<br/> name = string<br/> key_prefix = optional(string, "")<br/> sse_kms_key = string<br/> }))<br/> })</pre> | `{}` | no |
4343
| <a name="input_enabled"></a> [enabled](#input\_enabled) | (Optional) Whether to enable Amazon Macie and start all Macie activities for the account. Defaults to `true`. Set `false` to suspend Macie, it stops monitoring your AWS environment and does not generate new findings. The existing findings remain intact and are not affected. Delete `aws_macie2_account` resource to disable Macie, it permanently deletes all of your existing findings, classification jobs, and other Macie resources. | `bool` | `true` | no |
44-
| <a name="input_member_accounts"></a> [member\_accounts](#input\_member\_accounts) | (Optional) A list of configurations for member accounts on the macie account. Each block of `member_accounts` as defined below.<br> (Required) `account_id` - The AWS account ID for the account.<br> (Required) `email` - The email address for the account.<br> (Optional) `enabled` - Whether to enable Amazon Macie and start all Macie activities for the member account. Defaults to `true`.<br> (Optional) `tags` - A map of key-value pairs that specifies the tags to associate with the account in Amazon Macie. | <pre>list(object({<br> account_id = string<br> email = string<br> enabled = optional(bool, true)<br> tags = optional(map(string), {})<br> }))</pre> | `[]` | no |
44+
| <a name="input_member_accounts"></a> [member\_accounts](#input\_member\_accounts) | (Optional) A list of configurations for member accounts on the macie account. Each block of `member_accounts` as defined below.<br/> (Required) `account_id` - The AWS account ID for the account.<br/> (Required) `email` - The email address for the account.<br/> (Optional) `type` - The type of the member account. Valid values are `ORGANIZATION` or `INVITATION`. Defaults to `ORGANIZATION`.<br/> (Optional) `enabled` - Whether to enable Amazon Macie and start all Macie activities for the member account. Defaults to `true`.<br/> (Optional) `tags` - A map of key-value pairs that specifies the tags to associate with the account in Amazon Macie.<br/> (Optional) `invitation` - A configuration for invitation to the member account. `invitation` as defined below.<br/> (Optional) `message` - A custom message to include in the invitation to the account.<br/> (Optional) `email_notification_enabled` - Whether to send an email notification to the account when you invite it to become a member of your Macie account. This notification is in addition to an alert that the root user receives in AWS Personal Health Dashboard. Defaults to `false`. | <pre>list(object({<br/> account_id = string<br/> email = string<br/> type = optional(string, "ORGANIZATION")<br/> enabled = optional(bool, true)<br/> tags = optional(map(string), {})<br/> invitation = optional(object({<br/> message = optional(string, "")<br/> email_notification_enabled = optional(bool, false)<br/> }), {})<br/> }))</pre> | `[]` | no |
4545
| <a name="input_module_tags_enabled"></a> [module\_tags\_enabled](#input\_module\_tags\_enabled) | (Optional) Whether to create AWS Resource Tags for the module informations. | `bool` | `true` | no |
46-
| <a name="input_resource_group_description"></a> [resource\_group\_description](#input\_resource\_group\_description) | (Optional) The description of Resource Group. | `string` | `"Managed by Terraform."` | no |
47-
| <a name="input_resource_group_enabled"></a> [resource\_group\_enabled](#input\_resource\_group\_enabled) | (Optional) Whether to create Resource Group to find and group AWS resources which are created by this module. | `bool` | `true` | no |
48-
| <a name="input_resource_group_name"></a> [resource\_group\_name](#input\_resource\_group\_name) | (Optional) The name of Resource Group. A Resource Group name can have a maximum of 127 characters, including letters, numbers, hyphens, dots, and underscores. The name cannot start with `AWS` or `aws`. | `string` | `""` | no |
46+
| <a name="input_region"></a> [region](#input\_region) | (Optional) The region in which to create the module resources. If not provided, the module resources will be created in the provider's configured region. | `string` | `null` | no |
47+
| <a name="input_resource_group"></a> [resource\_group](#input\_resource\_group) | (Optional) A configurations of Resource Group for this module. `resource_group` as defined below.<br/> (Optional) `enabled` - Whether to create Resource Group to find and group AWS resources which are created by this module. Defaults to `true`.<br/> (Optional) `name` - The name of Resource Group. A Resource Group name can have a maximum of 127 characters, including letters, numbers, hyphens, dots, and underscores. The name cannot start with `AWS` or `aws`. If not provided, a name will be generated using the module name and instance name.<br/> (Optional) `description` - The description of Resource Group. Defaults to `Managed by Terraform.`. | <pre>object({<br/> enabled = optional(bool, true)<br/> name = optional(string, "")<br/> description = optional(string, "Managed by Terraform.")<br/> })</pre> | `{}` | no |
4948
| <a name="input_tags"></a> [tags](#input\_tags) | (Optional) A map of tags to add to all resources. | `map(string)` | `{}` | no |
5049
| <a name="input_update_frequency"></a> [update\_frequency](#input\_update\_frequency) | (Optional) How often to publish updates to policy findings for the account. This includes publishing updates to AWS Security Hub and Amazon EventBridge (formerly called Amazon CloudWatch Events). Valid values are `15m`, `1h` or `6h`. Defaults to `15m`. | `string` | `"15m"` | no |
5150

@@ -59,6 +58,8 @@ This module creates following resources.
5958
| <a name="output_id"></a> [id](#output\_id) | The ID of the macie account. |
6059
| <a name="output_member_accounts"></a> [member\_accounts](#output\_member\_accounts) | The list of configruations for member accounts on the macie account. |
6160
| <a name="output_name"></a> [name](#output\_name) | The account ID of the macie account. |
61+
| <a name="output_region"></a> [region](#output\_region) | The AWS region this module resources resides in. |
62+
| <a name="output_resource_group"></a> [resource\_group](#output\_resource\_group) | The resource group created to manage resources in this module. |
6263
| <a name="output_service_role"></a> [service\_role](#output\_service\_role) | The Amazon Resource Name (ARN) of the service-linked role that allows Macie to monitor and analyze data in AWS resources for the account. |
6364
| <a name="output_update_frequency"></a> [update\_frequency](#output\_update\_frequency) | How often to publish updates to policy findings for the macie account. |
6465
| <a name="output_updated_at"></a> [updated\_at](#output\_updated\_at) | The date and time, in UTC and extended RFC 3339 format, of the most recent change to the status of the Macie account. |

modules/macie-account/main.tf

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,15 @@ locals {
2424
}
2525
}
2626

27+
2728
###################################################
2829
# Macie Account
2930
###################################################
3031

3132
resource "aws_macie2_account" "this" {
32-
status = var.enabled ? "ENABLED" : "PAUSED"
33+
region = var.region
3334

35+
status = var.enabled ? "ENABLED" : "PAUSED"
3436
finding_publishing_frequency = local.update_frequency[var.update_frequency]
3537
}
3638

@@ -51,15 +53,17 @@ resource "aws_macie2_member" "this" {
5153
account.account_id => account
5254
}
5355

56+
region = aws_macie2_account.this.region
57+
5458
account_id = each.key
5559
email = each.value.email
56-
status = try(each.value.enabled, true) ? "ENABLED" : "PAUSED"
60+
status = each.value.enabled ? "ENABLED" : "PAUSED"
5761

5862

5963
## Invitation
60-
# invite = true
61-
# invitation_message = "Message of the invitation"
62-
# invitation_disable_email_notification = true
64+
invite = each.value.type == "INVITATION" ? true : null
65+
invitation_message = each.value.invitation.message
66+
invitation_disable_email_notification = !each.value.invitation.email_notification_enabled
6367

6468

6569
tags = merge(
@@ -78,10 +82,6 @@ resource "aws_macie2_member" "this" {
7882
email,
7983
]
8084
}
81-
82-
depends_on = [
83-
aws_macie2_account.this
84-
]
8585
}
8686

8787

@@ -92,13 +92,11 @@ resource "aws_macie2_member" "this" {
9292
resource "aws_macie2_classification_export_configuration" "this" {
9393
count = var.discovery_result_repository.s3_bucket != null ? 1 : 0
9494

95+
region = aws_macie2_account.this.region
96+
9597
s3_destination {
9698
bucket_name = var.discovery_result_repository.s3_bucket.name
9799
key_prefix = var.discovery_result_repository.s3_bucket.key_prefix
98100
kms_key_arn = var.discovery_result_repository.s3_bucket.sse_kms_key
99101
}
100-
101-
depends_on = [
102-
aws_macie2_account.this,
103-
]
104102
}

modules/macie-account/outputs.tf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
output "region" {
2+
description = "The AWS region this module resources resides in."
3+
value = aws_macie2_account.this.region
4+
}
5+
16
output "id" {
27
description = "The ID of the macie account."
38
value = aws_macie2_account.this.id
@@ -46,9 +51,11 @@ output "member_accounts" {
4651
id = account.id
4752
arn = account.arn
4853
email = account.email
54+
type = timecmp(account.invited_at, "1999-01-01T00:00:00Z") < 0 ? "ORGANIZATION" : "INVITATION"
4955
enabled = account.status == "ENABLED"
5056
relationship_status = account.relationship_status
5157

58+
invited_at = timecmp(account.invited_at, "1999-01-01T00:00:00Z") < 0 ? null : account.invited_at
5259
updated_at = account.updated_at
5360
}
5461
}

modules/macie-account/resource-group.tf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ module "resource_group" {
1616

1717
count = (var.resource_group.enabled && var.module_tags_enabled) ? 1 : 0
1818

19+
region = var.region
20+
1921
name = local.resource_group_name
2022
description = var.resource_group.description
2123

modules/macie-account/variables.tf

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
variable "region" {
2+
description = "(Optional) The region in which to create the module resources. If not provided, the module resources will be created in the provider's configured region."
3+
type = string
4+
default = null
5+
nullable = true
6+
}
7+
18
variable "enabled" {
29
description = "(Optional) Whether to enable Amazon Macie and start all Macie activities for the account. Defaults to `true`. Set `false` to suspend Macie, it stops monitoring your AWS environment and does not generate new findings. The existing findings remain intact and are not affected. Delete `aws_macie2_account` resource to disable Macie, it permanently deletes all of your existing findings, classification jobs, and other Macie resources."
310
type = bool
@@ -22,17 +29,35 @@ variable "member_accounts" {
2229
(Optional) A list of configurations for member accounts on the macie account. Each block of `member_accounts` as defined below.
2330
(Required) `account_id` - The AWS account ID for the account.
2431
(Required) `email` - The email address for the account.
32+
(Optional) `type` - The type of the member account. Valid values are `ORGANIZATION` or `INVITATION`. Defaults to `ORGANIZATION`.
2533
(Optional) `enabled` - Whether to enable Amazon Macie and start all Macie activities for the member account. Defaults to `true`.
2634
(Optional) `tags` - A map of key-value pairs that specifies the tags to associate with the account in Amazon Macie.
35+
(Optional) `invitation` - A configuration for invitation to the member account. `invitation` as defined below.
36+
(Optional) `message` - A custom message to include in the invitation to the account.
37+
(Optional) `email_notification_enabled` - Whether to send an email notification to the account when you invite it to become a member of your Macie account. This notification is in addition to an alert that the root user receives in AWS Personal Health Dashboard. Defaults to `false`.
2738
EOF
2839
type = list(object({
2940
account_id = string
3041
email = string
42+
type = optional(string, "ORGANIZATION")
3143
enabled = optional(bool, true)
3244
tags = optional(map(string), {})
45+
invitation = optional(object({
46+
message = optional(string, "")
47+
email_notification_enabled = optional(bool, false)
48+
}), {})
3349
}))
3450
default = []
3551
nullable = false
52+
53+
validation {
54+
condition = alltrue([
55+
for member in var.member_accounts :
56+
contains(["ORGANIZATION", "INVITATION"], member.type)
57+
])
58+
59+
error_message = "Valid values for `type` in `member_accounts` are `ORGANIZATION` or `INVITATION`."
60+
}
3661
}
3762

3863
variable "discovery_result_repository" {
@@ -73,9 +98,6 @@ variable "module_tags_enabled" {
7398
# Resource Group
7499
###################################################
75100

76-
77-
78-
79101
variable "resource_group" {
80102
description = <<EOF
81103
(Optional) A configurations of Resource Group for this module. `resource_group` as defined below.

modules/macie-account/versions.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
terraform {
2-
required_version = ">= 1.5"
2+
required_version = ">= 1.12"
33

44
required_providers {
55
aws = {
66
source = "hashicorp/aws"
7-
version = ">= 4.14"
7+
version = ">= 6.12"
88
}
99
}
1010
}

0 commit comments

Comments
 (0)