0
0
Terraformcloud~20 mins

Input variable precedence order 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
Variable Precedence in Terraform

In Terraform, multiple sources can provide values for input variables. Which source has the highest precedence when determining the final value of a variable?

AA value passed directly via the command line using -var
BA default value defined in the variable block
CA value set in environment variables with the TF_VAR_ prefix
DA value set in a terraform.tfvars file
Attempts:
2 left
💡 Hint

Think about which method directly overrides others when running Terraform commands.

🧠 Conceptual
intermediate
2:30remaining
Order of Variable Sources in Terraform

Arrange the following Terraform variable sources from highest to lowest precedence:

  • Default value in variable block
  • Environment variable with TF_VAR_ prefix
  • Command line -var option
  • terraform.tfvars file
A3,4,2,1
B3,2,4,1
C4,3,2,1
D2,3,4,1
Attempts:
2 left
💡 Hint

Remember that command line options override environment variables, which override tfvars files, which override defaults.

service_behavior
advanced
2:00remaining
Effect of Multiple Variable Sources on Terraform Plan

You have a variable region with a default value of us-east-1. You set an environment variable TF_VAR_region=us-west-2 and also pass -var='region=eu-central-1' on the command line. What region will Terraform use during the plan?

Aus-east-1
Bus-west-2
CTerraform will throw an error due to conflicting values
Deu-central-1
Attempts:
2 left
💡 Hint

Which input source has the highest priority?

security
advanced
2:30remaining
Security Implications of Variable Precedence

Which Terraform variable input method is the safest to store sensitive data like passwords, considering variable precedence and exposure risk?

AUsing environment variables with TF_VAR_ prefix
BStoring sensitive data in terraform.tfvars file checked into version control
CPassing sensitive data via command line -var option
DDefining sensitive data as default values in variable blocks
Attempts:
2 left
💡 Hint

Consider which method avoids exposing secrets in command history or version control.

Architecture
expert
3:00remaining
Resolving Variable Conflicts in Terraform Modules

You have a root module and a child module. The root module passes a variable instance_type with value t3.micro via -var. The child module has a variable instance_type with a default t2.small. The root module also sets instance_type in a terraform.tfvars file as t3a.small. Which instance_type value will the child module receive during apply?

At3a.small
BTerraform will fail due to conflicting variable values
Ct3.micro
Dt2.small
Attempts:
2 left
💡 Hint

Remember how variable values are passed from root to child modules and the precedence of input sources.