Question 1 · choose 1
var.users is a list of objects with name and is_admin attributes. A local value must be a map from each admin's name to that user object. Which expression builds it?
- A[ for u in var.users : u.name => u if u.is_admin ]
- B{ for u in var.users : u if u.is_admin }
- C{ for u in var.users : u.name => u if u.is_admin }
- Dlookup(var.users, "is_admin", true)
Show the answer and why
A[ for u in var.users : u.name => u if u.is_admin ]
Incorrect
Square brackets produce a list, which cannot use the key => value form.
B{ for u in var.users : u if u.is_admin }
Incorrect
A map-producing for expression needs a key => value pair.
C{ for u in var.users : u.name => u if u.is_admin }
Correct
A for expression in braces produces a map with key => value, and the if clause filters elements.
Dlookup(var.users, "is_admin", true)
Incorrect
lookup reads one key from a map; it does not filter or transform a list.
Brackets make lists, braces make maps, and if filters either.
HashiCorp documentation