0
0
Terraformcloud~10 mins

Default values in Terraform - Interactive Code Practice

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

Complete the code to set a default value for the variable.

Terraform
variable "region" {
  type    = string
  default = "[1]"
}
Drag options to blanks, or click blank then click option'
Aus-west-2
Btrue
C10
Dnull
Attempts:
3 left
💡 Hint
Common Mistakes
Using a boolean or number instead of a string for the default value.
Leaving the default value empty.
2fill in blank
medium

Complete the code to set a default value for the variable with a list of strings.

Terraform
variable "availability_zones" {
  type    = list(string)
  default = [1]
}
Drag options to blanks, or click blank then click option'
A3
B"us-west-2a"
Ctrue
D["us-west-2a", "us-west-2b"]
Attempts:
3 left
💡 Hint
Common Mistakes
Using a single string instead of a list.
Using a boolean or number instead of a list.
3fill in blank
hard

Fix the error in the variable default value to match the declared type.

Terraform
variable "instance_count" {
  type    = number
  default = [1]
}
Drag options to blanks, or click blank then click option'
A[3]
B"3"
C3
Dtrue
Attempts:
3 left
💡 Hint
Common Mistakes
Putting the number inside quotes, making it a string.
Using a list or boolean instead of a number.
4fill in blank
hard

Fill both blanks to define a variable with a map type and default values.

Terraform
variable "tags" {
  type    = map(string)
  default = { [1] = [2] }
}
Drag options to blanks, or click blank then click option'
A"Environment"
B"Production"
C"Version"
D"1.0"
Attempts:
3 left
💡 Hint
Common Mistakes
Using unquoted keys or values.
Mixing keys and values incorrectly.
5fill in blank
hard

Fill all three blanks to define a variable with a complex default map of strings.

Terraform
variable "metadata" {
  type    = map(string)
  default = {
    [1] = [2]
    [3] = "v1"
  }
}
Drag options to blanks, or click blank then click option'
A"Owner"
B"Alice"
C"Project"
D"CloudInfra"
Attempts:
3 left
💡 Hint
Common Mistakes
Using unquoted keys or values.
Mixing keys and values incorrectly.