TF-004 Read, generate and modify configuration Practice Question
A DevOps engineer is managing a multi-cloud infrastructure using Terraform. The team relies on a module sourced from the Terraform Registry to deploy a standard web application. This module defines an input variable called 'instance_count' with a default value of 2. For the production environment, the engineer wants to deploy 3 instances. They create a root module configuration that references the module. In the root module's main.tf, they write a block that sets instance_count = 3. However, when they run terraform plan, the output indicates that the module will still use instance_count = 2. The engineer double-checks the configuration: the root module's main.tf is syntactically correct, the module source points to the correct registry module and version, and they have run terraform init and terraform validate without errors. What is the most likely reason the variable override is not taking effect?
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 root module defines instance_count as a local value rather than passing it as an argument to the module block.
The scenario describes the engineer setting instance_count = 3 in the root module, but if it is defined as a local value (e.g., locals { instance_count = 3 }) rather than passed as an argument to the module block (e.g., module "web" { source = "...", instance_count = 3 }), the module will not receive the override and will use its default value. Option A is incorrect: module version does not prevent variable overrides; the module source is correct. Option B is incorrect: the variable is declared in the child module (it has a default). Option C is incorrect: terraform init is not required for configuration changes that don't affect providers or modules; terraform validate passed, indicating no syntax error.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
The module version specified does not support variable overrides; the engineer must use a different module.
Why it's wrong here
Terraform's module system inherently allows calling modules to pass values to any input variable declared within a child module, regardless of the module's version. Module versions primarily manage feature sets, bug fixes, and breaking changes in the module's internal logic, not the fundamental mechanism of variable input. Therefore, the ability to override variables is a core design principle of Terraform modules and is not dependent on a specific module version or disabled by any version.
- ✗
The variable 'instance_count' is not declared as an input variable in the child module's variables.tf.
Why it's wrong here
If 'instance_count' were not declared as an input variable within the child module's `variables.tf` (or any `.tf` file in the module), Terraform would produce an error during the `terraform plan` or `terraform validate` phase, indicating an undeclared variable. The problem statement implies that the plan runs without such an error, suggesting the variable is indeed declared, possibly with a default value, which is a common practice for optional or default-configured inputs.
- ✗
The engineer forgot to run terraform init after modifying the root module's configuration.
Why it's wrong here
`terraform init` is primarily responsible for initializing the working directory, which includes downloading provider plugins, configuring the backend, and downloading remote modules. Modifying a local variable or a module argument within the root module's configuration does not alter these foundational components. Since the engineer is attempting to override an existing module variable, `terraform init` would not be necessary to apply this specific configuration change, especially if `init` and `validate` have already run successfully.
- ✓
The root module defines instance_count as a local value rather than passing it as an argument to the module block.
Why this is correct
To pass a value to an input variable of a child module, it must be explicitly defined as an argument directly within the `module` block declaration in the calling configuration. A local value, defined using the `locals` block in the root module, is an internal construct for simplifying expressions within that *same* root module. It does not automatically get passed down or override variables within a child module; it must be referenced and then passed as a module argument.
Go deeper
Related to this question
About these practice questions
This TF-004 question is part of Courseiva's 428-question bank — original exam-style content with full explanations and wrong-answer analysis, never real exam questions or exam dumps. Learn why practice questions differ from exam dumps →
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.