hashicorp/terraform · error
Error loading state: %[3]s Terraform failed to load the
Error message
Error loading state:
%[3]s
Terraform failed to load the default state from the %[1]q %[2]s.
State migration cannot occur unless the state can be loaded.
State migration has been aborted. The state in both the
source and the destination remain unmodified. Please resolve the
above error and try again.
What it means
Returned by the single-to-single migration when the source state manager cannot be obtained (`opts.Source.StateMgr(...)` returns error diagnostics). Terraform cannot begin migration without a readable source state, so it aborts with both backends unmodified.
Source
Thrown at internal/command/meta_backend_migrate.go:279
return fmt.Errorf("Migration aborted by user.")
}
// Copy the default state
opts.sourceWorkspace = currentWorkspace
// now switch back to the default env so we can acccess the new backend
m.SetWorkspace(backend.DefaultStateName)
return m.backendMigrateState_s_s(opts)
}
// Single state to single state, assumed default state name.
func (m *Meta) backendMigrateState_s_s(opts *backendMigrateOpts) error {
log.Printf("[INFO] backendMigrateState: single-to-single migrating %q workspace to %q workspace", opts.sourceWorkspace, opts.destinationWorkspace)
sourceState, sDiags := opts.Source.StateMgr(opts.sourceWorkspace)
if sDiags.HasErrors() {
return fmt.Errorf(strings.TrimSpace(
errMigrateSingleLoadDefault), opts.SourceType, sDiags.Err())
}
if err := sourceState.RefreshState(); err != nil {
return fmt.Errorf(strings.TrimSpace(
errMigrateSingleLoadDefault), opts.SourceType, err)
}
// Do not migrate workspaces without state.
if sourceState.State().Empty() {
log.Print("[TRACE] backendMigrateState: source workspace has empty state, so nothing to migrate")
return nil
}
srcWord := backendHumanName(opts.Source)
dstWord := backendHumanName(opts.Destination)
var err error
destinationState, sDiags := opts.Destination.StateMgr(opts.destinationWorkspace)View on GitHub (pinned to d32a084675)
Solutions
- Validate the source backend block (`terraform init -backend=false` to isolate, then re-enable).
- Confirm the source workspace/key exists and the configured identity can read it.
- Re-authenticate and retry `terraform init`.
- Inspect the embedded `%[3]s` diagnostic for the precise backend-reported cause.
Defensive patterns
Strategy: validation
Validate before calling
# Validate the source backend can construct a state manager before init:
# confirm bucket/key/workspace resolve and identity has read access.
aws s3 ls "s3://${SRC_BUCKET}/${SRC_KEY}" >/dev/null \
|| echo "source state object unreadable"
terraform init Try / catch
# Source construction failure is usually config/auth, not transient:
if ! terraform init -input=false >/tmp/init.log 2>&1; then
grep -q 'Error loading state' /tmp/init.log \
&& { echo 'Source backend config/auth invalid' >&2; exit 2; }
cat /tmp/init.log; exit 1
fi Prevention
- Keep backend config in VCS and review changes that alter key/workspace paths.
- Refresh credentials immediately before init in CI.
- Run `terraform init -backend=false` to isolate config-vs-backend issues.
When it happens
Trigger: Fires at the top of `backendMigrateState_s_s` when `opts.Source.StateMgr(opts.sourceWorkspace)` returns diagnostics with errors — invalid workspace name, backend misconfiguration, or auth failure constructing the manager.
Common situations: Backend `key`/`workspace` path is malformed, the source backend's config references a missing bucket/container, or constructing the state client fails due to expired credentials.
Related errors
- Error copying state from the previous %[1]q %[2]s to the new
- Error locking state: %s
- Error asking for state migration action: %s
- Migration aborted by user.
- Error inspecting states in the %q %s: %s Prior to migra
AI-assisted analysis of hashicorp/terraform@d32a084675 (2026-08-11).
Data as JSON: /api/errors/1a2698ecc9781d88.
Report an issue: GitHub.