After a module refactor removed the variable legacy_subnet, a shared common.auto.tfvars file still assigns legacy_subnet. Meanwhile, one engineer's script still runs terraform plan -var="legacy_subnet=10.0.9.0/24". How does Terraform treat these two assignments?
Select an answer to reveal the explanation.
Short Explanation
Terraform grades the leftovers by how deliberately you typed them. A stale line in a tfvars file gets a warning, because files are shared and might cover several configurations. But typing -var for something that doesn't exist? That's an error, since you clearly meant it.
Full Explanation
Terraform handles values for undeclared variables differently by source. Environment variables with the TF_VAR_ prefix that match no variable block are ignored. Assignments in variable definition files, such as common.auto.tfvars, produce a warning about an undeclared variable, which helps catch misspellings without breaking shared files that serve more than one configuration. An assignment with -var on the command line for a variable that does not exist is an error, and the plan stops. Saying both are silently ignored describes only the environment variable case. Saying both cause errors overstates the file behaviour; Terraform intentionally warns there. Reversing the two, so that the file fails and the command-line value is quietly accepted, inverts the documented rule. Exam caveat: a warning in automation logs is easy to miss, so stale tfvars entries can linger for a long time; treat undeclared-variable warnings as cleanup items. Operational check: run terraform plan without the -var to see the warning naming legacy_subnet, remove the line from common.auto.tfvars, and update or retire the engineer's script so it no longer passes the removed variable.