A variable instance_type is set in terraform.tfvars as t3.micro. The same run is started with -var="instance_type=t3.large". Which value does Terraform use?
- A.
t3.large - B.
t3.micro, becauseterraform.tfvarsalways wins. - C.
The default value declared in the variable block.
- D.
Terraform raises a conflict error.
Show answer and explanation
Answer: A
Values from -var and -var-file on the command line have the highest precedence, so they override terraform.tfvars and environment variables.
t3.micro, becauseterraform.tfvarsalways wins.:terraform.tfvarsis loaded before command-line options.- The default value declared in the variable block.: Defaults are used only when no other value is supplied.
- Terraform raises a conflict error.: Precedence resolves the conflict silently.