for expression
An expression that builds a new list or map by transforming each element of another collection, as in [for n in var.names : lower(n)].
In more detail
Square brackets produce a list and braces produce a map, and an if clause can filter elements. It transforms values only; to create one resource per element you use count or for_each instead.
Examples
[for name in var.names : lower(trimspace(name))]{ for k, v in null_resource.subnet : k => v.id }Related terms
- Terraform expression — Anything that produces a value on the right of an equals sign: a literal, a reference, a function call, a for expression or a conditional.
- for_each — The for_each argument, which creates one instance of a resource or module per element of a map or set, addressed by key such as name["a"].
- built-in function — One of Terraform's fixed set of functions, such as lower(), join() or jsonencode(), that transform values inside expressions.
Taught in
- Return Values: Outputs And Locals — Infrastructure as Code with Terraform
- Functions And Expressions In HCL — Infrastructure as Code with Terraform
- Writing A Custom Network Module — Infrastructure as Code with Terraform
- Expressions And Functions: Making Configuration Compute — HashiCorp Terraform Associate (004) Exam Prep
- Count, For Each And Dynamic Blocks — HashiCorp Terraform Associate (004) Exam Prep