Bitzu

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

Single choice

Which collection type guarantees unique values and has no ordering?

  1. list
  2. set
  3. map
  4. 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.

Select all that apply

Which statements about collection types are correct?

  1. List elements are indexed starting at 0
  2. Converting a list to a set removes duplicates
  3. A set can be indexed with [0] to get its first value
  4. Map values are found with string keys
  5. 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

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.

Download on the App StoreGet it on Google Play

More Terraform Associate 004 topics in this module