Terraform Input Variables — Declaration and Assignment Methods
Which TWO statements about Terraform's handling of input variables are true?
Quick Answer
The correct answer is that variables can be declared in a .tf file using the 'variable' block, and Terraform automatically loads a terraform.tfvars file for assignment. This is because the variable block defines the input variable's name, type, and optional default, while Terraform's default variable file, terraform.tfvars, is loaded automatically to supply values without requiring explicit -var-file flags. On the HashiCorp Terraform Associate TF-003 exam, this concept tests your understanding of declaration versus assignment methods, often appearing in questions that try to confuse you with the requirement that variables must be assigned before plan or that defaults are set in .tfvars files. A common trap is assuming environment variables with the TF_VAR_ prefix cannot override .tfvars values, but they can. Remember the memory tip: "Declare with variable, assign with tfvars, override with TF_VAR."
⚠ Common exam trap
TF-004 often tests the misconception that all variables must be assigned before plan, or that defaults can only come from .tfvars files, confusing declaration syntax with value assignment mechanisms.
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
✓
The terraform.tfvars file is automatically loaded by Terraform.
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.
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 variables must be assigned a value before running terraform plan.
Why it's wrong here
Terraform only requires values for variables lacking defaults; variables with defaults need no assignment before terraform plan. It is tempting because unset variables without defaults do prompt, but that applies only to those specific variables, not all of them, so the blanket claim is false.
- ✗
Variable values cannot be overridden using environment variables.
Why it's wrong here
Terraform does read variable values from TF_VAR_-prefixed environment variables, so they can be overridden that way. It is tempting because environment variables are not the primary mechanism, but Terraform explicitly supports TF_VAR_name, making this statement false.
- ✓
The terraform.tfvars file is automatically loaded by Terraform.
Why this is correct
Terraform automatically loads terraform.tfvars from the working directory without any explicit flag, alongside terraform.tfvars.json and *.auto.tfvars. This automatic loading removes the need to pass -var-file manually, satisfying the stem's requirement for a true statement about input variable handling.
- ✗
Default values for variables can only be set using a .tfvars file.
Why it's wrong here
Terraform sets defaults via the variable block's default argument; .tfvars files supply values at plan or apply time, overriding defaults rather than defining them. The option is tempting because .tfvars files are the standard mechanism for environment-specific values, and they would be the right choice when supplying distinct values per workspace or deployment.
- ✓
Variables can be declared in a .tf file using the 'variable' block.
Why this is correct
The variable block is Terraform's declarative mechanism for defining input variables, specifying type, default and description. Declaring variables this way lets configurations accept external values at plan and apply time, satisfying the stem's requirement for a true statement about input variable handling.
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 configuration files are correct? (Choose two.)
easy- A.All .tf files in subdirectories are automatically loaded.
- ✓ B.A file named terraform.tfvars is automatically processed.
- C.The backend configuration must be defined in the same file as the provider configuration.
- D.The -var-file flag accepts a comma-separated list of variable files.
- ✓ E.Variable definitions files can have .tfvars.json extension.
Why B: 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.
JA
Written and reviewed by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
Last reviewed September 2026 · checked against the official HashiCorp exam blueprint
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.