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.
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)- A93% (53)
- B2% (1)
- C2% (1)
- D4% (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.
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.
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.
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.
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
Community Discussion
No community discussion yet for this question.