From 94e92c743c78df9e92cee05a794f19b7bbb175b9 Mon Sep 17 00:00:00 2001 From: Ivan Sukhomlyn Date: Fri, 26 Jan 2024 16:51:20 +0200 Subject: [PATCH 1/2] fix: define cluster_settings as list instead of single map --- README.md | 2 +- modules/cluster/README.md | 2 +- modules/cluster/main.tf | 2 +- modules/cluster/variables.tf | 14 ++++++++------ variables.tf | 14 ++++++++------ wrappers/cluster/main.tf | 10 ++++++---- wrappers/main.tf | 10 ++++++---- 7 files changed, 31 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index bce2c76..71a1152 100644 --- a/README.md +++ b/README.md @@ -188,7 +188,7 @@ No resources. | [cluster\_configuration](#input\_cluster\_configuration) | The execute command configuration for the cluster | `any` | `{}` | no | | [cluster\_name](#input\_cluster\_name) | Name of the cluster (up to 255 letters, numbers, hyphens, and underscores) | `string` | `""` | no | | [cluster\_service\_connect\_defaults](#input\_cluster\_service\_connect\_defaults) | Configures a default Service Connect namespace | `map(string)` | `{}` | no | -| [cluster\_settings](#input\_cluster\_settings) | Configuration block(s) with cluster settings. For example, this can be used to enable CloudWatch Container Insights for a cluster | `map(string)` |
{
"name": "containerInsights",
"value": "enabled"
}
| no | +| [cluster\_settings](#input\_cluster\_settings) | List of configuration block(s) with cluster settings. For example, this can be used to enable CloudWatch Container Insights for a cluster | `list(map(string))` |
[
{
"name": "containerInsights",
"value": "enabled"
}
]
| no | | [cluster\_tags](#input\_cluster\_tags) | A map of additional tags to add to the cluster | `map(string)` | `{}` | no | | [create](#input\_create) | Determines whether resources will be created (affects all resources) | `bool` | `true` | no | | [create\_cloudwatch\_log\_group](#input\_create\_cloudwatch\_log\_group) | Determines whether a log group is created by this module for the cluster logs. If not, AWS will automatically create one if logging is enabled | `bool` | `true` | no | diff --git a/modules/cluster/README.md b/modules/cluster/README.md index 1edf167..54144b8 100644 --- a/modules/cluster/README.md +++ b/modules/cluster/README.md @@ -173,7 +173,7 @@ No modules. | [cluster\_configuration](#input\_cluster\_configuration) | The execute command configuration for the cluster | `any` | `{}` | no | | [cluster\_name](#input\_cluster\_name) | Name of the cluster (up to 255 letters, numbers, hyphens, and underscores) | `string` | `""` | no | | [cluster\_service\_connect\_defaults](#input\_cluster\_service\_connect\_defaults) | Configures a default Service Connect namespace | `map(string)` | `{}` | no | -| [cluster\_settings](#input\_cluster\_settings) | Configuration block(s) with cluster settings. For example, this can be used to enable CloudWatch Container Insights for a cluster | `map(string)` |
{
"name": "containerInsights",
"value": "enabled"
}
| no | +| [cluster\_settings](#input\_cluster\_settings) | List of configuration block(s) with cluster settings. For example, this can be used to enable CloudWatch Container Insights for a cluster | `list(map(string))` |
[
{
"name": "containerInsights",
"value": "enabled"
}
]
| no | | [create](#input\_create) | Determines whether resources will be created (affects all resources) | `bool` | `true` | no | | [create\_cloudwatch\_log\_group](#input\_create\_cloudwatch\_log\_group) | Determines whether a log group is created by this module for the cluster logs. If not, AWS will automatically create one if logging is enabled | `bool` | `true` | no | | [create\_task\_exec\_iam\_role](#input\_create\_task\_exec\_iam\_role) | Determines whether the ECS task definition IAM role should be created | `bool` | `false` | no | diff --git a/modules/cluster/main.tf b/modules/cluster/main.tf index 2ae04b8..9db3bb8 100644 --- a/modules/cluster/main.tf +++ b/modules/cluster/main.tf @@ -79,7 +79,7 @@ resource "aws_ecs_cluster" "this" { } dynamic "setting" { - for_each = [var.cluster_settings] + for_each = var.cluster_settings content { name = setting.value.name diff --git a/modules/cluster/variables.tf b/modules/cluster/variables.tf index 2b9a52b..3af1171 100644 --- a/modules/cluster/variables.tf +++ b/modules/cluster/variables.tf @@ -27,12 +27,14 @@ variable "cluster_configuration" { } variable "cluster_settings" { - description = "Configuration block(s) with cluster settings. For example, this can be used to enable CloudWatch Container Insights for a cluster" - type = map(string) - default = { - name = "containerInsights" - value = "enabled" - } + description = "List of configuration block(s) with cluster settings. For example, this can be used to enable CloudWatch Container Insights for a cluster" + type = list(map(string)) + default = [ + { + name = "containerInsights" + value = "enabled" + } + ] } variable "cluster_service_connect_defaults" { diff --git a/variables.tf b/variables.tf index 97705e2..e1ab795 100644 --- a/variables.tf +++ b/variables.tf @@ -27,12 +27,14 @@ variable "cluster_configuration" { } variable "cluster_settings" { - description = "Configuration block(s) with cluster settings. For example, this can be used to enable CloudWatch Container Insights for a cluster" - type = map(string) - default = { - name = "containerInsights" - value = "enabled" - } + description = "List of configuration block(s) with cluster settings. For example, this can be used to enable CloudWatch Container Insights for a cluster" + type = list(map(string)) + default = [ + { + name = "containerInsights" + value = "enabled" + } + ] } variable "cluster_service_connect_defaults" { diff --git a/wrappers/cluster/main.tf b/wrappers/cluster/main.tf index 0a2f64c..8e90af6 100644 --- a/wrappers/cluster/main.tf +++ b/wrappers/cluster/main.tf @@ -10,10 +10,12 @@ module "wrapper" { cluster_configuration = try(each.value.cluster_configuration, var.defaults.cluster_configuration, {}) cluster_name = try(each.value.cluster_name, var.defaults.cluster_name, "") cluster_service_connect_defaults = try(each.value.cluster_service_connect_defaults, var.defaults.cluster_service_connect_defaults, {}) - cluster_settings = try(each.value.cluster_settings, var.defaults.cluster_settings, { - name = "containerInsights" - value = "enabled" - }) + cluster_settings = try(each.value.cluster_settings, var.defaults.cluster_settings, [ + { + name = "containerInsights" + value = "enabled" + } + ]) create = try(each.value.create, var.defaults.create, true) create_cloudwatch_log_group = try(each.value.create_cloudwatch_log_group, var.defaults.create_cloudwatch_log_group, true) create_task_exec_iam_role = try(each.value.create_task_exec_iam_role, var.defaults.create_task_exec_iam_role, false) diff --git a/wrappers/main.tf b/wrappers/main.tf index decb314..a14db9f 100644 --- a/wrappers/main.tf +++ b/wrappers/main.tf @@ -10,10 +10,12 @@ module "wrapper" { cluster_configuration = try(each.value.cluster_configuration, var.defaults.cluster_configuration, {}) cluster_name = try(each.value.cluster_name, var.defaults.cluster_name, "") cluster_service_connect_defaults = try(each.value.cluster_service_connect_defaults, var.defaults.cluster_service_connect_defaults, {}) - cluster_settings = try(each.value.cluster_settings, var.defaults.cluster_settings, { - name = "containerInsights" - value = "enabled" - }) + cluster_settings = try(each.value.cluster_settings, var.defaults.cluster_settings, [ + { + name = "containerInsights" + value = "enabled" + } + ]) cluster_tags = try(each.value.cluster_tags, var.defaults.cluster_tags, {}) create = try(each.value.create, var.defaults.create, true) create_cloudwatch_log_group = try(each.value.create_cloudwatch_log_group, var.defaults.create_cloudwatch_log_group, true) From 36b1baeb2fb39cd23d1dfb442676feef1cdd00cd Mon Sep 17 00:00:00 2001 From: Ivan Sukhomlyn Date: Mon, 12 Feb 2024 14:05:53 +0200 Subject: [PATCH 2/2] flatten list of ECS cluster setting to prevent breaking changes --- README.md | 2 +- modules/cluster/README.md | 2 +- modules/cluster/main.tf | 2 +- modules/cluster/variables.tf | 2 +- variables.tf | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 71a1152..42fe72c 100644 --- a/README.md +++ b/README.md @@ -188,7 +188,7 @@ No resources. | [cluster\_configuration](#input\_cluster\_configuration) | The execute command configuration for the cluster | `any` | `{}` | no | | [cluster\_name](#input\_cluster\_name) | Name of the cluster (up to 255 letters, numbers, hyphens, and underscores) | `string` | `""` | no | | [cluster\_service\_connect\_defaults](#input\_cluster\_service\_connect\_defaults) | Configures a default Service Connect namespace | `map(string)` | `{}` | no | -| [cluster\_settings](#input\_cluster\_settings) | List of configuration block(s) with cluster settings. For example, this can be used to enable CloudWatch Container Insights for a cluster | `list(map(string))` |
[
{
"name": "containerInsights",
"value": "enabled"
}
]
| no | +| [cluster\_settings](#input\_cluster\_settings) | List of configuration block(s) with cluster settings. For example, this can be used to enable CloudWatch Container Insights for a cluster | `any` |
[
{
"name": "containerInsights",
"value": "enabled"
}
]
| no | | [cluster\_tags](#input\_cluster\_tags) | A map of additional tags to add to the cluster | `map(string)` | `{}` | no | | [create](#input\_create) | Determines whether resources will be created (affects all resources) | `bool` | `true` | no | | [create\_cloudwatch\_log\_group](#input\_create\_cloudwatch\_log\_group) | Determines whether a log group is created by this module for the cluster logs. If not, AWS will automatically create one if logging is enabled | `bool` | `true` | no | diff --git a/modules/cluster/README.md b/modules/cluster/README.md index 54144b8..3d7abef 100644 --- a/modules/cluster/README.md +++ b/modules/cluster/README.md @@ -173,7 +173,7 @@ No modules. | [cluster\_configuration](#input\_cluster\_configuration) | The execute command configuration for the cluster | `any` | `{}` | no | | [cluster\_name](#input\_cluster\_name) | Name of the cluster (up to 255 letters, numbers, hyphens, and underscores) | `string` | `""` | no | | [cluster\_service\_connect\_defaults](#input\_cluster\_service\_connect\_defaults) | Configures a default Service Connect namespace | `map(string)` | `{}` | no | -| [cluster\_settings](#input\_cluster\_settings) | List of configuration block(s) with cluster settings. For example, this can be used to enable CloudWatch Container Insights for a cluster | `list(map(string))` |
[
{
"name": "containerInsights",
"value": "enabled"
}
]
| no | +| [cluster\_settings](#input\_cluster\_settings) | List of configuration block(s) with cluster settings. For example, this can be used to enable CloudWatch Container Insights for a cluster | `any` |
[
{
"name": "containerInsights",
"value": "enabled"
}
]
| no | | [create](#input\_create) | Determines whether resources will be created (affects all resources) | `bool` | `true` | no | | [create\_cloudwatch\_log\_group](#input\_create\_cloudwatch\_log\_group) | Determines whether a log group is created by this module for the cluster logs. If not, AWS will automatically create one if logging is enabled | `bool` | `true` | no | | [create\_task\_exec\_iam\_role](#input\_create\_task\_exec\_iam\_role) | Determines whether the ECS task definition IAM role should be created | `bool` | `false` | no | diff --git a/modules/cluster/main.tf b/modules/cluster/main.tf index 9db3bb8..c988f57 100644 --- a/modules/cluster/main.tf +++ b/modules/cluster/main.tf @@ -79,7 +79,7 @@ resource "aws_ecs_cluster" "this" { } dynamic "setting" { - for_each = var.cluster_settings + for_each = flatten([var.cluster_settings]) content { name = setting.value.name diff --git a/modules/cluster/variables.tf b/modules/cluster/variables.tf index 3af1171..7b5b968 100644 --- a/modules/cluster/variables.tf +++ b/modules/cluster/variables.tf @@ -28,7 +28,7 @@ variable "cluster_configuration" { variable "cluster_settings" { description = "List of configuration block(s) with cluster settings. For example, this can be used to enable CloudWatch Container Insights for a cluster" - type = list(map(string)) + type = any default = [ { name = "containerInsights" diff --git a/variables.tf b/variables.tf index e1ab795..8f65a0d 100644 --- a/variables.tf +++ b/variables.tf @@ -28,7 +28,7 @@ variable "cluster_configuration" { variable "cluster_settings" { description = "List of configuration block(s) with cluster settings. For example, this can be used to enable CloudWatch Container Insights for a cluster" - type = list(map(string)) + type = any default = [ { name = "containerInsights"