Terraform Cloud "Error migrating" state to HCP Terraform in CI
Init tried to migrate existing state into an HCP Terraform workspace and failed. The target workspace may already hold state, the migration needs -migrate-state, or the interactive confirmation is missing in a non-interactive CI run.
What this error means
terraform init fails with "Error: Error migrating the workspace state" or refuses to overwrite existing remote state during a backend change.
Error: Error migrating the workspace state
The target workspace "prod-network" already contains state. Terraform will not
overwrite it without explicit confirmation.Common causes
The target workspace already has state
Migrating into a workspace that already holds state would overwrite it, so Terraform refuses without explicit confirmation.
Non-interactive init without migration flags
CI runs terraform init -input=false, so the interactive migration prompt cannot be answered and the migration aborts.
How to fix it
Migrate deliberately into an empty workspace
- Target an empty workspace, or confirm you intend to replace existing state.
- Run init with
-migrate-stateand-input=false. - Verify the new remote state after migration.
terraform init -migrate-state -input=falseUse a fresh workspace to avoid overwrite
Point the cloud block at a new workspace so migration does not collide with pre-existing state.
How to prevent it
- Migrate into empty workspaces to avoid overwrite conflicts.
- Pass
-input=falsein CI and-migrate-stateonly when moving state. - Back up state before any backend migration.