Courseiva
Interact with Terraform modulesmediumMultiple ChoiceObjective-mapped

TF-004 Interact with Terraform modules Practice Question

A developer creates a module in a subdirectory of their Terraform configuration and wants to reference it from the root module. The directory structure is: /terraform-project/modules/networking. Which source argument should they use in the module block?

⚠ Common exam trap

HashiCorp often tests the distinction between local module paths (which must start with `./` or `../`) and registry module paths (which use a namespace/name/provider format), causing candidates to mistakenly choose an absolute path or a registry-style source for a local module.

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

source = "./modules/networking"

Terraform resolves local module paths relative to the root module's directory. The path `./modules/networking` correctly references the `networking` subdirectory within the `modules` folder, starting from the root of the Terraform configuration. This is the standard syntax for referencing a local module in a subdirectory.

Answer analysis

Option-by-option breakdown

For each option: why learners choose it and why it is or isn't the right answer here.

  • source = "file:///terraform-project/modules/networking"

    Why it's wrong here

    This source string uses the `file://` URI scheme, which explicitly denotes an absolute path on the local filesystem. While technically a valid way to specify an absolute file location, Terraform typically expects a simple filesystem path (relative or absolute) for local modules, not a URI. Using `file://` for local module references is generally not considered best practice, as it adds unnecessary verbosity and can be less portable than a direct path.

  • source = "/terraform-project/modules/networking"

    Why it's wrong here

    This path is an absolute filesystem path, starting from the root directory of the operating system. While Terraform can resolve absolute paths, this approach is highly non-portable across different development environments or CI/CD pipelines. The exact `/terraform-project/modules/networking` path is unlikely to be consistent across various machines, making the configuration fragile and difficult to share or execute reliably in diverse contexts.

  • source = "./modules/networking"

    Why this is correct

    This source string correctly uses a relative path, starting with `./`, indicating that the module is located in a `modules/networking` subdirectory relative to the current Terraform configuration file. This is the standard and most portable method for referencing local modules within the same repository. Terraform resolves this path from the directory containing the calling module, ensuring consistency across different execution environments.

  • source = "hashicorp/networking/aws"

    Why it's wrong here

    This format specifies a public or private Terraform Registry module source, implying that Terraform should fetch the module from a remote registry (e.g., `registry.terraform.io`). The components `hashicorp`, `networking`, and `aws` represent the namespace, module name, and provider, respectively. This is incorrect for referencing a local module residing in a subdirectory of the current project, as it would attempt to download a non-existent remote module instead of using the local source.

Visual reference

Client Recursive Resolver Root DNS (13 root servers) TLD DNS (.com, .org, …) Authoritative example.com query IP addr answer

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.