0
0
Terraformcloud~10 mins

Why complex types matter in Terraform - Test Your Understanding

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to define a variable with a complex type list of strings.

Terraform
variable "example_list" {
  type = [1]
}
Drag options to blanks, or click blank then click option'
Alist(string)
Bmap(string)
Cstring
Dnumber
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'string' instead of 'list(string)' for a list variable.
Using 'map(string)' which expects key-value pairs, not a list.
2fill in blank
medium

Complete the code to define a variable with a map of numbers.

Terraform
variable "example_map" {
  type = [1]
}
Drag options to blanks, or click blank then click option'
Astring
Blist(number)
Cmap(number)
Dnumber
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'list(number)' which is a list, not a map.
Using 'number' which is a single number, not a map.
3fill in blank
hard

Fix the error in the variable type definition for a set of strings.

Terraform
variable "example_set" {
  type = [1]
}
Drag options to blanks, or click blank then click option'
Aset(string)
Blist(string)
Cmap(string)
Dstring
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'list(string)' which allows duplicates and is ordered.
Using 'map(string)' which expects key-value pairs.
4fill in blank
hard

Fill both blanks to define an object type with two attributes: name (string) and count (number).

Terraform
variable "example_object" {
  type = object({
    name = [1],
    count = [2]
  })
}
Drag options to blanks, or click blank then click option'
Astring
Bnumber
Cbool
Dlist(string)
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'bool' or 'list(string)' for these attributes incorrectly.
Mixing up attribute types.
5fill in blank
hard

Fill all three blanks to define a complex variable: a list of objects with attributes id (number), enabled (bool), and tags (list of strings).

Terraform
variable "complex_var" {
  type = list(object({
    id = [1],
    enabled = [2],
    tags = [3]
  }))
}
Drag options to blanks, or click blank then click option'
Astring
Bbool
Clist(string)
Dnumber
Attempts:
3 left
💡 Hint
Common Mistakes
Confusing 'bool' with 'string' or 'number'.
Using 'string' instead of 'list(string)' for tags.