You changed where state lives and want to keep it
CommonA new bucket, key, region or backend type, or switching from local state to a remote backend. The existing state must come along.
Confirm
git diff HEAD~1 -- '*.tf' | grep -A6 'backend'
A changed bucket, key, path, region or backend type
Fix
- Back up first: terraform state pull > backup.tfstate (with the old settings still initialised), or copy the old state file.
- Then migrate: terraform init -migrate-state, answer yes (or add -force-copy in a script).
- Run terraform plan and expect No changes before doing anything else.
terraform init -migrate-state
Copies state to the new backend settings; add -force-copy to skip the prompt in automation. Reproduced on Terraform 1.14.0.