0
0
Terraformcloud~20 mins

Terraform.tfvars file - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Terraform.tfvars Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Configuration
intermediate
1: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"
A3
Bus-west-2
Ct2.micro
Dnull
Attempts:
2 left
💡 Hint
Look for the variable name and its assigned value in the tfvars content.
service_behavior
intermediate
1: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"
}
ATerraform will automatically generate a random password
BTerraform will prompt for the value during apply
CTerraform will use an empty string as the value
DTerraform will fail with a syntax error
Attempts:
2 left
💡 Hint
Think about how Terraform handles variables without default values and no input.
Architecture
advanced
2: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?
Aterraform apply -var-file=prod.tfvars
Bterraform apply -var prod.tfvars
Cterraform apply --tfvars=prod.tfvars
Dterraform apply -config=prod.tfvars
Attempts:
2 left
💡 Hint
Check the Terraform CLI option to specify a variable file.
security
advanced
2: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?
AEncrypt the Terraform.tfvars file and commit the encrypted file to version control
BStore sensitive values in Terraform.tfvars and commit the file to version control
CUse environment variables or secret management tools instead of storing sensitive data in Terraform.tfvars
DWrite sensitive data directly in Terraform configuration files
Attempts:
2 left
💡 Hint
Think about how to avoid exposing secrets in code repositories.
🧠 Conceptual
expert
2: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"
}
Aus-east-1
Bus-west-2
CTerraform will raise an error due to conflicting values
Deu-central-1
Attempts:
2 left
💡 Hint
Remember the order of precedence for variable values in Terraform.