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\" ...".
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
- Run
terraform initso the module manifest is rebuilt for the new source/version. - If you cache
.terraform, key the cache on the module files so edits bust it. - Re-run plan/apply against the freshly installed module.
terraform init -input=false
terraform plan -input=falseBust the cache on module changes
Include the module configuration and lock file in the cache key so a source change forces a fresh init.
- 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
.terraformcaches on the config and lock files. - Do not carry a stale module manifest across edits.