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

> Fix Terraform "Error: Module source has changed" in CI - a module block source or version was edited since the last init, so the installed module no longer matches the config.

Source: https://latchkey.dev/learn/terraform/tfmod-module-source-has-changed-in-ci  
Updated: 2026-06-30

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.

## 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
```

> A cancelled CI job can leave the state lock held, which blocks every later run with an error that reads like a permissions failure. Confirm no apply is genuinely running before force-unlocking.

## FAQ

### 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.

---

Latchkey runs CI/CD that repairs its own failures. Agent entry points: https://latchkey.dev/agent.txt, https://latchkey.dev/openapi.json, https://latchkey.dev/llms.txt
