{"record":{"id":"f27763d869df46d8","repo":"hashicorp/terraform","slug":"resource-s-has-an-unsupported-mode-s-f27763","errorCode":null,"errorMessage":"resource %s has an unsupported mode %s","messagePattern":"resource (.+?) has an unsupported mode (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/command/jsonstate/state.go","lineNumber":406,"sourceCode":"\t\t\t\tType:         resAddr.Type,\n\t\t\t\tName:         resAddr.Name,\n\t\t\t\tProviderName: r.ProviderConfig.Provider.String(),\n\t\t\t}\n\n\t\t\tif k != nil {\n\t\t\t\tindex := k.Value()\n\t\t\t\tif current.Index, err = ctyjson.Marshal(index, index.Type()); err != nil {\n\t\t\t\t\treturn nil, err\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tswitch resAddr.Mode {\n\t\t\tcase addrs.ManagedResourceMode:\n\t\t\t\tcurrent.Mode = ManagedResourceMode\n\t\t\tcase addrs.DataResourceMode:\n\t\t\t\tcurrent.Mode = DataResourceMode\n\t\t\tdefault:\n\t\t\t\treturn ret, fmt.Errorf(\"resource %s has an unsupported mode %s\",\n\t\t\t\t\tresAddr.String(),\n\t\t\t\t\tresAddr.Mode.String(),\n\t\t\t\t)\n\t\t\t}\n\n\t\t\tschema := schemas.ResourceTypeConfig(\n\t\t\t\tr.ProviderConfig.Provider,\n\t\t\t\tresAddr.Mode,\n\t\t\t\tresAddr.Type,\n\t\t\t)\n\n\t\t\t// It is possible that the only instance is deposed\n\t\t\tif ri.Current != nil {\n\t\t\t\tif schema.Version != int64(ri.Current.SchemaVersion) {\n\t\t\t\t\treturn nil, fmt.Errorf(\"schema version %d for %s in state does not match version %d from the provider\", ri.Current.SchemaVersion, resAddr, schema.Version)\n\t\t\t\t}\n\n\t\t\t\tcurrent.SchemaVersion = ri.Current.SchemaVersion","sourceCodeStart":388,"sourceCodeEnd":424,"githubUrl":"https://github.com/hashicorp/terraform/blob/c9def3e214014c1188faabfc4a5bde5095139765/internal/command/jsonstate/state.go#L388-L424","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Validate every resource in state has a known renderable mode before JSON serialization.\nfor _, m := range state.ResourceInstanceModes() {\n    if m != addrs.ManagedResourceMode && m != addrs.DataResourceMode {\n        return fmt.Errorf(\"state contains resource with unsupported mode %q\", m.String())\n    }\n}","typeGuard":null,"tryCatchPattern":"if _, err := jsonstate.MarshalState(state, schemas); err != nil {\n    // Likely state corruption — fall back to text show and prompt to restore backup.\n    return err\n}","preventionTips":["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."],"tags":["terraform","jsonstate","resource-mode","state-corruption","internal-bug"],"analyzedSha":"c9def3e214014c1188faabfc4a5bde5095139765","analyzedAt":"2026-08-07T15:39:49.278Z","schemaVersion":2},"datasetVersion":"2026-08-07T21:17:07.882Z"}