Courseiva
Interact with Terraform moduleseasyMultiple ChoiceObjective-mapped

TF-004 Interact with Terraform modules Practice Question

After applying a module that creates a VPC, a user wants to use the VPC ID in another resource within the root configuration. How should they reference the output from the module?

⚠ Common exam trap

The TF-003 exam often tests the exact syntax for referencing module outputs, and the trap here is that candidates confuse module output references with data source references (`data.`) or local values (`local.`), or they incorrectly use underscores instead of dots in the module path.

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

vpc_id = module.vpc.vpc_id

In Terraform, module outputs are accessed using the syntax `module.<module_name>.<output_name>`. Since the module is named `vpc` and it exposes an output called `vpc_id`, the correct reference is `module.vpc.vpc_id`. This allows the root configuration to consume the VPC ID created by the 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.

  • vpc_id = module.vpc.vpc_id

    Why this is correct

    This syntax, `module.<NAME>.<OUTPUT_NAME>`, is the canonical and correct way to reference an output value exported by a child module in Terraform. Here, `module.vpc` refers to the specific instance of the module named 'vpc' as defined in the calling configuration's `main.tf` or similar file. The `.vpc_id` then accesses the output variable explicitly defined within that `vpc` module, making its value available for use in other resources or outputs within the parent configuration. This pattern ensures clear and explicit data flow between module boundaries.

  • vpc_id = module_vpc.vpc_id

    Why it's wrong here

    The reference `module_vpc.vpc_id` is syntactically incorrect because it omits the mandatory `module.` prefix required to identify a child module. Terraform expects module references to follow the `module.<LOCAL_MODULE_NAME>.<OUTPUT_NAME>` pattern, where `LOCAL_MODULE_NAME` is the name given to the module block in the calling configuration. Without this explicit prefix, Terraform cannot correctly parse `module_vpc` as a module instance, leading to an unresolved reference or a parsing error during planning or applying.

  • vpc_id = data.module.vpc.vpc_id

    Why it's wrong here

    Using `data.module.vpc.vpc_id` is incorrect because the `data.` prefix is exclusively used for referencing data sources, which query information about existing infrastructure or external services. Module outputs, conversely, are values exported by child modules instantiated directly within the current configuration. Directly accessing a child module's output requires the `module.` prefix, not the `data.` prefix, as data sources and modules serve fundamentally different purposes in Terraform's reference system.

  • vpc_id = local.vpc_id

    Why it's wrong here

    The expression `local.vpc_id` attempts to reference a local value, which is an internal variable defined within the current configuration using a `locals` block. While a local value *could* be explicitly assigned the output of a module (e.g., `vpc_id = module.vpc.vpc_id`), `local.vpc_id` itself does not automatically derive from a module's output. This syntax is incorrect for directly accessing a module's exported value without an explicit local assignment, as local values must be defined before they can be referenced.

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.