nerdexam
HashiCorpHashiCorp

TERRAFORM-ASSOCIATE-004 · Question #22

TERRAFORM-ASSOCIATE-004 Question #22: Real Exam Question with Answer & Explanation

The correct answer is B: [ for o in var.list : o.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 }

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 PracticeBrowse All TERRAFORM-ASSOCIATE-004 Questions