OpenTofu "Backend configuration changed" in CI
OpenTofu detected that the backend block in your configuration no longer matches what the working directory was initialized with. It stops and asks you to reinitialize, choosing whether to migrate the existing state or reconfigure fresh.
What this error means
tofu init fails with "Error: Backend configuration changed" and "A change in the backend configuration has been detected ... Run \"tofu 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 "tofu init
-migrate-state". If you wish to store the current configuration with no
changes to the state, use "tofu init -reconfigure".Common causes
The backend block or partial config changed
A bucket, key, region, or table value in the backend (or a -backend-config value) differs from the initialized settings.
Migrating a Terraform backend to OpenTofu
Switching the tool or moving to a different backend changes the recorded config, so tofu requires an explicit reinit decision.
How to fix it
Reconfigure when the state target is unchanged
If you are pointing at the same state and only the tool or metadata changed, reinitialize without moving state.
tofu init -reconfigureMigrate state when moving backends
When the state should move to a new backend, let tofu copy it during init.
tofu init -migrate-stateHow to prevent it
- Pass backend settings consistently via
-backend-configin CI. - Choose
-reconfigurevs-migrate-statedeliberately, not by retry. - Keep backend values in one source so they do not drift between runs.