Terraform "Backend configuration changed" in CI
Terraform detected that the current backend configuration does not match the one recorded in .terraform. It stops and asks you to run init with -reconfigure (ignore old state) or -migrate-state (move state) before it proceeds.
What this error means
terraform init stops with "Error: Backend configuration changed" and "A change in the backend configuration has been detected ... run \"terraform init\" with the \"-reconfigure\" or \"-migrate-state\" flags".
Error: Backend configuration changed
A change in the backend configuration has been detected, which may require
migrating existing state.
If you wish to attempt automatic migration of the state, use "terraform init
-migrate-state". If you wish to store the current configuration with no changes
to the state, use "terraform init -reconfigure".Common causes
The backend block or -backend-config values changed
A bucket, key, region, or other backend setting differs from what init previously recorded, so Terraform will not silently switch backends.
A stale .terraform from a different backend
A cache restored .terraform initialized against a different backend than the current config declares.
How to fix it
Reconfigure when the change is intentional and state stays put
- If you are pointing at a backend that already holds the right state, init with
-reconfigure. - Pass the same
-backend-configvalues the config expects. - Re-run plan against the reconfigured backend.
terraform init -reconfigure -input=false -backend-config=backend.hclMigrate state when moving backends
To move existing state to a new backend, init with -migrate-state so Terraform copies it across.
terraform init -migrate-state -input=falseHow to prevent it
- Keep
-backend-configvalues stable across CI runs. - Choose
-reconfigurevs-migrate-statedeliberately. - Do not restore a
.terraformfrom a different backend.