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.

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 ""Module source has changed""?
The source or version on a module block changed, but the job restored a cached .terraform from before the change.
How do I fix "Module source has changed"?
Re-run terraform init

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card