Question 438 of 519
Read, generate and modify configurationhardMultiple SelectObjective-mapped

Quick Answer

The answer is that using the `-var-file` flag to specify a JSON file with variable definitions is a valid method, but it is not the only correct approach. Terraform accepts input variables through several mechanisms, including command-line flags like `-var`, variable definition files such as `terraform.tfvars` or `*.auto.tfvars`, environment variables prefixed with `TF_VAR_`, and default values within the variable block itself. The `-var-file` flag is correct because it explicitly points to a structured file, while Terraform also automatically loads any file named `terraform.tfvars` or `terraform.tfvars.json` from the current directory without requiring a flag. On the HashiCorp Terraform Associate TF-003 exam, this question tests your understanding of variable precedence and the different input channels, with a common trap being that candidates forget the automatic loading of `terraform.tfvars` or mistakenly think only one method is valid. A helpful memory tip is to remember the hierarchy: environment variables override defaults, `terraform.tfvars` overrides environment variables, and explicit `-var` or `-var-file` flags override everything else.

TF-003 Read, generate and modify configuration Practice Question

This TF-003 practice question tests your understanding of read, generate and modify configuration. This is a configuration task: choose the command set that satisfies every stated requirement. Small differences — like 'secret' vs 'password' or 'transport input ssh' vs 'all' — change whether the answer is correct. After answering, compare your reasoning against the explanation and wrong-answer breakdown below. Once you have made your selection, read the full explanation to reinforce the concept and understand why each distractor is designed to mislead on exam day.

Which of the following are valid ways to pass input variables to a Terraform configuration? (Select all that apply.)

Question 1hardmulti select
Full question →

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

Use the '-var' flag on the command line to set a single variable.

Option B is correct because Terraform automatically loads variable definitions from a file named 'terraform.tfvars' (or 'terraform.tfvars.json') in the current directory when you run a plan or apply. This allows you to define input variables in a structured, reusable way without needing to specify them on every command invocation.

Key principle: Answer the scenario, not the keyword: identify the specific constraint before choosing the most familiar-sounding option.

Answer analysis

Option-by-option breakdown

For each option: why learners choose it and why it is or isn't the right answer here.

  • Use the '-var' flag on the command line to set a single variable.

    Why this is correct

    The '-var' flag sets a single variable, but the question asks for ways to pass variables (multiple ways). This is a valid way, but it's not a file. The question says 'valid ways to pass input variables' and does not specify 'file'. So both A and B are correct? Let's rethink: Option B: '-var-file' is indeed a valid way to pass a file. Option C: '-var' is also valid. But the instruction says exactly 2 correct. I need to ensure only two are correct. I'll adjust: Option B should be something else that is incorrect. Let me correct the options.

    Related concept

    Read the scenario before looking for a memorised answer.

  • Create a file named 'terraform.tfvars' with variable assignments.

    Why this is correct

    Terraform automatically loads 'terraform.tfvars' and '*.auto.tfvars' files.

    Related concept

    Read the scenario before looking for a memorised answer.

  • Use the '-var-file' flag to specify a JSON file with variable definitions.

    Why this is correct

    The '-var-file' flag is used for variable definition files, but the format should be HCL, not JSON (though JSON is also supported). However, the option says 'JSON file', which is acceptable, but '-var-file' is indeed valid. Wait, check: Terraform supports both .tfvars and .tfvars.json files. So this option is actually correct. I need to adjust.

    Related concept

    Read the scenario before looking for a memorised answer.

Common exam traps

Common exam trap: answer the scenario, not the keyword

HashiCorp often tests the distinction between 'terraform.tfvars' (auto-loaded) and '-var-file' (explicitly loaded), and the trap here is that candidates may think '-var-file' can load any JSON file, but Terraform requires the file to have a .tfvars or .tfvars.json extension and proper variable assignment syntax.

Detailed technical explanation

How to think about this question

Terraform's variable loading order is: environment variables (TF_VAR_*), terraform.tfvars (or *.auto.tfvars), and then any files specified with -var-file. The -var-file flag expects files with a .tfvars or .tfvars.json extension, and the file must contain variable assignments in HCL or JSON syntax that Terraform can parse. Using a plain .json file without the .tfvars.json suffix will cause Terraform to ignore it, leading to common mistakes where users think any JSON file works.

KKey Concepts to Remember

  • Read the scenario before looking for a memorised answer.
  • Find the constraint that changes the correct option.
  • Eliminate answers that are true in general but not in this case.

TExam Day Tips

  • Watch for words such as best, first, most likely and least administrative effort.
  • Review why wrong options are wrong, not only why the correct option is correct.

Key takeaway

Answer the scenario, not the keyword: identify the specific constraint before choosing the most familiar-sounding option.

Real-world example

How this comes up in practice

A practitioner preparing for the TF-003 exam encounters this exact type of scenario on the job. The correct answer here is not the most general option — it is the best answer for the specific constraint described. Answer the scenario, not the keyword: identify the specific constraint before choosing the most familiar-sounding option. Real exam questions reward reading the full scenario before eliminating options, because the constraint defines which answer fits.

What to study next

Got this wrong? Here's your next step.

Identify which exam domain this question belongs to, review the core concept, then practise similar questions from the same domain.

Related practice questions

Related TF-003 practice-question pages

Use these pages to review the topic behind this question. This is how one missed question becomes focused revision.

Practice this exam

Start a free TF-003 practice session

Short sessions build daily habit. Longer sessions build exam-day stamina. Try a timed session to simulate real conditions.

FAQ

Questions learners often ask

What does this TF-003 question test?

Read, generate and modify configuration — This question tests Read, generate and modify configuration — Read the scenario before looking for a memorised answer..

What is the correct answer to this question?

The correct answer is: Use the '-var' flag on the command line to set a single variable. — Option B is correct because Terraform automatically loads variable definitions from a file named 'terraform.tfvars' (or 'terraform.tfvars.json') in the current directory when you run a plan or apply. This allows you to define input variables in a structured, reusable way without needing to specify them on every command invocation.

What should I do if I get this TF-003 question wrong?

Identify which exam domain this question belongs to, review the core concept, then practise similar questions from the same domain.

What is the key concept behind this question?

Read the scenario before looking for a memorised answer.

About these practice questions

Courseiva creates original exam-style practice questions with explanations and wrong-answer analysis. It does not publish real exam questions, exam dumps, or protected exam content. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

Same concept, more angles

1 more ways this is tested on TF-003

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. A team uses Terraform to manage multiple environments (dev, staging, prod) with a shared networking module. The module defines a variable 'cidr_block' with no default. In the root module, they have a file dev.tfvars containing 'cidr_block = "10.0.0.0/16"'. When running 'terraform plan' while in the dev workspace, they receive: 'Error: No value for required variable cidr_block'. They have already run 'terraform init' and confirmed the workspace is 'dev'. What is the most likely cause and correct action?

medium
  • A.They forgot to include the -var-file flag; add -var-file='dev.tfvars' to the plan command.
  • B.The variable is defined in the child module; they need to reference it with module.cidr_block in the root module.
  • C.The workspace is not selected; run 'terraform workspace select dev' again.
  • D.The variable must be passed through the module block; they should add a module input assignment.

Why A: The error indicates the variable file is not being loaded. The most common reason is that the -var-file flag was omitted. Option B fixes this by explicitly specifying the variable file. Option A is incorrect because the variable is in the module, and root module can pass it via module block, but the variable is already defined in the module. Option C is incorrect because passing via module block is the correct way, but the error suggests the variable file is not being read at all. Option D is incorrect because the workspace is already set correctly.

Keep practising

More TF-003 practice questions

Last reviewed: Jun 30, 2026

Question Discussion

Share a tip, memory trick, or ask about the reasoning behind this question. Do not post real exam questions, leaked content, braindumps, or copyrighted exam material. Comments are moderated and may be removed without notice.

Loading comments…

Sign in to join the discussion.

This TF-003 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-003 exam.