{"record":{"id":"998f8a553f061d9f","repo":"hashicorp/terraform","slug":"found-unrecognized-resource-mode","errorCode":null,"errorMessage":"found unrecognized resource mode: ","messagePattern":"found unrecognized resource mode: ","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"internal/command/jsonformat/plan.go","lineNumber":50,"sourceCode":"\tOutputChanges      map[string]jsonplan.Change        `json:\"output_changes,omitempty\"`\n\tResourceChanges    []jsonplan.ResourceChange         `json:\"resource_changes,omitempty\"`\n\tResourceDrift      []jsonplan.ResourceChange         `json:\"resource_drift,omitempty\"`\n\tRelevantAttributes []jsonplan.ResourceAttr           `json:\"relevant_attributes,omitempty\"`\n\tDeferredChanges    []jsonplan.DeferredResourceChange `json:\"deferred_changes,omitempty\"`\n\tActionInvocations  []jsonplan.ActionInvocation       `json:\"action_invocations,omitempty\"`\n\n\tProviderFormatVersion string                            `json:\"provider_format_version\"`\n\tProviderSchemas       map[string]*jsonprovider.Provider `json:\"provider_schemas,omitempty\"`\n}\n\nfunc (plan Plan) getSchema(change jsonplan.ResourceChange) *jsonprovider.Schema {\n\tswitch change.Mode {\n\tcase jsonstate.ManagedResourceMode:\n\t\treturn plan.ProviderSchemas[change.ProviderName].ResourceSchemas[change.Type]\n\tcase jsonstate.DataResourceMode:\n\t\treturn plan.ProviderSchemas[change.ProviderName].DataSourceSchemas[change.Type]\n\tdefault:\n\t\tpanic(\"found unrecognized resource mode: \" + change.Mode)\n\t}\n}\n\nfunc (plan Plan) getActionSchema(ai jsonplan.ActionInvocation) *jsonprovider.ActionSchema {\n\treturn plan.ProviderSchemas[ai.ProviderName].ActionSchemas[ai.Type]\n}\n\nfunc (plan Plan) renderHuman(renderer Renderer, mode plans.Mode, opts ...plans.Quality) {\n\tcheckOpts := func(target plans.Quality) bool {\n\t\treturn slices.Contains(opts, target)\n\t}\n\n\tdiffs := precomputeDiffs(plan, mode)\n\thaveRefreshChanges := renderHumanDiffDrift(renderer, diffs, mode)\n\n\twillPrintResourceChanges := false\n\tcounts := make(map[plans.Action]int)\n\timportingCount := 0","sourceCodeStart":32,"sourceCodeEnd":68,"githubUrl":"https://github.com/hashicorp/terraform/blob/c9def3e214014c1188faabfc4a5bde5095139765/internal/command/jsonformat/plan.go#L32-L68","documentation":"A panic in `Plan.getSchema` (internal/command/jsonformat/plan.go:50) triggered when a resource change's `Mode` field matches neither `ManagedResourceMode` nor `DataResourceMode`. The default case of the switch concatenates the unknown mode into the panic message. It is an internal invariant: every resource change in a well-formed plan JSON must be either managed or data. Hitting it means the plan JSON is malformed or produced by an incompatible Terraform version.","triggerScenarios":"Rendering or applying a JSON plan (`terraform show -json`, `terraform apply tfplan`) where a `resource_changes[].mode` entry holds an unrecognized value (not 'managed' or 'data'). Typically from a hand-edited plan file, a plan produced by a newer Terraform that introduced a new resource mode, or third-party tooling that wrote non-standard JSON.","commonSituations":"Version skew: generating a plan with Terraform 1.x and rendering/applying it with an older binary; corrupted plan files; tooling that round-trips plan JSON incorrectly; experimental forks of Terraform.","solutions":["Regenerate the plan with the same Terraform version used to render or apply it, and never downgrade across a plan.","If using `terraform show -json` output programmatically, validate `resource_changes[].mode` is in {managed, data} before processing.","Report as a Terraform bug if reproduced with unmodified stock Terraform and a freshly generated plan.","Avoid hand-editing or rewriting plan JSON files; treat plans as opaque artifacts."],"exampleFix":"// before: consuming plan JSON without validation\nfor _, rc := range planJSON[\"resource_changes\"].([]interface{}) {\n    schema := getSchema(rc) // panics on unknown mode\n}\n\n// after: validate mode before dispatching\nfor _, rc := range planJSON[\"resource_changes\"].([]interface{}) {\n    mode := rc.(map[string]interface{})[\"mode\"].(string)\n    if mode != \"managed\" && mode != \"data\" {\n        return fmt.Errorf(\"unsupported resource mode %q; regenerate plan with current terraform\", mode)\n    }\n    schema := getSchema(rc)\n}","handlingStrategy":"validation","validationCode":"// Go: validate plan JSON modes before passing to jsonformat rendering\nfunc validateResourceModes(planJSON []byte) error {\n\tvar p struct {\n\t\tRC []struct{ Mode string `json:\"mode\"` } `json:\"resource_changes\"`\n\t}\n\tif err := json.Unmarshal(planJSON, &p); err != nil {\n\t\treturn err\n\t}\n\tfor _, rc := range p.RC {\n\t\tif rc.Mode != \"managed\" && rc.Mode != \"data\" {\n\t\t\treturn fmt.Errorf(\"unrecognized resource mode %q; regenerate plan with current terraform\", rc.Mode)\n\t\t}\n\t}\n\treturn nil\n}","typeGuard":null,"tryCatchPattern":"// Go: recover from the jsonformat panic and surface a controlled error\ndefer func() {\n\tif r := recover(); r != nil {\n\t\terr = fmt.Errorf(\"plan rendering failed (likely version skew): %v\", r)\n\t}\n}()\nrenderer.Render(plan)","preventionTips":["Never apply or render a plan with a different Terraform version than produced it.","Treat plan files as opaque; do not hand-edit resource mode fields.","If consuming `terraform show -json` output, validate mode against {managed, data} first.","Pin Terraform versions across CI and local environments."],"tags":["terraform","plan","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"}