HashiCorp Certified: Terraform Associate — Question 28
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.)
Answer options
- A. { for o in var.list : o => o.id }
- B. var.list[*].id
- C. [ var.list[*].id ]
- D. [ for o in var.list : o.id ]
Correct answer: B, D
Explanation
The correct answers B and D effectively extract the id attributes from each object in var.list. Option B directly accesses the id attributes using the wildcard syntax, while option D uses a loop to gather the ids into a list. Options A and C do not correctly produce a list of IDs; A uses an incorrect syntax for the operation, and C wraps the result in another list which is unnecessary.