A CI job exports TF_VAR_region=eu-west-1, but terraform plan keeps using us-east-1. No -var or -var-file options are passed, and the variable's default is eu-central-1. Which explanation fits these symptoms?
Select an answer to reveal the explanation.
Short Explanation
TF_VAR_ environment variables sit near the bottom of the precedence ladder: they beat the default and nothing else. So if something else in the directory sets region, the environment gets outvoted. The trap is forgetting the auto-loaded files you never passed on the command line.
Full Explanation
Terraform loads root variable values from several sources and applies them in precedence order, with later sources overriding earlier ones: defaults, then TF_VAR_ environment variables, then terraform.tfvars, terraform.tfvars.json, any .auto.tfvars or .auto.tfvars.json files, and finally command-line -var and -var-file options. The plan shows neither the environment value nor the default, so some higher-precedence source in the working directory must be setting us-east-1, and an auto-loaded definition file is the usual culprit in CI checkouts. Environment variables are read during plan and apply, not only during init, and they never configure backends, since backend blocks cannot reference variables. Terraform matches the variable name after the TF_VAR_ prefix exactly as declared; the documentation notes the name is case-sensitive on operating systems with case-sensitive environments, so an unrelated TF_VAR_REGION would not override a variable named region. A default is the lowest-precedence source and applies only when nothing else sets the variable. Exam caveat: the same ordering explains why CI-specific values are better passed with -var-file than with environment variables when other definition files exist. Operational check: search the working directory for terraform.tfvars and *.auto.tfvars files and run terraform console to print var.region.