A test file sets bucket_prefix = "test" and region = "us-east-1" in a file-level variables block, and six run blocks use those values. One run must check behaviour when bucket_prefix is "audit" while still using the same region. What is the cleanest way to do this?
Select an answer to reveal the explanation.
Short Explanation
File-level variables are the house defaults; a run-level variables block is a per-room override. Set just the one value you want to change in that run, and everything else flows down from the file.
Full Explanation
Terraform test files support variables blocks at two levels. Values in the file-level block are passed to every run block, and a variables block inside a run block overrides only the keys it sets for that run, leaving the other file-level values in place. Setting bucket_prefix = "audit" inside the one run therefore changes that run alone while region continues to come from the file. A test file may contain zero or one file-level variables block; position in the file is irrelevant because Terraform processes variables and provider blocks before executing runs, so a second block is neither valid nor scoped to the run that follows it. Command-line -var values cannot win here: values defined in test files take the highest precedence, overriding environment variables, variable files and command-line input, and -var would apply to every run in any case. Automatic variable files placed in the test directory, such as terraform.tfvars, apply to all tests in that directory rather than to the next run block, and they would also lose to the file-level value. Exam caveat: run-level variables can reference outputs of earlier runs and file-level variables, whereas file-level variables can refer only to global variables. Operational check: run terraform test -verbose and confirm the overridden run plans a bucket named with the audit prefix while the others keep test.