モジュール側で map の配列を受け取るようにする。
variable "parameters" {
type = list(map(string))
}
resource "aws_rds_cluster_parameter_group" "template" {
family = "aurora-mysql5.7"
name = var.name
dynamic "parameter" {
for_each = var.parameters
content {
apply_method = parameter.value["apply_method"]
name = parameter.value["name"]
value = parameter.value["value"]
}
}
}
呼び出し側で parameters の配列に必要なパラメータを map で書いてあげればよい。
module "parameter_group" {
source = "../../modules/aws_rds_cluster_parameter_group"
name = "sample-parameter-group"
parameters = [
{ apply_method : "immediate", name : "character_set_server", value : "utf8mb4" },
{ apply_method : "pending-reboot", name : "binlog_format", value : "MIXED" },
]
}
plan 結果。
# module.parameter_group.aws_rds_cluster_parameter_group.template will be created
+ resource "aws_rds_cluster_parameter_group" "template" {
+ arn = (known after apply)
+ description = "Managed by Terraform"
+ family = "aurora-mysql5.7"
+ id = (known after apply)
+ name = "sample-parameter-group"
+ name_prefix = (known after apply)
+ tags_all = (known after apply)
+ parameter {
+ apply_method = "immediate"
+ name = "character_set_server"
+ value = "utf8mb4"
}
+ parameter {
+ apply_method = "pending-reboot"
+ name = "binlog_format"
+ value = "MIXED"
}
}
Plan: 1 to add, 0 to change, 0 to destroy.