0
0
Terraformcloud~10 mins

Variable declaration syntax 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 declare a variable with a default value.

Terraform
variable "region" {
  type    = string
  default = [1]
}
Drag options to blanks, or click blank then click option'
A"us-west-2"
Bregion
Cus-west-2
Dstring
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting to use quotes around string values.
Using a bare word without quotes for the default.
2fill in blank
medium

Complete the code to declare a variable with a list type.

Terraform
variable "availability_zones" {
  type = [1]
}
Drag options to blanks, or click blank then click option'
Abool
Blist(string)
Cmap(string)
Dstring
Attempts:
3 left
💡 Hint
Common Mistakes
Using just 'string' instead of 'list(string)'.
Confusing map and list types.
3fill in blank
hard

Fix the error in the variable declaration for a boolean variable.

Terraform
variable "enable_logging" {
  type    = bool
  default = [1]
}
Drag options to blanks, or click blank then click option'
A"true"
BFalse
C"false"
Dtrue
Attempts:
3 left
💡 Hint
Common Mistakes
Putting quotes around boolean values.
Using capitalized boolean values like False.
4fill in blank
hard

Fill both blanks to declare a variable with a map of strings type and a default value.

Terraform
variable "tags" {
  type    = [1]
  default = [2]
}
Drag options to blanks, or click blank then click option'
Amap(string)
B{"Environment" = "dev", "Owner" = "team"}
C["dev", "team"]
Dlist(string)
Attempts:
3 left
💡 Hint
Common Mistakes
Using list type instead of map.
Using list syntax for default instead of map syntax.
5fill in blank
hard

Fill all three blanks to declare a variable with a description, type, and default value.

Terraform
variable "instance_count" {
  description = [1]
  type        = [2]
  default     = [3]
}
Drag options to blanks, or click blank then click option'
A"Number of instances to create"
Bnumber
C3
D"3"
Attempts:
3 left
💡 Hint
Common Mistakes
Using quotes around the default number value.
Using string type instead of number.