TA-002-P · Question #293
A user has created a module called "my_test_module" and committed it to GitHub. Over time, several commits have been made with updates to the module, each tagged in GitHub with an incremental version
The correct answer is D. source = "git::https://example.com/my_test_module.git?ref=v1.0.4". Terraform uses the ?ref= query parameter in a Git source URL to pin a module to a specific tag, branch, or commit SHA.
Question
A user has created a module called "my_test_module" and committed it to GitHub. Over time, several commits have been made with updates to the module, each tagged in GitHub with an incremental version number. Which of the following lines would be required in a module configuration block in terraform to select tagged version v1.0.4?
Options
- Asource = "git::https://example.com/my_test_module.git@tag=v1.0.4"
- Bsource = "git::https://example.com/my_test_module.git&ref=v1.0.4"
- Csource = "git::https://example.com/my_test_module.git#tag=v1.0.4"
- Dsource = "git::https://example.com/my_test_module.git?ref=v1.0.4"
How the community answered
(20 responses)- C5% (1)
- D95% (19)
Why each option
Terraform uses the ?ref= query parameter in a Git source URL to pin a module to a specific tag, branch, or commit SHA.
The @tag= syntax is not valid for Terraform Git module sources and is not recognized by Terraform's module loader.
The &ref= syntax is invalid because & is used to chain additional query parameters but the reference must start with ?ref= as the first query string parameter.
The #tag= syntax is invalid for Terraform Git sources because # denotes a URL fragment in HTTP, not a query parameter, and Terraform does not use it for version selection.
The correct syntax for referencing a specific Git tag in a Terraform module source is the ?ref= query parameter appended to the repository URL. The value git::https://example.com/my_test_module.git?ref=v1.0.4 instructs Terraform to check out the commit associated with the v1.0.4 tag when downloading the module.
Concept tested: Git module source ?ref= syntax for version pinning
Source: https://developer.hashicorp.com/terraform/language/modules/sources#selecting-a-revision
Topics
Community Discussion
No community discussion yet for this question.