Terraform "Module source has changed" run terraform init in CI
By Kaveh Alemi·Latchkey
Terraform detected that a module block's source or version differs from what is recorded in the module manifest under .terraform. plan/apply stop until terraform init re-installs the module to match.
What this error means
plan or apply stops with "Error: Module source has changed" and "the source address was changed since this module was installed. Run \"terraform init\" ...".
Terraform
Error: Module source has changed
on main.tf line 5, in module "network":
5: source = "terraform-aws-modules/vpc/aws"
The source address was changed since this module was installed. Run "terraform init"
to install all modules required by this configuration.
Diagnose it: init, state, or credentials?
Terraform failures in CI are dominated by backend and credential problems rather than configuration errors. Confirm the runner can initialise, authenticate, and lock state before reading the plan.
Key .terraform caches on the config and lock files.
Do not carry a stale module manifest across edits.
Frequently asked questions
What causes Terraform "Module source has changed" run terraform init in CI?
There are 2 common causes: a module source or version was edited without re-init and ci plans on a stale module manifest. The source or version on a module block changed, but the job restored a cached .terraform from before the change.
How do I fix Terraform "Module source has changed" run terraform init in CI?
There are 2 fixes depending on which cause you have: re-run terraform init and bust the cache on module changes. Work through them in order, since the first is the most common.
What does Terraform "Module source has changed" run terraform init in CI actually mean?
plan or apply stops with "Error: Module source has changed" and "the source address was changed since this module was installed.
How do I stop Terraform "Module source has changed" run terraform init in CI happening again?
Init after any module source or version change. The prevention section lists 3 changes that keep it from recurring.