HashiCorp Certified: Terraform Associate (003) — Question 27

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

Correct answer: A

Explanation

Option A is correct because it uses a list comprehension to iterate through each object in var.list and extract the id attribute. Option B is incorrect as it attempts to access the id attributes directly from the list without proper iteration. Option C creates a nested list, which is not the desired output. Option D creates a map rather than a list of IDs, which is not the intended result.