Challenge - 5 Problems
Terraform.tfvars Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Configuration
intermediate1:30remaining
Identify the correct value of a variable from a Terraform.tfvars file
Given the following Terraform.tfvars content, what is the value of the variable instance_count after Terraform applies the configuration?
Terraform
instance_count = 3 region = "us-west-2" instance_type = "t2.micro"
Attempts:
2 left
💡 Hint
Look for the variable name and its assigned value in the tfvars content.
✗ Incorrect
The variable
instance_count is assigned the value 3 in the Terraform.tfvars file, so Terraform uses this value during deployment.❓ service_behavior
intermediate1:30remaining
Effect of missing variable in Terraform.tfvars file
If a variable db_password is declared in Terraform but not set in the Terraform.tfvars file or elsewhere, what will happen when you run
terraform apply?Terraform
variable "db_password" { type = string description = "The database password" }
Attempts:
2 left
💡 Hint
Think about how Terraform handles variables without default values and no input.
✗ Incorrect
Terraform prompts the user to enter a value for variables that have no default and are not set in any input files like tfvars.
❓ Architecture
advanced2:00remaining
Choosing the right Terraform.tfvars file for multiple environments
You have two Terraform.tfvars files:
dev.tfvars and prod.tfvars. How do you apply the Terraform configuration for the production environment using the correct tfvars file?Attempts:
2 left
💡 Hint
Check the Terraform CLI option to specify a variable file.
✗ Incorrect
The correct CLI option to specify a variable file is
-var-file. This tells Terraform to load variables from the given file.❓ security
advanced2:00remaining
Best practice for sensitive data in Terraform.tfvars files
Which practice is best to keep sensitive data like passwords secure when using Terraform.tfvars files?
Attempts:
2 left
💡 Hint
Think about how to avoid exposing secrets in code repositories.
✗ Incorrect
Storing sensitive data in environment variables or secret managers avoids exposing secrets in files that might be committed to version control.
🧠 Conceptual
expert2:30remaining
Understanding variable precedence with Terraform.tfvars
Given a variable
region defined with a default in Terraform, set to "us-east-1", and also set in terraform.tfvars as "us-west-2", and finally set via CLI as -var='region=eu-central-1', what value will Terraform use for region?Terraform
variable "region" { type = string default = "us-east-1" }
Attempts:
2 left
💡 Hint
Remember the order of precedence for variable values in Terraform.
✗ Incorrect
Terraform uses CLI -var values first, then tfvars files, then defaults. So CLI value
eu-central-1 overrides others.