002 · Domain 6: Advanced Module Usage and Registry Practices · 10% of the exam
Task 6.3: Use the Terraform registry to build or update a configuration
Consuming registry modules well: source addresses, version constraints, the standard module structure, private registry hosts and credentials in the CLI configuration file.
Study it
Registry modules: sources, versions and private registries
Lesson coming
Sample questions
Try each one before opening the answer. Every option is explained, with the HashiCorp documentation page that proves it.
Question 1 · choose 1
A team publishes its network module to the organization's private registry as app.terraform.io/acme/network/aws. The repository has an examples/basic directory that other teams copy into their own repositories. How should the module block in examples/basic/main.tf set source?
Asource = "../../", pointing the example at the code in the same commit
Bsource = "app.terraform.io/acme/network/aws" with a version constraint
Csource = "./modules/network", the nested-module path inside the repository
DCopy the module's resources into the example instead of calling it
Show the answer and why
Asource = "../../", pointing the example at the code in the same commit
Incorrect
Examples are copied into other repositories, where a relative path points nowhere, so HashiCorp recommends the external address.
Bsource = "app.terraform.io/acme/network/aws" with a version constraint
Correct
Module blocks in examples should use the address an external caller would use, so copied examples work unchanged.
Csource = "./modules/network", the nested-module path inside the repository
Incorrect
That path only resolves inside this repository; a copied example would not find it.
DCopy the module's resources into the example instead of calling it
Incorrect
An example should show how to call the module, not duplicate its resources.
Examples are meant to be copied into other repositories, so the standard module structure has their module blocks use the address an external caller would use.
A registry module has nested modules under modules/. One has a README.md and one does not. How does the standard module structure treat the one without?
AAs an internal module, not meant for outside use
BAs invalid, as the registry rejects the module
CAs the module's main entry point
DAs an example to copy
Show the answer and why
AAs an internal module, not meant for outside use
Correct
Nested modules with a README.md are usable by external users; without one, a nested module is considered internal.
BAs invalid, as the registry rejects the module
Incorrect
Missing nested READMEs only change how the module is classified.
CAs the module's main entry point
Incorrect
The root of the repository is the primary entry point.
DAs an example to copy
Incorrect
Examples live under examples/.
Add a README.md to any nested module that callers are meant to use directly.