After reading theprevious articlerelated on # for_each with a list in dynamic block terraform, you may need to iterate on more complex terraform objects. Below an example with a map of terraform custom object.
- In the
variables.tf
file:
variable "map_to_iterate" {
description = "A map containing a map object for each value"
type = map(object({
arg1 = string
arg2 = string
}))
default = {}
}
- In the
main.tf
file:
resource "resource" "local_given_name" {
dynamic "block" {
for_each = var.map_to_iterate
content {
block_arg1 = local_given_name.value.arg1
block_arg2 = local_given_name.value.arg2
}
}
}