Courseiva
Understand Terraform basicshardMultiple SelectObjective-mapped

TF-004 Understand Terraform basics Practice Question

Which TWO of the following are valid ways to reference a resource attribute in Terraform?

⚠ Common exam trap

HashiCorp often tests the distinction between resource attributes, data source attributes, module outputs, and input variables, and the trap here is that candidates confuse data source references (like `data.aws_ami.ubuntu.id`) with resource attribute references, or they think `module.vpc.output` is a valid catch-all syntax for module outputs.

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

`module.vpc.vpc_id` directly references an output attribute from a module. In Terraform, module outputs are accessed using the syntax `module.<module_name>.<output_name>`, and `vpc_id` is a common output from VPC modules that exposes the ID of the created VPC resource.

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.output`

    Why it's wrong here

    This reference is syntactically incorrect for accessing a module output. While `module.vpc` correctly identifies an instantiated module named `vpc`, the subsequent `.output` is not a valid placeholder for an output name. Terraform requires the specific name of the output variable, such as `module.vpc.vpc_id`, to retrieve its value. This syntax would result in a parsing error during plan or apply, as `.output` is not a keyword or a valid attribute name in this context.

  • `data.aws_ami.ubuntu.id`

    Why it's wrong here

    Although the syntax `data.<TYPE>.<NAME>.<ATTRIBUTE>` is correctly demonstrated here for referencing an attribute of a data source, this option is invalid because data sources are distinct from resources. Data sources merely fetch information about existing infrastructure or external data, they do not manage or create infrastructure themselves. The question specifically asks for valid ways to reference a *resource* attribute, making this a technically correct reference to a data source attribute, but not a resource attribute.

  • `var.instance_type`

    Why it's wrong here

    This expression correctly references an input variable named `instance_type`. However, the question specifically asks for ways to reference a *resource attribute*. Variables are used to parameterize configurations and provide dynamic values, but they do not represent attributes of managed infrastructure resources themselves. Therefore, while `var.instance_type` is a valid Terraform expression for accessing a variable, it does not fulfill the requirement of referencing a resource attribute.

  • `module.vpc.vpc_id`

    Why this is correct

    This is a valid way to reference an attribute. It correctly accesses the `vpc_id` output from a child module named `vpc`. Module outputs are commonly used to expose specific attributes or computed values from resources managed within that module, making them accessible to the parent module or other parts of the configuration. This effectively references a value derived from a resource within the module, making it a valid answer.

  • `aws_instance.web.id`

    Why this is correct

    This is a valid and direct way to reference a resource attribute. It specifies the `id` attribute of an `aws_instance` resource that has been given the local name `web`. This syntax, `resource_type.resource_name.attribute_name`, is the standard and most common method for accessing specific attributes of managed infrastructure resources within a Terraform configuration. It directly retrieves a property of an infrastructure component managed by Terraform.

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.