nerdexam
HashiCorp

TERRAFORM-ASSOCIATE-004 · Question #22

You have declared a variable called var.list which is a list of objects that all have an attribute id . Which options will produce a list of the IDs? Choose two correct answers.

The correct answer is B. [ for o in var.list : o.Id ] C. var.list[*].id. Two syntaxes produce a flat list of attribute values in Terraform. C - var.list[*].id - uses the splat expression, which iterates over all elements of var.list and extracts the id attribute from each, returning a list. B - [ for o in var.list : o.id ] - uses a for expression insi

Submitted by thandi_sa· Apr 18, 2026Work with Terraform Configurations

Question

You have declared a variable called var.list which is a list of objects that all have an attribute id . Which options will produce a list of the IDs? Choose two correct answers.

Options

  • A[ var.list [ * ] , id ]
  • B[ for o in var.list : o.Id ]
  • Cvar.list[*].id
  • D{ for o in var.llst : o => o.id }

How the community answered

(24 responses)
  • A
    8% (2)
  • B
    79% (19)
  • D
    13% (3)

Explanation

Two syntaxes produce a flat list of attribute values in Terraform. C - var.list[*].id - uses the splat expression, which iterates over all elements of var.list and extracts the id attribute from each, returning a list. B - [ for o in var.list : o.id ] - uses a for expression inside a tuple constructor, explicitly iterating over each object and projecting its id attribute into a new list. Option A has invalid syntax. Option D uses double curly braces and the o => o.id map syntax, which would produce a map, not a list.

Topics

#Terraform Expressions#List Manipulation#For Expressions#Splat Expressions

Community Discussion

No community discussion yet for this question.

Full TERRAFORM-ASSOCIATE-004 Practice