{"record":{"id":"59b9743cee25a15a","repo":"hashicorp/terraform","slug":"found-unrecognized-resource-mode-59b974","errorCode":null,"errorMessage":"found unrecognized resource mode: ","messagePattern":"found unrecognized resource mode: ","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"internal/command/jsonformat/state.go","lineNumber":39,"sourceCode":"\tRootModule         jsonstate.Module            `json:\"root_module,omitempty\"`\n\tRootModuleOutputs  map[string]jsonstate.Output `json:\"outputs,omitempty\"`\n\n\tProviderFormatVersion string                            `json:\"provider_format_version\"`\n\tProviderSchemas       map[string]*jsonprovider.Provider `json:\"provider_schemas,omitempty\"`\n}\n\nfunc (state State) Empty() bool {\n\treturn len(state.RootModuleOutputs) == 0 && len(state.RootModule.Resources) == 0 && len(state.RootModule.ChildModules) == 0\n}\n\nfunc (state State) GetSchema(resource jsonstate.Resource) *jsonprovider.Schema {\n\tswitch resource.Mode {\n\tcase jsonstate.ManagedResourceMode:\n\t\treturn state.ProviderSchemas[resource.ProviderName].ResourceSchemas[resource.Type]\n\tcase jsonstate.DataResourceMode:\n\t\treturn state.ProviderSchemas[resource.ProviderName].DataSourceSchemas[resource.Type]\n\tdefault:\n\t\tpanic(\"found unrecognized resource mode: \" + resource.Mode)\n\t}\n}\n\nfunc (state State) renderHumanStateModule(renderer Renderer, module jsonstate.Module, opts computed.RenderHumanOpts, first bool) {\n\tif len(module.Resources) > 0 && !first {\n\t\trenderer.Streams.Println()\n\t}\n\n\tfor _, resource := range module.Resources {\n\n\t\tif !first {\n\t\t\trenderer.Streams.Println()\n\t\t}\n\n\t\tif first {\n\t\t\tfirst = false\n\t\t}\n","sourceCodeStart":21,"sourceCodeEnd":57,"githubUrl":"https://github.com/hashicorp/terraform/blob/c9def3e214014c1188faabfc4a5bde5095139765/internal/command/jsonformat/state.go#L21-L57","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"null","handlingStrategy":"validation","validationCode":"// Go: validate state JSON resource modes before rendering\nfunc validateStateModes(stateJSON []byte) error {\n\twalk := func(res []map[string]interface{}) error {\n\t\tfor _, r := range res {\n\t\t\tif m, _ := r[\"mode\"].(string); m != \"managed\" && m != \"data\" {\n\t\t\t\treturn fmt.Errorf(\"unrecognized state resource mode %q\", m)\n\t\t\t}\n\t\t}\n\t\treturn nil\n\t}\n\tvar s struct {\n\t\tRoot map[string]interface{} `json:\"values\"`\n\t}\n\tif err := json.Unmarshal(stateJSON, &s); err == nil {\n\t\tif res, ok := s.Root[\"root_module\"].(map[string]interface{}); ok {\n\t\t\tif rr, ok := res[\"resources\"].([]map[string]interface{}); ok {\n\t\t\t\treturn walk(rr)\n\t\t\t}\n\t\t}\n\t}\n\treturn nil\n}","typeGuard":null,"tryCatchPattern":"// Go: recover around state rendering\ndefer func() {\n\tif r := recover(); r != nil {\n\t\terr = fmt.Errorf(\"state rendering failed: %v\", r)\n\t}\n}()\nstate.RenderHuman()","preventionTips":["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."],"tags":["terraform","state","json-format","panic","resource-mode","internal-bug"],"analyzedSha":"c9def3e214014c1188faabfc4a5bde5095139765","analyzedAt":"2026-08-07T15:39:49.278Z","schemaVersion":2},"datasetVersion":"2026-08-07T21:17:07.882Z"}