concept

For expressions and filtering

Construct tuples or objects by transforming a collection; filter entries and group repeated result keys where appropriate.

Formal Syntax & Structure

terraform syntaxterraform
For expressions and filtering

Working Example

Example Snippetterraform
variable "services" {  type = list(object({    name    = string    enabled = optional(bool, true)    port    = number  }))  default = [    { name = "search", port = 8080 },    { name = "archive", port = 8081, enabled = false },    { name = "catalog", port = 8082 }  ]}
output "enabled_names" {  value = [for svc in var.services : svc.name if svc.enabled]}
output "ports_by_name" {  value = { for svc in var.services : svc.name => svc.port }}
Terraform Reference