TA-002-P · Question #185
You have a Terraform configuration file where a variable itemNum is defined as follows: variable "itemNum" { default = 3} You also have a defined the following environment variables in your shell…
The correct answer is D. 4. Terraform evaluates variable values in a strict precedence order, from lowest to highest: (1) default value in the variable block (3), (2) TF_VAR_ environment variables (TF_VAR_itemNum=9), (3) terraform.tfvars / .auto.tfvars files (7), (4) -var or -var-file flags on the command…
Question
You have a Terraform configuration file where a variable itemNum is defined as follows:
variable "itemNum" { default = 3} You also have a defined the following environment variables in your shell: TF_itemNum =6, TF_VAR_itemNum =9. You also have a terraform.tfvars file with the following contents itemNum = 7 When you run the following apply command, what is the value assigned to the itemNum variable? terraform apply -var itemNum =4
Options
- A10
- B6
- C1
- D4
- E3
How the community answered
(52 responses)- A8% (4)
- B2% (1)
- C6% (3)
- D83% (43)
- E2% (1)
Explanation
Terraform evaluates variable values in a strict precedence order, from lowest to highest: (1) default value in the variable block (3), (2) TF_VAR_* environment variables (TF_VAR_itemNum=9), (3) terraform.tfvars / *.auto.tfvars files (7), (4) -var or -var-file flags on the command line (4). The -var flag has the highest precedence and always wins. Note that TF_itemNum is NOT a valid Terraform environment variable - only variables prefixed with TF_VAR_ are recognized. Because the command includes -var itemNum=4, the final value is 4.
Topics
Community Discussion
No community discussion yet for this question.