Terraform Configuration File Loading — Auto-Load Rules and Best Practices
Which TWO statements about Terraform configuration files are correct? (Choose two.)
Quick Answer
The correct answer is that variable definitions files can have a .tfvars.json extension, and Terraform automatically loads terraform.tfvars without requiring any flags. This is because Terraform’s configuration file loading behavior is designed to auto-load any file named exactly terraform.tfvars or terraform.tfvars.json, as well as any file ending in .auto.tfvars or .auto.tfvars.json, from the current working directory. On the HashiCorp Terraform Associate TF-003 exam, this concept tests your understanding of implicit versus explicit variable file loading, and a common trap is assuming Terraform loads .tf files recursively—it does not, as it only processes the root directory by default. Another frequent mistake is thinking the -var-file flag accepts comma-separated lists, but you must repeat the flag for each file. To remember this, think of the “auto” in .auto.tfvars as “automatic loading,” and note that JSON support is a direct extension of the standard .tfvars format.
Answer choices
Why each option matters
Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.
Correct answer & explanation
✓
A file named terraform.tfvars is automatically processed.
Option B is correct because Terraform automatically loads a file named terraform.tfvars (as well as terraform.tfvars.json and any files matching *.auto.tfvars or *.auto.tfvars.json) from the current working directory to populate input variable values without requiring an explicit flag. Option E is correct because Terraform supports variable definitions files in JSON format, and these must use the .tfvars.json extension (e.g., terraform.tfvars.json or *.auto.tfvars.json) so Terraform parses them as JSON rather than HCL. Option A is wrong because Terraform only loads .tf and .tf.json files in the current working directory, not files in subdirectories, unless those directories are referenced as modules. Option C is wrong because backend configuration can be placed in any .tf file in the root module (commonly backend.tf) and does not need to share a file with the provider block. Option D is wrong because the -var-file flag takes a single file per occurrence and cannot accept a comma-separated list; multiple files require repeating the flag.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
All .tf files in subdirectories are automatically loaded.
Why it's wrong here
Terraform loads only the root module's own .tf files; subdirectories become separate modules that must be referenced explicitly via module blocks. Automatic recursive loading is tempting if you assume filesystem-wide discovery, but that applies only within a single module directory.
- ✓
A file named terraform.tfvars is automatically processed.
Why this is correct
Terraform automatically loads `terraform.tfvars` at plan and apply time, so variable values defined there need no explicit `-var-file` flag. This satisfies the stem's requirement for automatic processing, unlike arbitrary `.tfvars` files, which Terraform ignores unless passed explicitly via the command line.
- ✗
The backend configuration must be defined in the same file as the provider configuration.
Why it's wrong here
Backend and provider blocks may sit in any .tf file within the same module; Terraform merges them. Requiring co-location is tempting for tidiness, but the actual constraint is only that backend configuration cannot use variables or references.
- ✗
The -var-file flag accepts a comma-separated list of variable files.
Why it's wrong here
The -var-file flag takes exactly one file per occurrence; multiple files require repeating the flag. A comma-separated list is tempting because other CLI tools accept lists, but Terraform parses the whole string as a single filename and errors.
- ✓
Variable definitions files can have .tfvars.json extension.
Why this is correct
Terraform accepts variable definitions files with either `.tfvars` or `.tfvars.json` extensions, so JSON-formatted values load correctly during plan and apply. This satisfies the stem's requirement for a correct statement about configuration files, as `.tfvars.json` is explicitly supported for assigning variable values.
Go deeper
Related to this question
About these practice questions
One of 434 original TF-004 practice questions on Courseiva, each with a full explanation and wrong-answer analysis — not exam dumps or protected exam content. Learn why practice questions differ from exam dumps →
Same concept, more angles
1 more way this is tested on TF-004
These questions test the same concept from different angles. Work through them to make sure you can recognise it however the exam phrases it.
Variation 1. Which TWO statements about Terraform's handling of input variables are true?
medium- A.All variables must be assigned a value before running terraform plan.
- B.Variable values cannot be overridden using environment variables.
- ✓ C.The terraform.tfvars file is automatically loaded by Terraform.
- D.Default values for variables can only be set using a .tfvars file.
- ✓ E.Variables can be declared in a .tf file using the 'variable' block.
Why C: Option C is correct because Terraform automatically loads a file named terraform.tfvars (or terraform.tfvars.json) from the current working directory when running commands like terraform plan and terraform apply, without requiring an explicit -var-file flag. Option E is correct because input variables are declared in configuration files using the variable block, e.g. variable "region" { type = string }, which defines the variable's name, type, and optional default. Option A is false because variables with a default value, or those not referenced in the configuration, do not need to be assigned before terraform plan; only variables lacking a default and actually used must be supplied. Option B is false because Terraform does read environment variables prefixed with TF_VAR_ (e.g. TF_VAR_region) to assign variable values. Option D is false because default values are set with the default argument inside the variable block, not via a .tfvars file, which is instead used to assign values at runtime.
JA
Written by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
This TF-004 practice question is part of Courseiva's free HashiCorp certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the TF-004 exam.