Terraform Associate 004 ยท Configuration building blocks
Primitive and collection types
string, number, bool, list, set, map, indexing and key access, ordering and uniqueness differences (4d).
Key points
- Primitives: string, number, bool.
- Collections hold values of one type: list(T) is ordered and indexed from 0 (var.names[0]); set(T) holds unique values with no order and no index; map(T) holds values found by string keys (var.tags["env"]).
- Lists may repeat values, sets drop duplicates.
Source: https://developer.hashicorp.com/terraform/language/expressions/type-constraints
Practice questions
Which collection type guarantees unique values and has no ordering?
- list
- set
- map
- tuple
Show answer
Answer: B. set
A set holds unique values with no secondary identifiers or order. A list is ordered and may repeat; a map is keyed.
Which statements about collection types are correct?
- List elements are indexed starting at 0
- Converting a list to a set removes duplicates
- A set can be indexed with [0] to get its first value
- Map values are found with string keys
- A list can never contain duplicate values
Show answer
Answer: A. List elements are indexed starting at 0, B. Converting a list to a set removes duplicates, D. Map values are found with string keys
Lists are zero-indexed and ordered; converting list to set drops duplicates and order; maps use string keys. Sets cannot be indexed by position.
True or false: in list(string), the first element is accessed with index 1.
Show answer
Answer: False
False. Indexing starts at 0, so the first element is var.names[0].
Practice 8 questions on this topic in Bitzu
Short lessons, instant explanations and spaced review of what you get wrong. Free on iOS and Android.
