QuestionQ152

Terraform configuration

You have declared a variable named var.list, which is a list of objects, each with an id attribute.

Which expressions evaluate to a list of the objects’ id attributes?

Choose two
  • A [ var.list[*].id ]
  • B [ for o in var.list : o.id ]
  • C var.list[*].id
  • D { for o in var.list : o => o.id }
Explanation

A square-bracket for expression transforms each object into its id value, producing a tuple/list-like result. The [*] splat operator likewise iterates across all elements of a list and accesses id on each element. HashiCorp documents [for o in var.list : o.id] and var.list[*].id as equivalent expressions for this case.

Learn more

Community Discussion

No comments yet. Be the first to start the discussion!