0
0
Terraformcloud~20 mins

Variable declaration syntax in Terraform - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Terraform Variable Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Understanding Terraform variable declaration
Which of the following Terraform variable declarations correctly defines a string variable with a default value?
Avariable region { type = string default = us-west-1 }
Bvariable "region" { type = string default = "us-west-1" }
Cvariable "region" { type = string default = us-west-1 }
Dvariable "region" { type = "string" default = "us-west-1" }
Attempts:
2 left
💡 Hint
Remember that string values must be quoted and the type keyword expects a type identifier without quotes.
Configuration
intermediate
2:00remaining
Correct syntax for list variable declaration
Which option correctly declares a Terraform variable named availability_zones as a list of strings with two default values?
Avariable "availability_zones" { type = list(string) default = ["us-east-1a", "us-east-1b"] }
Bvariable "availability_zones" { type = list default = [us-east-1a, us-east-1b] }
Cvariable "availability_zones" { type = list(string) default = us-east-1a, us-east-1b }
Dvariable availability_zones { type = list(string) default = ["us-east-1a", "us-east-1b"] }
Attempts:
2 left
💡 Hint
Check how the list type and default values are formatted.
Architecture
advanced
2:30remaining
Choosing variable types for infrastructure parameters
You want to declare a Terraform variable to accept a map of strings representing tags for AWS resources. Which declaration is correct?
Avariable tags { type = map(string) default = { Environment = prod, Owner = team } }
Bvariable "tags" { type = map default = { "Environment" = "prod", "Owner" = "team" } }
Cvariable "tags" { type = map(string) default = { Environment = "prod", Owner = "team" } }
Dvariable "tags" { type = map(string) default = ["Environment" = "prod", "Owner" = "team"] }
Attempts:
2 left
💡 Hint
Remember the syntax for maps and quoting keys and values.
security
advanced
2:00remaining
Declaring sensitive variables in Terraform
Which Terraform variable declaration correctly marks a variable as sensitive to avoid showing its value in logs?
Avariable "db_password" { type = string sensitive = true }
Bvariable "db_password" { type = string sensitive = "true" }
Cvariable "db_password" { type = string sensitive = yes }
Dvariable "db_password" { type = string sensitive = 1 }
Attempts:
2 left
💡 Hint
Check the correct boolean syntax for the sensitive attribute.
service_behavior
expert
1:30remaining
Effect of variable default on module behavior
Given a Terraform module with a variable declared as:
variable "instance_count" { type = number default = 3 }

What will be the value of instance_count if the module is called without specifying this variable?
A0
BIt will cause a runtime error due to missing variable
Cnull
D3
Attempts:
2 left
💡 Hint
Check how Terraform handles variables with default values when not overridden.