Courseiva
Use Terraform outside the core workfloweasyMultiple ChoiceObjective-mapped

TF-004 Use Terraform outside the core workflow Practice Question

A developer wants to use a module from the Terraform Registry in their configuration. Which block is required in the root module?

⚠ Common exam trap

A common trap in Terraform is confusing the `module` block with a `resource` block. Some candidates incorrectly think modules are declared as resources or data sources, but the correct syntax is `module "<name>" { source = "..." }`. The `source` argument is required to locate the module, and without it Terraform cannot fetch and instantiate the module's resources.

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 "my-module" { source = "..." }

To use a module from the Terraform Registry, you must declare a `module` block in your root configuration. The `source` argument inside that block specifies the module's location (e.g., a registry path like `hashicorp/consul/aws`). This is the only way Terraform knows to fetch, version, and instantiate the module's resources.

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 "my-module" { source = "..." }

    Why this is correct

    The `module` block is the correct and exclusive construct for calling a reusable collection of Terraform configurations. It encapsulates a set of resources, data sources, and other modules, promoting reusability and organization within your infrastructure code. The mandatory `source` argument specifies the module's origin, which can be the Terraform Registry, a local path, or a remote Git repository, enabling Terraform to fetch and utilize its defined infrastructure components.

  • resource "my-module" { ... }

    Why it's wrong here

    A `resource` block is fundamentally designed to declare and manage a single, specific infrastructure object within a cloud provider or service, such as an AWS S3 bucket or an Azure Virtual Machine. It defines the desired state for that individual component, allowing Terraform to create, update, or delete it. Modules, in contrast, are higher-level abstractions that group multiple resources and configurations, not a single provisionable entity themselves.

  • provider "my-module" { source = "..." }

    Why it's wrong here

    The `provider` block is specifically used to configure the authentication and connection details for a particular infrastructure provider, like `aws` or `azurerm`, enabling Terraform to interact with its APIs. It defines settings such as region, access keys, or assumed roles necessary for managing resources within that provider. Modules, however, are collections of configurations that *utilize* providers to create infrastructure, rather than being a provider configuration themselves, making this syntax incorrect for module calls.

  • data "my-module" { ... }

    Why it's wrong here

    A `data` block serves the distinct purpose of querying and retrieving information about existing infrastructure components or external data sources that Terraform does not directly manage. It allows configurations to reference dynamic values, such as an existing VPC ID or the latest AMI for a specific OS, without creating new resources. Modules, conversely, are primarily used to define and provision new infrastructure, making a `data` block an inappropriate construct for calling a module.

About these practice questions

This TF-004 question is part of Courseiva's 428-question bank — original exam-style content with full explanations and wrong-answer analysis, never real exam questions or exam 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.