004 · Domain 4: Terraform configuration · 13% of the exam
Task 4.3: Use variables and outputs
Input variables with types, defaults, validation and every way to set them, the precedence order, locals for repeated expressions, and outputs for the CLI, other configurations and parent modules.
Study it
Input variables, precedence, locals and outputs
Lesson coming
Sample questions
Try each one before opening the answer. Every option is explained, with the HashiCorp documentation page that proves it.
Question 1 · choose 1
A pipeline exports TF_VAR_region=us-east-2, and the working directory also has a terraform.tfvars file with region = "us-west-2". No -var options are passed. Which value does Terraform use?
Aus-east-2, because environment variables take precedence over files
Bus-west-2, since terraform.tfvars outranks environment variables
CNeither; Terraform stops with an error about two conflicting values
Dus-east-2, because the variable is read from the shell before any file
Show the answer and why
Aus-east-2, because environment variables take precedence over files
Incorrect
Environment variables are near the bottom of the order, above only the default.
Bus-west-2, since terraform.tfvars outranks environment variables
Correct
In the precedence order, terraform.tfvars is above environment variables, which are only above the variable's default.
CNeither; Terraform stops with an error about two conflicting values
Incorrect
Multiple sources are allowed; the precedence order resolves them.
Dus-east-2, because the variable is read from the shell before any file
Incorrect
Load order does not decide; the precedence order does.
Environment variables sit near the bottom of the precedence order, above only the variable's default.