Skip to content
Latchkey

Terraform "Module source has changed" run terraform init in CI

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.

Terminal
terraform init -backend=true -input=false
terraform validate
terraform providers
terraform plan -input=false -no-color -detailed-exitcode
#   0 = no changes, 2 = changes, 1 = error

Common causes

A module source or version was edited without re-init

The source or version on a module block changed, but the job restored a cached .terraform from before the change.

CI plans on a stale module manifest

A cache restored the old .terraform/modules/modules.json that no longer matches the edited configuration.

How to fix it

Re-run terraform init

  1. Run terraform init so the module manifest is rebuilt for the new source/version.
  2. If you cache .terraform, key the cache on the module files so edits bust it.
  3. Re-run plan/apply against the freshly installed module.
Terminal
terraform init -input=false
terraform plan -input=false

Bust the cache on module changes

Include the module configuration and lock file in the cache key so a source change forces a fresh init.

.github/workflows/ci.yml
- uses: actions/cache@v4
  with:
    path: .terraform
    key: tf-${{ hashFiles('**/*.tf', '.terraform.lock.hcl') }}

How to prevent it

  • Init after any module source or version change.
  • 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.

Related guides

References

Not every red build is your code. Latchkey repairs the ones that are not, on the runner. Start free → 30-day trial · No credit card