TF-004 Read, generate and modify configuration Practice Question
A team wants to reuse a VPC module across multiple environments. They need to pass outputs from one module as inputs to another. Which configuration is correct?
⚠ Common exam trap
Many candidates confuse Terraform's module output syntax with the `outputs` block used in root modules or with AWS CloudFormation's `Fn::GetAtt`, leading them to add an extra `.outputs` or omit the `module.` prefix.
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
✓
module "vpc" { source = "./vpc" } module "app" { source = "./app" subnet_id = module.vpc.subnet_id }
In Terraform, module outputs are accessed using the syntax `module.<module_name>.<output_name>`, not `module.<module_name>.outputs.<output_name>` or `vpc.output.<output_name>`. The `outputs` attribute is not a valid path; Terraform automatically exposes all declared outputs of a module as attributes of the module object. Therefore, `module.vpc.subnet_id` correctly references the `subnet_id` output from the `vpc` module.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
module "vpc" { source = "./vpc" } module "app" { source = "./app" subnet_id = module.vpc.outputs.subnet_id }
Why it's wrong here
The syntax `module.vpc.outputs.subnet_id` is incorrect because Terraform directly exposes module outputs as attributes of the module instance itself. The `outputs` keyword is not part of the standard reference path for accessing module outputs. Instead, outputs from a module are accessed using the format `module.<MODULE_NAME>.<OUTPUT_NAME>`, making `module.vpc.subnet_id` the correct and idiomatic reference.
- ✗
module "vpc" { source = "./vpc" } module "app" { source = "./app" subnet_id = vpc.output.subnet_id }
Why it's wrong here
This option presents two distinct syntax errors: `vpc.output.subnet_id` incorrectly omits the `module.` prefix required to reference a named module instance, and it uses `.output` instead of directly referencing the output name. Terraform requires the full `module.<MODULE_NAME>.<OUTPUT_NAME>` syntax to correctly resolve the value exported by the module. Without `module.`, Terraform cannot identify the source of the `vpc` reference as a module instance.
- ✓
module "vpc" { source = "./vpc" } module "app" { source = "./app" subnet_id = module.vpc.subnet_id }
Why this is correct
This option correctly demonstrates the standard and recommended way to reference an output value from a Terraform module. The syntax `module.vpc.subnet_id` directly accesses the `subnet_id` output defined within the `vpc` module. This allows the `app` module to receive the necessary resource ID, establishing an explicit dependency and enabling resource sharing between different module instances.
- ✗
module "app" { source = "./app" subnet_id = module.vpc.subnet_id }
Why it's wrong here
This configuration is incorrect because it attempts to reference `module.vpc.subnet_id` without first defining a module named `vpc` in the current configuration. Terraform requires that any module instance referenced, such as `module.vpc`, must be explicitly declared using a `module` block with a unique name. Without the `module "vpc" { ... }` definition, Terraform cannot resolve the reference, leading to a configuration error during validation or planning.
Visual reference
Go deeper
Related to this question
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 →
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.