hashicorp/terraform · critical
found unrecognized resource mode:
Error message
found unrecognized resource mode:
What it means
A panic in `State.GetSchema` (internal/command/jsonformat/state.go:39) fired from the default branch when a state resource's `Mode` is neither managed nor data. This mirrors the plan-side invariant (error 963) but for state rendering: every resource in a well-formed state JSON must have a recognized mode. The panic includes the offending mode string.
Source
Thrown at internal/command/jsonformat/state.go:39
RootModule jsonstate.Module `json:"root_module,omitempty"`
RootModuleOutputs map[string]jsonstate.Output `json:"outputs,omitempty"`
ProviderFormatVersion string `json:"provider_format_version"`
ProviderSchemas map[string]*jsonprovider.Provider `json:"provider_schemas,omitempty"`
}
func (state State) Empty() bool {
return len(state.RootModuleOutputs) == 0 && len(state.RootModule.Resources) == 0 && len(state.RootModule.ChildModules) == 0
}
func (state State) GetSchema(resource jsonstate.Resource) *jsonprovider.Schema {
switch resource.Mode {
case jsonstate.ManagedResourceMode:
return state.ProviderSchemas[resource.ProviderName].ResourceSchemas[resource.Type]
case jsonstate.DataResourceMode:
return state.ProviderSchemas[resource.ProviderName].DataSourceSchemas[resource.Type]
default:
panic("found unrecognized resource mode: " + resource.Mode)
}
}
func (state State) renderHumanStateModule(renderer Renderer, module jsonstate.Module, opts computed.RenderHumanOpts, first bool) {
if len(module.Resources) > 0 && !first {
renderer.Streams.Println()
}
for _, resource := range module.Resources {
if !first {
renderer.Streams.Println()
}
if first {
first = false
}
View on GitHub (pinned to c9def3e214)
Solutions
- Pull the state with the same Terraform version that wrote it, then `terraform state push`/re-save if needed.
- Validate the state JSON `resource.mode` values are 'managed' or 'data' before rendering.
- Restore state from a known-good backup (`.terraform.tfstate.backup`) if corruption is suspected.
- Report a bug if it reproduces with stock Terraform on a freshly-pulled state.
Example fix
null
Defensive patterns
Strategy: validation
Validate before calling
// Go: validate state JSON resource modes before rendering
func validateStateModes(stateJSON []byte) error {
walk := func(res []map[string]interface{}) error {
for _, r := range res {
if m, _ := r["mode"].(string); m != "managed" && m != "data" {
return fmt.Errorf("unrecognized state resource mode %q", m)
}
}
return nil
}
var s struct {
Root map[string]interface{} `json:"values"`
}
if err := json.Unmarshal(stateJSON, &s); err == nil {
if res, ok := s.Root["root_module"].(map[string]interface{}); ok {
if rr, ok := res["resources"].([]map[string]interface{}); ok {
return walk(rr)
}
}
}
return nil
} Try / catch
// Go: recover around state rendering
defer func() {
if r := recover(); r != nil {
err = fmt.Errorf("state rendering failed: %v", r)
}
}()
state.RenderHuman() Prevention
- Read state only with the Terraform version that wrote it.
- Restore from `.terraform.tfstate.backup` if state looks corrupt.
- Avoid external tools that rewrite state JSON.
- Validate state `resource.mode` values before programmatic processing.
When it happens
Trigger: Rendering a JSON state (`terraform show -json` of state, or state rendering paths) where a resource's `mode` field is an unrecognized value. Caused by a corrupt or version-incompatible state JSON, or state produced by a tool that wrote a non-standard mode.
Common situations: State files produced by a different/newer Terraform version read back by an older one; state migration gone wrong; third-party state manipulation tools; manually edited state JSON.
Related errors
- found unrecognized resource mode:
- resource %s has an unsupported mode %s
- resource %s has an unsupported mode %s
- unrecognized action slice:
- Workspace data missing from plan file. Current workspace is
AI-assisted analysis of hashicorp/terraform@c9def3e214 (2026-08-07).
Data as JSON: /api/errors/59b9743cee25a15a.
Report an issue: GitHub.