{"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":"validation","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/d32a084675427f5ac3f7d2868578ef8b2c1dc525/internal/command/jsonstate/state.go#L388-L424","documentation":"Thrown by jsonstate.Marshal while serializing the current state to JSON. The switch over resAddr.Mode only maps Managed and Data resources; an ephemeral, list, invalid, or future-mode resource in the state object hits the default branch. Persistent state is only defined for managed/data resources, so an unsupported mode here indicates either an internal bug or a state object that should never have been persisted.","triggerScenarios":"A resource with Ephemeral/List/Invalid mode is present in the in-memory states.State passed to jsonstate.Marshal; a future ResourceMode is added without updating this switch; state built by a divergent Terraform build.","commonSituations":"Internal/dev build persisting an unsupported mode; state object constructed programmatically (e.g. in tests/tools) with Mode==0; cross-version state consumption.","solutions":["Upgrade Terraform so the state serializer handles the mode (or skips it).","Regenerate the state with the same Terraform binary that will read it.","If extending Terraform, add the case or a skip in internal/command/jsonstate/state.go around line 406.","Report upstream with the address and mode string from the message."],"exampleFix":"// before\nswitch resAddr.Mode {\ncase addrs.ManagedResourceMode:\n\tcurrent.Mode = ManagedResourceMode\ncase addrs.DataResourceMode:\n\tcurrent.Mode = DataResourceMode\ndefault:\n\treturn ret, fmt.Errorf(\"resource %s has an unsupported mode %s\", resAddr.String(), resAddr.Mode.String())\n}\n\n// after\ncase addrs.EphemeralResourceMode, addrs.ListResourceMode:\n\tcontinue // not persisted in JSON state","handlingStrategy":"validation","validationCode":"// Before jsonstate.Marshal, drop resources whose mode has no JSON state representation.\nfunc isPersistableMode(m addrs.ResourceMode) bool {\n    return m == addrs.ManagedResourceMode || m == addrs.DataResourceMode\n}\n\nfor _, m := range state.Modules {\n    for addr, res := range m.Resources {\n        if !isPersistableMode(res.Addr.Resource.Resource.Mode) {\n            return fmt.Errorf(\"state contains non-persistable mode %s on %s\", res.Addr.Resource.Resource.Mode, addr)\n        }\n    }\n}","typeGuard":"func isJSONStateSerializableResource(a addrs.Resource) bool {\n    switch a.Mode {\n    case addrs.ManagedResourceMode, addrs.DataResourceMode:\n        return true\n    }\n    return false\n}","tryCatchPattern":null,"preventionTips":["Never persist ephemeral/list resources in a states.State passed to jsonstate.Marshal.","Keep the state serializer's mode switch in sync with internal/addrs.","When building state programmatically (tests/tools), set Mode explicitly to Managed or Data."],"tags":["terraform","json-state","resource-mode","serialization","enum-exhaustiveness"],"backgroundTag":null,"analyzedSha":"d32a084675427f5ac3f7d2868578ef8b2c1dc525","analyzedAt":"2026-08-11T18:43:52.779Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}