Skip to content
Latchkey

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.

terraform
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

  1. Target an empty workspace, or confirm you intend to replace existing state.
  2. Run init with -migrate-state and -input=false.
  3. Verify the new remote state after migration.
Terminal
terraform init -migrate-state -input=false

Use 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=false in CI and -migrate-state only when moving state.
  • Back up state before any backend migration.

Frequently asked questions

What causes ""Error migrating" state"?
Migrating into a workspace that already holds state would overwrite it, so Terraform refuses without explicit confirmation.
How do I fix "Error migrating" state?
Migrate deliberately into an empty workspace

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card