Skip to content
Latchkey

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

Terraform
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

  1. If you are pointing at a backend that already holds the right state, init with -reconfigure.
  2. Pass the same -backend-config values the config expects.
  3. Re-run plan against the reconfigured backend.
Terminal
terraform init -reconfigure -input=false -backend-config=backend.hcl

Migrate state when moving backends

To move existing state to a new backend, init with -migrate-state so Terraform copies it across.

Terminal
terraform init -migrate-state -input=false

How to prevent it

  • Keep -backend-config values stable across CI runs.
  • Choose -reconfigure vs -migrate-state deliberately.
  • Do not restore a .terraform from a different backend.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →