nerdexam
HashiCorp

TA-002-P · Question #399

Which is the best way to specify a tag of v1.0.0 when referencing a module stored in Git (for example git::https://example.com/vpc.git)?

The correct answer is A. Append ref=v1. 0. 0 argument to the source path. When referencing a Terraform module stored in a Git repository, a specific tag or commit is selected by appending a ref query parameter to the source URL.

Interact with Terraform modules

Question

Which is the best way to specify a tag of v1.0.0 when referencing a module stored in Git (for example git::https://example.com/vpc.git)?

Options

  • AAppend ref=v1. 0. 0 argument to the source path
  • BAdd version = "1.0.0" parameter to module block
  • CNothing " modules stored on GitHub always default to version 1.0.0
  • DModules stored on GitHub do not support versioning

How the community answered

(57 responses)
  • A
    93% (53)
  • B
    2% (1)
  • C
    2% (1)
  • D
    4% (2)

Why each option

When referencing a Terraform module stored in a Git repository, a specific tag or commit is selected by appending a ref query parameter to the source URL.

AAppend ref=v1. 0. 0 argument to the source pathCorrect

Terraform's Git source protocol supports the ref argument appended to the URL as a query string (e.g., git::https://example.com/vpc.git?ref=v1.0.0) to pin the module to a specific tag, branch, or commit hash. This is the correct and documented mechanism for versioning Git-based module sources, distinct from the version argument used for Terraform Registry modules.

BAdd version = "1.0.0" parameter to module block

The 'version' parameter in a module block is only valid for modules sourced from the Terraform Registry - Git-based sources use the ref URL query argument instead.

CNothing " modules stored on GitHub always default to version 1.0.0

Git-sourced modules do not default to any fixed version automatically; without a ref argument, Terraform uses the repository's default branch, not a pinned version.

DModules stored on GitHub do not support versioning

Git-sourced modules fully support versioning through the ref query argument, making this statement factually incorrect.

Concept tested: Pinning Git module source to a specific version tag

Source: https://developer.hashicorp.com/terraform/language/modules/sources#selecting-a-revision

Topics

#Terraform modules#Git module source#Module versioning#Source URL syntax

Community Discussion

No community discussion yet for this question.

Full TA-002-P Practice