Skill 4.5.1
Conditional and for expressions
Key Concepts
A conditional has the form condition ? true_value : false_value, such as var.environment == "prod" ? "m6i.large" : "t3.micro". Both results should have the same type, or types Terraform can convert to a common type.
A for expression builds a new collection from another. [for s in var.names : upper(s)] produces a list, and {for k, v in var.tags : k => lower(v)} produces a map. An if clause filters elements, as in [for u in var.users : u.name if u.admin]. With a map input, the two symbols are the key and the value; with a list, they are the index and the element.