Can a dynamic block name itself be a variable?
Am trying to create a resource that has a logging_configuration block, which has a inner set of blocks that when declared will create log groups.
resource "aws_resource" "example" {
arg1 = var.arg1
...
logging_config {
agent_log {
name_prefix = "dr_ag"
}
error_log {
name_prefix = "dr_err"
}
}
}
The inner blocks are like 6 different categories. Currently am declaring like above and the resource spins off log groups when it finds an inner block.
So was checking out if the inner block can be dynamically created off of a map(string), like so:
variable "logs_configs" {
type = map(string)
default = {
"agent_log" = "dr_ag"
"error_log" = "dr_err"
}
}
resource "aws_resource" "example" {
arg1 = var.arg1
...
dynamic "logging_config" {
for_each = var.logs_configs
dynamic logging_config.key { <== Can this be from a variable!!
content {
name_prefix = logging_config.value.value
enabled = true
}
}
}
}
Obviously the above code doesn’t compile, but is there an alternative way to achieve something like above. Any thoughts. Thanks.