TF-Associate-004 - Terraform modules (11% of the exam) - Section 5a
Explain how Terraform sources modules.
The source argument selects a local path, the public or a private registry, a Git or HTTP source, and init retrieves it. Candidates should distinguish a local module from a registry module and know that changing source requires re-running init.
module source argumentlocal versus registry moduleTerraform Registrymodule retrieval during init
Practice question for this objective
lock_openFree sampleTerraform modulesmedium
A team edits the source of an existing module block to point at a new registry version, then runs 'terraform plan' straight away without re-running init. What is the most likely outcome?
module "vpc" {
source = "terraform-aws-modules/vpc/aws"
version = "5.1.0"
}
AThe plan silently uses the newly requested version because Terraform downloads modules automatically at plan time.
BThe plan proceeds using the previously installed version and prints no warning, because the source change takes effect only on the next apply.
CThe plan errors and asks the practitioner to run 'terraform init' because the module version currently installed does not satisfy the changed configuration.check_circle Correct
DTerraform automatically re-runs init as part of plan, downloads the new version, and continues without any prompt.
Terraform installs modules during init, so changing a module source or version requires re-running init before plan can proceed. Module retrieval and installation occur only during terraform init. When the configured source or version no longer matches what is installed under '.terraform/modules', plan halts and instructs the user to run init to install the requested module.
Why A is wrong: This assumes plan performs retrieval, but module installation happens during init, so plan does not fetch the new version on its own.
Why B is wrong: It is tempting to think Terraform quietly keeps the old module, but it detects that the installed module no longer matches the configuration and stops rather than proceeding silently.
Why C is correct: Module retrieval is an init-time step, so a changed source or version that is not yet installed causes plan to fail and direct the user to run init first.
Why D is wrong: Plan never triggers init implicitly; the two are distinct commands, so Terraform will not fetch modules or providers as a side effect of planning.
Answers that look right on this material and are not. Each one is a distractor from a different question in the TF-Associate-004 bank for this domain.
It treats the address as a local path and reads the files directly from the repository working copy already on disk.
errorWhy it is wrong: A 'git::' prefix marks a remote Git source, so Terraform does not treat it as a local path and there is no assumption of an existing working copy.
terraform get -update, which is required instead of init for registry modules.
errorWhy it is wrong: terraform get can refresh module installs, but it is not a replacement for init and init already performs module installation, so calling it the required step is wrong.
Use source = "github.com/hashicorp/terraform-aws-consul" with no version argument, letting init pick the latest.
errorWhy it is wrong: A github.com shorthand is treated as a Git source rather than a registry shorthand, so the registry version argument does not apply, and omitting a pin defeats the pinning the engineer asked for.