Courseiva
Interact with Terraform moduleseasyMultiple ChoiceObjective-mapped

TF-004 Interact with Terraform modules Practice Question

After adding a new module sourced from a Git repository with a specific tag, terraform init reports that the module is being downloaded. What is the best practice to ensure the team uses the same version of this module consistently?

⚠ Common exam trap

In Terraform, candidates often confuse version constraints (for registry modules) with source URL parameters (for Git, Mercurial, or other VCS sources), leading them to incorrectly apply registry-style versioning to Git-sourced modules.

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

Use a Git tag, like '?ref=v1.0.0', to pin the version.

Using a Git tag (e.g., `?ref=v1.0.0`) in the module source URL pins the module to a specific, immutable commit. This ensures that every team member downloads the exact same version of the module, regardless of future changes to the default branch. Terraform resolves the tag to a commit hash and caches it, providing deterministic and reproducible infrastructure.

Answer analysis

Option-by-option breakdown

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

  • Use a version constraint in the module block, e.g., version = 1.0.0.

    Why it's wrong here

    Terraform's `version` argument within a `module` block is specifically designed for modules sourced from a Terraform Module Registry (e.g., `hashicorp/aws/s3`). When sourcing a module directly from a Git repository, this argument is ignored because Git itself does not inherently understand or enforce these registry-style version constraints. To pin a Git-sourced module, a Git-specific reference mechanism must be used, as the `version` argument is not applicable in this context.

  • Specify the source as the branch name 'main'.

    Why it's wrong here

    Referencing a Git module by a branch name, such as `ref=main`, is problematic for ensuring consistent deployments across environments or over time. Branches are inherently mutable; new commits can be pushed, altering the module's code without any change to the Terraform configuration. This mutability can lead to unexpected behavior, broken infrastructure, or non-reproducible deployments if the `main` branch is updated between Terraform runs, making it an unreliable pinning strategy.

  • Use the 'latest' tag in the source URL.

    Why it's wrong here

    While Git allows tags, using a generic `latest` tag in the source URL is not a reliable method for pinning a module version. Unlike specific semantic version tags (e.g., `v1.0.0`), a `latest` tag can be moved or re-pointed to a newer commit at any time, making it mutable. This mutability means that subsequent Terraform runs could fetch different code, undermining the goal of reproducible infrastructure deployments and potentially introducing unexpected changes.

  • Use a Git tag, like '?ref=v1.0.0', to pin the version.

    Why this is correct

    Using a specific Git tag, such as `?ref=v1.0.0`, is the recommended and most robust method for pinning a module's version when sourcing directly from a Git repository. Git tags are immutable pointers to a specific commit in the repository's history, ensuring that the exact same module code is fetched every time Terraform runs. This immutability is crucial for achieving consistent and reproducible infrastructure deployments across all environments and team members, preventing unexpected changes and simplifying debugging.

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

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.