Skip to main content

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
        }
    } 
}
Close Menu

WHERE TO FIND US


PARIS

Bâtiment Crisco Duo
7 avenue de la Cristallerie
92310 Sèvres, France

NANTES

Centre d’affaires Euptouyou
4 rue Edith Piaf Immeuble Asturia C
44800 Saint-Herblain, France

PHONE

+33 1 46 48 26 00

EMAIL

[email protected]