nerdexam
HashiCorp

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.

Interact with Terraform modules

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

How the community answered

(20 responses)
  • C
    5% (1)
  • D
    95% (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.

Asource = "git::https://example.com/my_test_module.git@tag=v1.0.4"

The @tag= syntax is not valid for Terraform Git module sources and is not recognized by Terraform's module loader.

Bsource = "git::https://example.com/my_test_module.git&ref=v1.0.4"

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.

Csource = "git::https://example.com/my_test_module.git#tag=v1.0.4"

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.

Dsource = "git::https://example.com/my_test_module.git?ref=v1.0.4"Correct

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

#Terraform modules#Module source#Git modules#Module versioning

Community Discussion

No community discussion yet for this question.

Full TA-002-P Practice