Courseiva
Read, generate and modify configurationeasyMultiple SelectObjective-mapped

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.

Options B and E are correct. Terraform automatically processes a file named terraform.tfvars if it exists in the configuration directory, making option B correct. Variable definitions files can also have a .tfvars.json extension, as stated in option E. Option A is incorrect because Terraform does not load .tf files from subdirectories by default; only the root directory is scanned. Option C is incorrect because the backend configuration does not have to be defined in the same file as the provider configuration; they can be in separate files. Option D is incorrect because the -var-file flag does not accept a comma-separated list; you must use multiple -var-file flags to specify multiple variable files.

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 only loads .tf files from the root directory unless using -chdir or specifying paths.

  • A file named terraform.tfvars is automatically processed.

    Why this is correct

    Terraform automatically loads terraform.tfvars if present in the root directory.

  • The backend configuration must be defined in the same file as the provider configuration.

    Why it's wrong here

    Backend configuration can be defined in a separate file and is merged during initialization.

  • The -var-file flag accepts a comma-separated list of variable files.

    Why it's wrong here

    The -var-file flag only accepts a single file path; use multiple -var-file flags for multiple files.

  • Variable definitions files can have .tfvars.json extension.

    Why this is correct

    Terraform supports both .tfvars and .tfvars.json variable definition files.

About these practice questions

One of 428 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 →

How Courseiva writes practice questions · Editorial policy

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: Options C and E are correct. Option C is correct because Terraform automatically loads terraform.tfvars and any *.auto.tfvars files in the working directory. Option E is correct because variables are declared using the 'variable' block in .tf files. Option A is incorrect: variables can have default values and are not required to be assigned before terraform plan. Option B is incorrect: variable values can be overridden using environment variables with the TF_VAR_ prefix. Option D is incorrect: default values are set within the variable block using the default argument, not in .tfvars files.

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.