0
0
Terraformcloud~10 mins

Input variable precedence order 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 define a variable with a default value.

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

Complete the code to override the variable value using a CLI flag.

Terraform
terraform apply -var='region=[1]'
Drag options to blanks, or click blank then click option'
Aeu-central-1
Bdefault
Cfalse
Dnull
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'default' as a value which is not a valid region.
Using boolean or null values.
3fill in blank
hard

Fix the error in the variable declaration to set a description.

Terraform
variable "environment" {
  type        = string
  description = [1]
  default     = "dev"
}
Drag options to blanks, or click blank then click option'
Anull
B"The deployment environment"
Ctrue
Ddev
Attempts:
3 left
💡 Hint
Common Mistakes
Not quoting the description string.
Using a boolean or null instead of a string.
4fill in blank
hard

Fill both blanks to set a variable with a type and a default list value.

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

Fill all three blanks to demonstrate variable precedence: default, environment variable, and CLI override.

Terraform
# Variable with default
variable "instance_type" {
  type    = string
  default = "t2.micro"
}

# Environment variable override example
# export TF_VAR_instance_type=[1]

# CLI override example
terraform apply -var='instance_type=[2]'

# Final value used is [3]
Drag options to blanks, or click blank then click option'
At2.small
Bt2.medium
Dt2.micro
Attempts:
3 left
💡 Hint
Common Mistakes
Confusing the precedence order of variable sources.
Using the default as the final value when overrides exist.