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.SchemaVersion

View on GitHub (pinned to c9def3e214)

Solutions

  1. 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.
  2. Restore state from a known-good backup (Terraform keeps terraform.tfstate.backup) before the corruption.
  3. Upgrade Terraform Core to a stable release; report if reproducible.
  4. 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

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


AI-assisted analysis of hashicorp/terraform@c9def3e214 (2026-08-07). Data as JSON: /api/errors/f27763d869df46d8. Report an issue: GitHub.