0
0
Terraformcloud~5 mins

Input variable precedence order in Terraform - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is the highest precedence source for Terraform input variables?
Command-line flags (e.g., -var or -var-file) have the highest precedence and override all other sources.
Click to reveal answer
intermediate
List the order of precedence for Terraform input variables from highest to lowest.
1. Command-line flags (-var, -var-file) 2. Environment variables (TF_VAR_name) 3. terraform.tfvars files and other tfvars files 4. Default values in variable blocks
Click to reveal answer
beginner
How do environment variables affect Terraform input variables?
Environment variables prefixed with TF_VAR_ set the value of input variables and override values from tfvars files and defaults, but are overridden by command-line flags.
Click to reveal answer
beginner
What happens if a variable is not set by any source in Terraform?
Terraform uses the default value defined in the variable block. If no default is set and the variable is required, Terraform will prompt the user for input.
Click to reveal answer
intermediate
Why is understanding input variable precedence important in Terraform?
It helps avoid unexpected values by knowing which source will override others, ensuring predictable and controlled infrastructure configuration.
Click to reveal answer
Which source has the lowest precedence for Terraform input variables?
AEnvironment variables
BDefault values in variable blocks
Cterraform.tfvars files
DCommand-line flags
If a variable is set in both an environment variable and a terraform.tfvars file, which value does Terraform use?
AValue from terraform.tfvars file
BValue from default in variable block
CTerraform will throw an error
DValue from environment variable
How can you override a Terraform variable value without changing any files?
APass the value using a command-line flag
BUse a terraform.tfvars file
CTerraform does not allow overriding without files
DSet a default value in the variable block
What prefix must environment variables have to set Terraform input variables?
ATF_VAR_
BTF_INPUT_
CTERRAFORM_VAR_
DVAR_
If a required variable has no default and is not set by any source, what does Terraform do?
AUses a null value
BThrows an error and stops
CPrompts the user to enter a value
DUses an empty string
Explain the order in which Terraform applies input variable values from different sources.
Think about which source you would want to override others when running Terraform.
You got /4 concepts.
    Describe what happens when a Terraform variable is not set anywhere and has no default value.
    Consider how Terraform ensures required variables have values.
    You got /3 concepts.