Skip to content

Commit e3694b7

Browse files
committed
feat(config-managed-rule): support aws provider v6
1 parent 186974b commit e3694b7

File tree

6 files changed

+57
-19
lines changed

6 files changed

+57
-19
lines changed

modules/config-managed-rule/README.md

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

1616
| Name | Version |
1717
|------|---------|
18-
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.6 |
19-
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.23 |
18+
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.12 |
19+
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 6.12 |
2020

2121
## Providers
2222

2323
| Name | Version |
2424
|------|---------|
25-
| <a name="provider_aws"></a> [aws](#provider\_aws) | 5.46.0 |
25+
| <a name="provider_aws"></a> [aws](#provider\_aws) | 6.13.0 |
2626

2727
## Modules
2828

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

3333
## Resources
3434

@@ -43,17 +43,16 @@ This module creates following resources.
4343
|------|-------------|------|---------|:--------:|
4444
| <a name="input_source_rule"></a> [source\_rule](#input\_source\_rule) | (Required) The identifier for AWS Config managed rule. Use the format like `root-account-mfa-enabled` instead of predefiend format like `ROOT_ACCOUNT_MFA_ENABLED`. | `string` | n/a | yes |
4545
| <a name="input_description"></a> [description](#input\_description) | (Optional) The description of the rule. Use default description if not provided. | `string` | `null` | no |
46-
| <a name="input_evaluation_modes"></a> [evaluation\_modes](#input\_evaluation\_modes) | (Optional) A set of evaluation modes to enable for the Config rule. Valid values are `DETECTIVE`, `PROACTIVE`. Default value contains only `DETECTIVE`. | `set(string)` | <pre>[<br> "DETECTIVE"<br>]</pre> | no |
46+
| <a name="input_evaluation_modes"></a> [evaluation\_modes](#input\_evaluation\_modes) | (Optional) A set of evaluation modes to enable for the Config rule. Valid values are `DETECTIVE`, `PROACTIVE`. Default value contains only `DETECTIVE`. | `set(string)` | <pre>[<br/> "DETECTIVE"<br/>]</pre> | no |
4747
| <a name="input_excluded_accounts"></a> [excluded\_accounts](#input\_excluded\_accounts) | (Optional) A list of AWS account identifiers to exclude from the rule. Only need when `level` is configured with value `ORGANIZATION`. | `list(string)` | `[]` | no |
4848
| <a name="input_level"></a> [level](#input\_level) | (Optional) Choose to create a rule across all accounts in your Organization. Valid values are `ACCOUNT` and `ORGANIZATION`. Use `ORGANIZATION` level in Organization master account or delegated administrator accounts. | `string` | `"ACCOUNT"` | no |
4949
| <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 |
5050
| <a name="input_name"></a> [name](#input\_name) | (Optional) The name of the rule. Use default rule name if not provided. | `string` | `null` | no |
5151
| <a name="input_parameters"></a> [parameters](#input\_parameters) | (Optional) A map of parameters that is passed to the AWS Config rule Lambda function. | `any` | `{}` | no |
52-
| <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 |
53-
| <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-
| <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 |
52+
| <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 |
53+
| <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 |
5554
| <a name="input_resource_id"></a> [resource\_id](#input\_resource\_id) | (Optional) The ID of the only AWS resource that you want to trigger an evaluation for the rule. If you specify this, you must specify only one resource type for `resource_types`. Only need when `scope` is configured with value `RESOURCES`. | `string` | `null` | no |
56-
| <a name="input_resource_tag"></a> [resource\_tag](#input\_resource\_tag) | (Optional) The tag that are applied to only those AWS resources that you want you want to trigger an evaluation for the rule. You can configure with only `key` or a set of `key` and `value`. Only need when `scope` is configured with value `TAGS`. | `map(string)` | `{}` | no |
55+
| <a name="input_resource_tag"></a> [resource\_tag](#input\_resource\_tag) | (Optional) The tag that are applied to only those AWS resources that you want you want to trigger an evaluation for the rule. You can configure with only `key` or a set of `key` and `value`. Only need when `scope` is configured with value `TAGS`. | <pre>object({<br/> key = string<br/> value = optional(string)<br/> })</pre> | `null` | no |
5756
| <a name="input_resource_types"></a> [resource\_types](#input\_resource\_types) | (Optional) A list of resource types of only those AWS resources that you want to trigger an evaluation for the rule. For example, `AWS::EC2::Instance` or `AWS::CloudTrail::Trail`. Only need when `scope` is configured with value `RESOURCES`. | `list(string)` | `[]` | no |
5857
| <a name="input_schedule_frequency"></a> [schedule\_frequency](#input\_schedule\_frequency) | (Optional) The frequency with which AWS Config runs evaluations for a rule. Use default value if not provided. Valid values are `1h`, `3h`, `6h`, `12h`, or `24h`. | `string` | `null` | no |
5958
| <a name="input_scope"></a> [scope](#input\_scope) | (Optional) Choose when evaluations will occur. Valid values are `ALL_CHANGES`, `RESOURCES`, or `TAGS`. | `string` | `"RESOURCES"` | no |
@@ -71,6 +70,8 @@ This module creates following resources.
7170
| <a name="output_level"></a> [level](#output\_level) | The level of the rule. `ACOUNT` or `ORGANIZATION`. The rule is for accounts in your Organization if the value is configured with `ORGANIZATION`. |
7271
| <a name="output_name"></a> [name](#output\_name) | The name of the rule. |
7372
| <a name="output_parameters"></a> [parameters](#output\_parameters) | The parameters of the rule. |
73+
| <a name="output_region"></a> [region](#output\_region) | The AWS region this module resources resides in. |
74+
| <a name="output_resource_group"></a> [resource\_group](#output\_resource\_group) | The resource group created to manage resources in this module. |
7475
| <a name="output_source_rule"></a> [source\_rule](#output\_source\_rule) | The information of the managed rule used. |
7576
| <a name="output_trigger_by_change"></a> [trigger\_by\_change](#output\_trigger\_by\_change) | The information of trigger by configuration changes. |
7677
| <a name="output_trigger_by_schedule"></a> [trigger\_by\_schedule](#output\_trigger\_by\_schedule) | The information of trigger by schedule. |

modules/config-managed-rule/main.tf

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ locals {
4242
"TAGS" = {
4343
resource_types = null
4444
resource_id = null
45-
tag_key = try(var.resource_tag.key, null)
46-
tag_value = try(var.resource_tag.value, null)
45+
tag_key = var.resource_tag != null ? var.resource_tag.key : null
46+
tag_value = var.resource_tag != null ? var.resource_tag.value : null
4747
}
4848
}
4949
}
@@ -56,6 +56,8 @@ locals {
5656
resource "aws_config_config_rule" "this" {
5757
count = var.level == "ACCOUNT" ? 1 : 0
5858

59+
region = var.region
60+
5961
name = local.metadata.name
6062
description = coalesce(var.description, local.rule.description)
6163

@@ -119,6 +121,8 @@ resource "aws_config_config_rule" "this" {
119121
resource "aws_config_organization_managed_rule" "this" {
120122
count = var.level == "ORGANIZATION" ? 1 : 0
121123

124+
region = var.region
125+
122126
name = local.metadata.name
123127
description = coalesce(var.description, local.rule.description)
124128

modules/config-managed-rule/outputs.tf

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
output "region" {
2+
description = "The AWS region this module resources resides in."
3+
value = try(
4+
aws_config_config_rule.this[0].region,
5+
aws_config_organization_managed_rule.this[0].region
6+
)
7+
}
8+
19
output "id" {
210
description = "The ID of the rule."
311
value = try(

modules/config-managed-rule/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/config-managed-rule/variables.tf

Lines changed: 29 additions & 6 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 "source_rule" {
29
description = "(Required) The identifier for AWS Config managed rule. Use the format like `root-account-mfa-enabled` instead of predefiend format like `ROOT_ACCOUNT_MFA_ENABLED`."
310
type = string
@@ -69,20 +76,39 @@ variable "resource_types" {
6976
type = list(string)
7077
default = []
7178
nullable = false
79+
80+
validation {
81+
condition = anytrue([
82+
var.scope != "RESOURCES",
83+
var.scope == "RESOURCES" && length(var.resource_types) > 0,
84+
])
85+
error_message = "You must provide at least one resource type in `resource_types` when `scope` is configured with value `RESOURCES`."
86+
}
7287
}
7388

7489
variable "resource_id" {
7590
description = "(Optional) The ID of the only AWS resource that you want to trigger an evaluation for the rule. If you specify this, you must specify only one resource type for `resource_types`. Only need when `scope` is configured with value `RESOURCES`."
7691
type = string
7792
default = null
7893
nullable = true
94+
95+
validation {
96+
condition = anytrue([
97+
var.scope != "RESOURCES",
98+
var.scope == "RESOURCES" && (var.resource_id == null || (var.resource_id != null && length(var.resource_types) == 1)),
99+
])
100+
error_message = "You must provide only one resource type in `resource_types` when `resource_id` is specified and `scope` is configured with value `RESOURCES`."
101+
}
79102
}
80103

81104
variable "resource_tag" {
82105
description = "(Optional) The tag that are applied to only those AWS resources that you want you want to trigger an evaluation for the rule. You can configure with only `key` or a set of `key` and `value`. Only need when `scope` is configured with value `TAGS`."
83-
type = map(string)
84-
default = {}
85-
nullable = false
106+
type = object({
107+
key = string
108+
value = optional(string)
109+
})
110+
default = null
111+
nullable = true
86112
}
87113

88114
variable "schedule_frequency" {
@@ -118,9 +144,6 @@ variable "module_tags_enabled" {
118144
# Resource Group
119145
###################################################
120146

121-
122-
123-
124147
variable "resource_group" {
125148
description = <<EOF
126149
(Optional) A configurations of Resource Group for this module. `resource_group` as defined below.
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
terraform {
2-
required_version = ">= 1.6"
2+
required_version = ">= 1.12"
33

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

0 commit comments

Comments
 (0)