A team is using a module from the public Terraform Registry. They want to ensure that the module is pinned to a specific version to avoid unexpected changes. Which approach should they use?
Trap 1: Use 'required_providers' block in the root module to lock the…
The 'required_providers' block is used for provider versioning, not module versioning.
Trap 2: Add a 'version' argument inside the module block.
While adding a version argument is part of the correct approach, this option is incomplete because it does not include the source attribute, which is required to reference the module.
Trap 3: Store the module locally in a vendor directory and reference it by…
Storing the module locally avoids registry versioning issues but is not the standard approach for pinning a registry module version.
- A
Use 'required_providers' block in the root module to lock the module version.
Why wrong: The 'required_providers' block is used for provider versioning, not module versioning.
- B
Add a 'version' argument inside the module block.
Why wrong: While adding a version argument is part of the correct approach, this option is incomplete because it does not include the source attribute, which is required to reference the module.
- C
Set 'version' in the module's source attribute, e.g., source = "terraform-aws-modules/vpc/aws" with version = "3.2.0".
Correct. This example shows the full syntax: source and version as separate arguments in the module block, which correctly pins the module version.
- D
Store the module locally in a vendor directory and reference it by path.
Why wrong: Storing the module locally avoids registry versioning issues but is not the standard approach for pinning a registry module version.