Courseiva
Interact with Terraform modulesmediumMultiple ChoiceObjective-mapped

TF-004 Interact with Terraform modules Practice Question

Exhibit

Refer to the exhibit.
```hcl
module "networking" {
  source = "./modules/networking"
  vpc_cidr = "10.0.0.0/16"
}
```
The module in `./modules/networking` has `variables.tf`:
```hcl
variable "vpc_cidr" {
  description = "CIDR block for the VPC"
  type = string
}
variable "environment" {
  description = "Environment name"
  type = string
}
```

After running `terraform plan`, the user receives an error: `Error: Missing required variable`. The variable 'vpc_cidr' is provided. What is the most likely cause?

⚠ Common exam trap

Many candidates assume the error is about the variable they did provide, rather than recognizing that other required variables may be missing.

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 module requires a variable 'environment' that is not passed.

The error 'Missing required variable' indicates that a variable required by the module has not been provided. Even though 'vpc_cidr' is supplied, the module likely defines a required input variable named 'environment' without a default value, and the user did not pass it in the module block. Terraform enforces that all required variables without defaults must be explicitly set by the caller.

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 requires a variable 'environment' that is not passed.

    Why this is correct

    A Terraform module's `variables.tf` file likely declares a variable named 'environment' without specifying a `default` value. When a variable lacks a default, it becomes mandatory and must be explicitly provided when the module is called. The `terraform plan` command fails because it cannot resolve a value for this required input, preventing the configuration from being evaluated and a plan from being generated.

  • The module block syntax is incorrect.

    Why it's wrong here

    The error is not indicative of incorrect module block syntax, which typically involves issues with the `module` keyword, `source` argument, or block delimiters. Terraform's parser would flag a syntax error immediately, often with a specific message about unexpected tokens or missing braces. In this scenario, the module block structure itself is valid, but a required input variable within that valid structure is simply not supplied.

  • The variable 'vpc_cidr' is misspelled.

    Why it's wrong here

    A misspelling error for a variable like 'vpc_cidr' would typically manifest as Terraform reporting an 'unsupported argument' or 'unknown variable' within the module block where it's being passed. The error described, however, points to a *missing* required variable, implying Terraform correctly identified an expected input that was simply not supplied. The variable name itself is likely correct, but its value was omitted.

  • The variable 'vpc_cidr' conflicts with a provider variable.

    Why it's wrong here

    A conflict between a module variable and a provider variable is an uncommon scenario and would present differently, perhaps as a type constraint violation or an explicit error about duplicate declarations in specific contexts. Terraform's variable resolution prioritizes module inputs, and a simple missing variable error does not suggest an underlying conflict. The issue is purely that a necessary input for the module's operation was not provided.

Visual reference

192.168.1.0 /24 256 addresses (254 usable) 192.168.1.0 /25 Subnet A 128 addr (126 usable) 192.168.1.128 /25 Subnet B 128 addr (126 usable) Borrowing 1 bit from host portion creates 2 subnets (/25)

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

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.