From c32a65786dbfb28bac8fbc9f60ff3a4ac06830d9 Mon Sep 17 00:00:00 2001 From: Ivan Sukhomlyn Date: Mon, 12 Feb 2024 15:28:36 +0200 Subject: [PATCH] fix: Allow `cluster_settings` to be list of maps instead of single map (#157) --- 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..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) | 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 | `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 1edf167..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) | 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 | `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 2ae04b8..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 2b9a52b..7b5b968 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 = any + default = [ + { + name = "containerInsights" + value = "enabled" + } + ] } variable "cluster_service_connect_defaults" { diff --git a/variables.tf b/variables.tf index 97705e2..8f65a0d 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 = any + 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)