Courseiva
Read, generate and modify configurationhardMultiple ChoiceObjective-mapped

TF-004 Read, generate and modify configuration Practice Question

A module requires an input variable named 'vpc_id'. How should the calling configuration pass the VPC ID from another module's output?

⚠ Common exam trap

The Terraform exam often tests the misconception that module outputs require an explicit `.outputs.` attribute, leading candidates to choose Option A, when in fact Terraform flattens outputs into direct module attributes for simplicity.

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, when you need to reference an output from a child module, the syntax is `module.<module_name>.<output_name>`. The `.outputs.` prefix is not used; Terraform automatically exposes module outputs as direct attributes of the module resource. Therefore, `module.vpc.vpc_id` correctly retrieves the `vpc_id` output from the module named `vpc`.

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.outputs.vpc_id

    Why it's wrong here

    The syntax `module.vpc.outputs.vpc_id` is incorrect for referencing module outputs in Terraform. While modules do define outputs, they are directly exposed as attributes of the module block itself, not nested under an explicit `outputs` keyword. The correct approach is to access the output directly using `module.<MODULE_NAME>.<OUTPUT_NAME>` without the intermediate `.outputs` attribute.

  • vpc_id = var.vpc_id

    Why it's wrong here

    Using `var.vpc_id` would attempt to reference an input variable named `vpc_id` defined within the *current* Terraform configuration or module where this assignment is being made. This is not suitable when the intent is to retrieve an output value from a *separate, already defined module* named `vpc`. The `var.` prefix is exclusively for accessing input variables, not outputs from other modules.

  • vpc_id = vpc.module.vpc_id

    Why it's wrong here

    The syntax `vpc.module.vpc_id` is structurally incorrect and will result in a parsing error in Terraform. When referencing an output from a called module, the `module` keyword must always precede the local name assigned to that module instance. The correct order is `module.<LOCAL_MODULE_NAME>.<OUTPUT_NAME>`, making `vpc.module` an invalid construct for this purpose.

  • vpc_id = module.vpc.vpc_id

    Why this is correct

    This syntax, `vpc_id = module.vpc.vpc_id`, is the correct and standard method for referencing an output value from a module in Terraform. The `module` keyword signifies that a module instance is being referenced, `vpc` is the local name given to that specific module instance within the configuration, and `vpc_id` is the name of the output variable defined within the `vpc` module itself. This allows the output of one module to be used as an input for another resource or module.

About these practice questions

Courseiva writes every TF-004 question from scratch — 428 in total, each with an explanation and a wrong-answer breakdown. None are copied from real exams or dumps. 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.