Skip to content

Commit d67b195

Browse files
committed
feat(macie-custom-data-identifier): add new module
1 parent ba937ac commit d67b195

File tree

9 files changed

+311
-0
lines changed

9 files changed

+311
-0
lines changed

.github/labeler.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,8 @@
2828
- changed-files:
2929
- any-glob-to-any-file:
3030
- modules/macie-account/**/*
31+
32+
":floppy_disk: macie-custom-data-identifier":
33+
- changed-files:
34+
- any-glob-to-any-file:
35+
- modules/macie-custom-data-identifier/**/*

.github/labels.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,6 @@
5858
- color: "fbca04"
5959
description: "This issue or pull request is related to macie-account module."
6060
name: ":floppy_disk: macie-account"
61+
- color: "fbca04"
62+
description: "This issue or pull request is related to macie-custom-data-identifier module."
63+
name: ":floppy_disk: macie-custom-data-identifier"

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Terraform module which creates security related resources on AWS.
1212
- [config-managed-rule](./modules/config-managed-rule)
1313
- [config-recorder](./modules/config-recorder)
1414
- [macie-account](./modules/macie-account)
15+
- [macie-custom-data-identifier](./modules/macie-custom-data-identifier)
1516

1617

1718
## Target AWS Services
@@ -29,6 +30,9 @@ Terraform Modules from [this package](https://github.com/tedilabs/terraform-aws-
2930
- Managed Rules
3031
- **AWS Macie**
3132
- Account
33+
- Member Accounts
34+
- Organization Configurations
35+
- Custom Data Identifier
3236

3337

3438
## Usage
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# macie-custom-data-identifier
2+
3+
This module creates following resources.
4+
5+
- `aws_macie2_custom_data_identifier`
6+
7+
<!-- BEGIN_TF_DOCS -->
8+
## Requirements
9+
10+
| Name | Version |
11+
|------|---------|
12+
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.12 |
13+
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 6.12 |
14+
15+
## Providers
16+
17+
| Name | Version |
18+
|------|---------|
19+
| <a name="provider_aws"></a> [aws](#provider\_aws) | 6.13.0 |
20+
21+
## Modules
22+
23+
| Name | Source | Version |
24+
|------|--------|---------|
25+
| <a name="module_resource_group"></a> [resource\_group](#module\_resource\_group) | tedilabs/misc/aws//modules/resource-group | ~> 0.12.0 |
26+
27+
## Resources
28+
29+
| Name | Type |
30+
|------|------|
31+
| [aws_macie2_custom_data_identifier.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/macie2_custom_data_identifier) | resource |
32+
33+
## Inputs
34+
35+
| Name | Description | Type | Default | Required |
36+
|------|-------------|------|---------|:--------:|
37+
| <a name="input_name"></a> [name](#input\_name) | (Required) A name for the custom data identifier. The name can contain as many as 128 characters. | `string` | n/a | yes |
38+
| <a name="input_regex"></a> [regex](#input\_regex) | (Required) The regular expression (regex) that defines the pattern to match. The expression can contain as many as 512 characters. | `string` | n/a | yes |
39+
| <a name="input_description"></a> [description](#input\_description) | (Optional) A description of the custom data identifier. Defaults to `Managed by Terraform.`. | `string` | `"Managed by Terraform."` | no |
40+
| <a name="input_ignore_words"></a> [ignore\_words](#input\_ignore\_words) | (Optional) An array that lists specific character sequences (ignore words) to exclude from the results. If the text matched by the regular expression is the same as any string in this array, Amazon Macie ignores it. The array can contain as many as 10 ignore words. Each ignore word can contain 4 - 90 characters. Ignore words are case sensitive. | `set(string)` | `[]` | no |
41+
| <a name="input_keywords"></a> [keywords](#input\_keywords) | (Optional) An array that lists specific character sequences (keywords), one of which must be within proximity (maximum\_match\_distance) of the regular expression to match. The array can contain as many as 50 keywords. Each keyword can contain 3 - 90 characters. Keywords aren't case sensitive. | `set(string)` | `[]` | no |
42+
| <a name="input_maximum_match_distance"></a> [maximum\_match\_distance](#input\_maximum\_match\_distance) | (Optional) The maximum allowable distance between text that matches the regex pattern and the keywords. The distance can be 1 - 300 characters. Defaults to `50`. | `number` | `50` | no |
43+
| <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 |
44+
| <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 |
45+
| <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 |
46+
| <a name="input_tags"></a> [tags](#input\_tags) | (Optional) A map of tags to add to all resources. | `map(string)` | `{}` | no |
47+
48+
## Outputs
49+
50+
| Name | Description |
51+
|------|-------------|
52+
| <a name="output_arn"></a> [arn](#output\_arn) | The ARN (Amazon Resource Name) for the macie custom data identifier. For example: `arn:aws:cloudfront::123456789012:distribution/EDFDVBD632BHDS5`. |
53+
| <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 custom data identifier was created. |
54+
| <a name="output_description"></a> [description](#output\_description) | The description of the macie custom data identifier. |
55+
| <a name="output_id"></a> [id](#output\_id) | The ID of the macie custom data identifier. |
56+
| <a name="output_ignore_words"></a> [ignore\_words](#output\_ignore\_words) | An array that lists specific character sequences (ignore words) to exclude from the results. |
57+
| <a name="output_keywords"></a> [keywords](#output\_keywords) | An array that lists specific character sequences (keywords), one of which must be within proximity (maximum\_match\_distance) of the regular expression to match. |
58+
| <a name="output_maximum_match_distance"></a> [maximum\_match\_distance](#output\_maximum\_match\_distance) | The maximum number of characters that can exist between text that matches the regex pattern and the character sequences specified by the keywords array. |
59+
| <a name="output_name"></a> [name](#output\_name) | The name of the macie custom data identifier. |
60+
| <a name="output_regex"></a> [regex](#output\_regex) | The regular expression (regex) that defines the pattern to match. |
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. |
63+
<!-- END_TF_DOCS -->
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
locals {
2+
metadata = {
3+
package = "terraform-aws-security"
4+
version = trimspace(file("${path.module}/../../VERSION"))
5+
module = basename(path.module)
6+
name = var.name
7+
}
8+
module_tags = var.module_tags_enabled ? {
9+
"module.terraform.io/package" = local.metadata.package
10+
"module.terraform.io/version" = local.metadata.version
11+
"module.terraform.io/name" = local.metadata.module
12+
"module.terraform.io/full-name" = "${local.metadata.package}/${local.metadata.module}"
13+
"module.terraform.io/instance" = local.metadata.name
14+
} : {}
15+
}
16+
17+
18+
###################################################
19+
# Custom Data Identifier for Macie Account
20+
###################################################
21+
22+
# INFO: Not supported attributes
23+
# - `name_prefix`
24+
resource "aws_macie2_custom_data_identifier" "this" {
25+
region = var.region
26+
27+
name = var.name
28+
description = var.description
29+
30+
regex = var.regex
31+
keywords = length(var.keywords) > 0 ? var.keywords : null
32+
ignore_words = length(var.ignore_words) > 0 ? var.ignore_words : null
33+
maximum_match_distance = var.maximum_match_distance
34+
35+
tags = merge(
36+
{
37+
"Name" = local.metadata.name
38+
},
39+
local.module_tags,
40+
var.tags,
41+
)
42+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
output "region" {
2+
description = "The AWS region this module resources resides in."
3+
value = aws_macie2_custom_data_identifier.this.region
4+
}
5+
6+
output "arn" {
7+
description = "The ARN (Amazon Resource Name) for the macie custom data identifier. For example: `arn:aws:cloudfront::123456789012:distribution/EDFDVBD632BHDS5`."
8+
value = aws_macie2_custom_data_identifier.this.arn
9+
}
10+
11+
output "id" {
12+
description = "The ID of the macie custom data identifier."
13+
value = aws_macie2_custom_data_identifier.this.id
14+
}
15+
16+
output "name" {
17+
description = "The name of the macie custom data identifier."
18+
value = local.metadata.name
19+
}
20+
21+
output "description" {
22+
description = "The description of the macie custom data identifier."
23+
value = aws_macie2_custom_data_identifier.this.description
24+
}
25+
26+
output "regex" {
27+
description = "The regular expression (regex) that defines the pattern to match."
28+
value = aws_macie2_custom_data_identifier.this.regex
29+
}
30+
31+
output "keywords" {
32+
description = "An array that lists specific character sequences (keywords), one of which must be within proximity (maximum_match_distance) of the regular expression to match."
33+
value = aws_macie2_custom_data_identifier.this.keywords
34+
}
35+
36+
output "ignore_words" {
37+
description = "An array that lists specific character sequences (ignore words) to exclude from the results."
38+
value = aws_macie2_custom_data_identifier.this.ignore_words
39+
}
40+
41+
output "maximum_match_distance" {
42+
description = "The maximum number of characters that can exist between text that matches the regex pattern and the character sequences specified by the keywords array."
43+
value = aws_macie2_custom_data_identifier.this.maximum_match_distance
44+
}
45+
46+
output "created_at" {
47+
description = "The date and time, in UTC and extended RFC 3339 format, when the Amazon Macie custom data identifier was created."
48+
value = aws_macie2_custom_data_identifier.this.created_at
49+
}
50+
51+
output "resource_group" {
52+
description = "The resource group created to manage resources in this module."
53+
value = merge(
54+
{
55+
enabled = var.resource_group.enabled && var.module_tags_enabled
56+
},
57+
(var.resource_group.enabled && var.module_tags_enabled
58+
? {
59+
arn = module.resource_group[0].arn
60+
name = module.resource_group[0].name
61+
}
62+
: {}
63+
)
64+
)
65+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
locals {
2+
resource_group_name = (var.resource_group.name != ""
3+
? var.resource_group.name
4+
: join(".", [
5+
local.metadata.package,
6+
local.metadata.module,
7+
replace(local.metadata.name, "/[^a-zA-Z0-9_\\.-]/", "-"),
8+
])
9+
)
10+
}
11+
12+
13+
module "resource_group" {
14+
source = "tedilabs/misc/aws//modules/resource-group"
15+
version = "~> 0.12.0"
16+
17+
count = (var.resource_group.enabled && var.module_tags_enabled) ? 1 : 0
18+
19+
region = var.region
20+
21+
name = local.resource_group_name
22+
description = var.resource_group.description
23+
24+
query = {
25+
resource_tags = local.module_tags
26+
}
27+
28+
module_tags_enabled = false
29+
tags = merge(
30+
local.module_tags,
31+
var.tags,
32+
)
33+
}
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
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+
8+
variable "name" {
9+
description = "(Required) A name for the custom data identifier. The name can contain as many as 128 characters."
10+
type = string
11+
nullable = false
12+
}
13+
14+
variable "description" {
15+
description = "(Optional) A description of the custom data identifier. Defaults to `Managed by Terraform.`."
16+
type = string
17+
default = "Managed by Terraform."
18+
nullable = false
19+
}
20+
21+
variable "regex" {
22+
description = "(Required) The regular expression (regex) that defines the pattern to match. The expression can contain as many as 512 characters."
23+
type = string
24+
nullable = false
25+
}
26+
27+
variable "keywords" {
28+
description = "(Optional) An array that lists specific character sequences (keywords), one of which must be within proximity (maximum_match_distance) of the regular expression to match. The array can contain as many as 50 keywords. Each keyword can contain 3 - 90 characters. Keywords aren't case sensitive."
29+
type = set(string)
30+
default = []
31+
nullable = false
32+
}
33+
34+
variable "ignore_words" {
35+
description = "(Optional) An array that lists specific character sequences (ignore words) to exclude from the results. If the text matched by the regular expression is the same as any string in this array, Amazon Macie ignores it. The array can contain as many as 10 ignore words. Each ignore word can contain 4 - 90 characters. Ignore words are case sensitive."
36+
type = set(string)
37+
default = []
38+
nullable = false
39+
}
40+
41+
variable "maximum_match_distance" {
42+
description = "(Optional) The maximum allowable distance between text that matches the regex pattern and the keywords. The distance can be 1 - 300 characters. Defaults to `50`."
43+
type = number
44+
default = 50
45+
nullable = false
46+
47+
validation {
48+
condition = var.maximum_match_distance >= 1 && var.maximum_match_distance <= 300
49+
error_message = "Value for `maximum_match_distance` must be between 1 and 300."
50+
}
51+
}
52+
53+
variable "tags" {
54+
description = "(Optional) A map of tags to add to all resources."
55+
type = map(string)
56+
default = {}
57+
nullable = false
58+
}
59+
60+
variable "module_tags_enabled" {
61+
description = "(Optional) Whether to create AWS Resource Tags for the module informations."
62+
type = bool
63+
default = true
64+
nullable = false
65+
}
66+
67+
68+
###################################################
69+
# Resource Group
70+
###################################################
71+
72+
variable "resource_group" {
73+
description = <<EOF
74+
(Optional) A configurations of Resource Group for this module. `resource_group` as defined below.
75+
(Optional) `enabled` - Whether to create Resource Group to find and group AWS resources which are created by this module. Defaults to `true`.
76+
(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.
77+
(Optional) `description` - The description of Resource Group. Defaults to `Managed by Terraform.`.
78+
EOF
79+
type = object({
80+
enabled = optional(bool, true)
81+
name = optional(string, "")
82+
description = optional(string, "Managed by Terraform.")
83+
})
84+
default = {}
85+
nullable = false
86+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
terraform {
2+
required_version = ">= 1.12"
3+
4+
required_providers {
5+
aws = {
6+
source = "hashicorp/aws"
7+
version = ">= 6.12"
8+
}
9+
}
10+
}

0 commit comments

Comments
 (0)