Skip to content

Commit ab1a710

Browse files
authored
Improve macie-account module (#49)
1 parent b97717a commit ab1a710

File tree

4 files changed

+56
-32
lines changed

4 files changed

+56
-32
lines changed

modules/macie-account/README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ This module creates following resources.
1818

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

2323
## Modules
2424

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

4040
| Name | Description | Type | Default | Required |
4141
|------|-------------|------|---------|:--------:|
42-
| <a name="input_discovery_result"></a> [discovery\_result](#input\_discovery\_result) | (Optional) The configuration for discovery result location and encryption of the macie account. A `discovery_result` block as defined below.<br> (Required) `s3_bucket` - The name of the S3 bucket in which Amazon Macie exports the data discovery result.<br> (Optional) `s3_key_prefix` - The key prefix for the specified S3 bucket. Defaults to `""`.<br> (Required) `encryption_kms_key` - The Amazon Resource Name (ARN) of the KMS key to be used to encrypt the data. | `map(any)` | `null` | 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` -<br> (Required) `email` -<br> (Optional) `enabled` - Whether to enable Amazon Macie and start all Macie activities for the member account.<br> (Optional) `tags` - A map of key-value pairs that specifies the tags to associate with the account in Amazon Macie. | `any` | `[]` | 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 |
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 |
4646
| <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 |
4747
| <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 |
@@ -54,6 +54,7 @@ This module creates following resources.
5454
| Name | Description |
5555
|------|-------------|
5656
| <a name="output_created_at"></a> [created\_at](#output\_created\_at) | The date and time, in UTC and extended RFC 3339 format, when the Amazon Macie account was created. |
57+
| <a name="output_discovery_result_repository"></a> [discovery\_result\_repository](#output\_discovery\_result\_repository) | The configuration for discovery result location and encryption of the macie account. |
5758
| <a name="output_enabled"></a> [enabled](#output\_enabled) | Whether the macie account is eanbled. |
5859
| <a name="output_id"></a> [id](#output\_id) | The ID of the macie account. |
5960
| <a name="output_member_accounts"></a> [member\_accounts](#output\_member\_accounts) | The list of configruations for member accounts on the macie account. |

modules/macie-account/main.tf

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ resource "aws_macie2_account" "this" {
4141

4242
# TODO: Cannot delete member account from AWS Organization
4343
# https://github.com/hashicorp/terraform-provider-aws/issues/26219
44+
# INFO: Not supported attributes
45+
# - `invite`
46+
# - `invitation_message`
47+
# - `invitation_disable_email_notification`
4448
resource "aws_macie2_member" "this" {
4549
for_each = {
4650
for account in var.member_accounts :
@@ -51,11 +55,13 @@ resource "aws_macie2_member" "this" {
5155
email = each.value.email
5256
status = try(each.value.enabled, true) ? "ENABLED" : "PAUSED"
5357

58+
5459
## Invitation
5560
# invite = true
5661
# invitation_message = "Message of the invitation"
5762
# invitation_disable_email_notification = true
5863

64+
5965
tags = merge(
6066
{
6167
"Name" = each.key
@@ -84,12 +90,12 @@ resource "aws_macie2_member" "this" {
8490
###################################################
8591

8692
resource "aws_macie2_classification_export_configuration" "this" {
87-
count = var.discovery_result != null ? 1 : 0
93+
count = var.discovery_result_repository.s3_bucket != null ? 1 : 0
8894

8995
s3_destination {
90-
bucket_name = var.discovery_result.s3_bucket
91-
key_prefix = try(var.discovery_result.s3_key_prefix, "")
92-
kms_key_arn = var.discovery_result.encryption_kms_key
96+
bucket_name = var.discovery_result_repository.s3_bucket.name
97+
key_prefix = var.discovery_result_repository.s3_bucket.key_prefix
98+
kms_key_arn = var.discovery_result_repository.s3_bucket.sse_kms_key
9399
}
94100

95101
depends_on = [

modules/macie-account/outputs.tf

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -43,18 +43,22 @@ output "member_accounts" {
4343
value = {
4444
for id, account in aws_macie2_member.this :
4545
id => {
46-
id = account.id
47-
arn = account.arn
48-
email = account.email
49-
enabled = account.status == "ENABLED"
46+
id = account.id
47+
arn = account.arn
48+
email = account.email
49+
enabled = account.status == "ENABLED"
50+
relationship_status = account.relationship_status
51+
52+
updated_at = account.updated_at
5053
}
5154
}
5255
}
5356

54-
# TODO
55-
# output "discovery_result" {
56-
# description = <<EOF
57-
# The configuration for discovery result location and encryption of the macie account.
58-
# EOF
59-
# value = aws_macie2_classification_export_configuration.this
60-
# }
57+
output "discovery_result_repository" {
58+
description = <<EOF
59+
The configuration for discovery result location and encryption of the macie account.
60+
EOF
61+
value = {
62+
s3_bucket = var.discovery_result_repository.s3_bucket
63+
}
64+
}

modules/macie-account/variables.tf

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,27 +20,40 @@ variable "update_frequency" {
2020
variable "member_accounts" {
2121
description = <<EOF
2222
(Optional) A list of configurations for member accounts on the macie account. Each block of `member_accounts` as defined below.
23-
(Required) `account_id` -
24-
(Required) `email` -
25-
(Optional) `enabled` - Whether to enable Amazon Macie and start all Macie activities for the member account.
23+
(Required) `account_id` - The AWS account ID for the account.
24+
(Required) `email` - The email address for the account.
25+
(Optional) `enabled` - Whether to enable Amazon Macie and start all Macie activities for the member account. Defaults to `true`.
2626
(Optional) `tags` - A map of key-value pairs that specifies the tags to associate with the account in Amazon Macie.
2727
EOF
28-
type = any
29-
default = []
30-
nullable = false
28+
type = list(object({
29+
account_id = string
30+
email = string
31+
enabled = optional(bool, true)
32+
tags = optional(map(string), {})
33+
}))
34+
default = []
35+
nullable = false
3136
}
3237

33-
34-
variable "discovery_result" {
38+
variable "discovery_result_repository" {
3539
description = <<EOF
36-
(Optional) The configuration for discovery result location and encryption of the macie account. A `discovery_result` block as defined below.
37-
(Required) `s3_bucket` - The name of the S3 bucket in which Amazon Macie exports the data discovery result.
38-
(Optional) `s3_key_prefix` - The key prefix for the specified S3 bucket. Defaults to `""`.
39-
(Required) `encryption_kms_key` - The Amazon Resource Name (ARN) of the KMS key to be used to encrypt the data.
40+
(Optional) The configuration for discovery result location and encryption of the macie account. A `discovery_result_repository` block as defined below.
41+
(Optional) `s3_bucket` - A configuration for the S3 bucket in which Amazon Macie exports the data discovery results. `s3_bucket` as defined below.
42+
(Required) `name` - The name of the S3 bucket in which Amazon Macie exports the data classification results.
43+
(Optional) `key_prefix` - The key prefix for the specified S3 bucket.
44+
(Required) `sse_kms_key` - The ARN of the AWS KMS key to be used to encrypt the data.
4045
EOF
41-
type = map(any)
42-
default = null
46+
type = object({
47+
s3_bucket = optional(object({
48+
name = string
49+
key_prefix = optional(string, "")
50+
sse_kms_key = string
51+
}))
52+
})
53+
default = {}
54+
nullable = false
4355
}
56+
4457
variable "tags" {
4558
description = "(Optional) A map of tags to add to all resources."
4659
type = map(string)

0 commit comments

Comments
 (0)