hashicorp/terraform · error
resource %s has an unsupported mode %s
Error message
resource %s has an unsupported mode %s
What it means
Thrown by the JSON state serializer when a resource address mode is neither managed nor data. Mirrors error 621 but applies to state serialization (the marshal of existing state, not planned changes). Reaching the default branch is an internal inconsistency: Terraform only defines managed and data resource modes.
Source
Thrown at internal/command/jsonstate/state.go:406
Type: resAddr.Type,
Name: resAddr.Name,
ProviderName: r.ProviderConfig.Provider.String(),
}
if k != nil {
index := k.Value()
if current.Index, err = ctyjson.Marshal(index, index.Type()); err != nil {
return nil, err
}
}
switch resAddr.Mode {
case addrs.ManagedResourceMode:
current.Mode = ManagedResourceMode
case addrs.DataResourceMode:
current.Mode = DataResourceMode
default:
return ret, fmt.Errorf("resource %s has an unsupported mode %s",
resAddr.String(),
resAddr.Mode.String(),
)
}
schema := schemas.ResourceTypeConfig(
r.ProviderConfig.Provider,
resAddr.Mode,
resAddr.Type,
)
// It is possible that the only instance is deposed
if ri.Current != nil {
if schema.Version != int64(ri.Current.SchemaVersion) {
return nil, fmt.Errorf("schema version %d for %s in state does not match version %d from the provider", ri.Current.SchemaVersion, resAddr, schema.Version)
}
current.SchemaVersion = ri.Current.SchemaVersionView on GitHub (pinned to c9def3e214)
Solutions
- Inspect the raw state file (`terraform show -json` on the offending state, or open terraform.tfstate) and locate the resource with an empty/invalid mode field.
- Restore state from a known-good backup (Terraform keeps terraform.tfstate.backup) before the corruption.
- Upgrade Terraform Core to a stable release; report if reproducible.
- If the resource is unrecoverable, use `terraform state rm` to drop it, then re-import.
Defensive patterns
Strategy: validation
Validate before calling
// Validate every resource in state has a known renderable mode before JSON serialization.
for _, m := range state.ResourceInstanceModes() {
if m != addrs.ManagedResourceMode && m != addrs.DataResourceMode {
return fmt.Errorf("state contains resource with unsupported mode %q", m.String())
}
} Try / catch
if _, err := jsonstate.MarshalState(state, schemas); err != nil {
// Likely state corruption — fall back to text show and prompt to restore backup.
return err
} Prevention
- Never hand-edit terraform.tfstate mode fields.
- Keep terraform.tfstate.backup; verify state integrity with `terraform plan` after migrations.
- Use `terraform state` subcommands instead of editing state JSON directly.
When it happens
Trigger: Produced during state-to-JSON serialization (jsonstate) when iterating resources in state and resAddr.Mode is not ManagedResourceMode or DataResourceMode. Triggered by `terraform show -json` on a state file or any command that renders state as JSON.
Common situations: Indicates a corrupt state file or a Terraform Core bug writing a resource with an uninitialized mode. Can occur after manual edits to state JSON, after a failed/aborted migration, or with prerelease builds. Not produced by ordinary configuration.
Related errors
- resource %s has an unsupported mode %s
- %s: cannot serialize value marked as %#v for inclusion in a
- found unrecognized resource mode:
- found unrecognized resource mode:
- missing field in set: %s.%s
AI-assisted analysis of hashicorp/terraform@c9def3e214 (2026-08-07).
Data as JSON: /api/errors/f27763d869df46d8.
Report an issue: GitHub.