nerdexam
HashiCorp

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…

Use the Terraform CLI (terraform plan, apply, destroy, fmt, init, validate, workspace, import, taint, providers, output)

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)
  • A
    8% (4)
  • B
    2% (1)
  • C
    6% (3)
  • D
    83% (43)
  • E
    2% (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

#Terraform variables#Variable precedence#CLI arguments#Environment variables

Community Discussion

No community discussion yet for this question.

Full TA-002-P Practice