{"record":{"id":"1c1a38aa519405ac","repo":"opentofu/opentofu","slug":"ephemeral-resources-are-not-meant-to-be-stored-in-1c1a38","errorCode":null,"errorMessage":"ephemeral resources are not meant to be stored in the state file but schema for ephemeral %s.%s has been requested","messagePattern":"ephemeral resources are not meant to be stored in the state file but schema for ephemeral (.+?)\\.(.+?) has been requested","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"internal/command/jsonformat/state.go","lineNumber":41,"sourceCode":"\tRootModule         jsonstate.Module            `json:\"root\"`\n\tRootModuleOutputs  map[string]jsonstate.Output `json:\"root_module_outputs\"`\n\n\tProviderFormatVersion string                            `json:\"provider_format_version\"`\n\tProviderSchemas       map[string]*jsonprovider.Provider `json:\"provider_schemas\"`\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\tcase jsonstate.EphemeralResourceMode:\n\t\tpanic(fmt.Errorf(\"ephemeral resources are not meant to be stored in the state file but schema for ephemeral %s.%s has been requested\", resource.Type, resource.Name))\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","sourceCodeStart":23,"sourceCodeEnd":59,"githubUrl":"https://github.com/opentofu/opentofu/blob/3561785c48c1ce615e7c50261bd351f26053efa2/internal/command/jsonformat/state.go#L23-L59","documentation":"jsonformat.State.GetSchema panics when asked for a schema for an ephemeral-mode resource: ephemeral resources must never persist into state files, so their presence indicates a malformed or foreign state file (or an internal bug). This is a panic, not a returned error.","triggerScenarios":"Rendering a state file whose resources array contains an entry with mode \"ephemeral\" - state written by a different OpenTofu version, hand-crafted state JSON, or corruption.","commonSituations":"State files migrated or restored across versions, external tooling that generates state JSON, testing fixtures with wrong mode strings.","solutions":["Reproduce the state with the current OpenTofu binary (fresh apply or refresh) instead of reusing the foreign state file","Do not hand-edit state files; use 'tofu state' commands only","If 'tofu show -json' on a freshly written state panics, report a bug including the state redacted"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"func containsEphemeralResources(m jsonstate.Module) bool {\n    for _, r := range m.Resources {\n        if r.Mode == jsonstate.EphemeralResourceMode {\n            return true\n        }\n    }\n    for _, c := range m.ChildModules {\n        if containsEphemeralResources(c) {\n            return true\n        }\n    }\n    return false\n}","typeGuard":"func isRenderableStateMode(m jsonstate.ResourceMode) bool {\n    return m == jsonstate.ManagedResourceMode || m == jsonstate.DataResourceMode\n}","tryCatchPattern":"defer func() {\n    if r := recover(); r != nil {\n        err = fmt.Errorf(\"state renderer panic (likely foreign state file): %v\", r)\n    }\n}()","preventionTips":["Recreate state with the current binary instead of reusing foreign snapshots","Never hand-edit state JSON; use 'tofu state' subcommands","Version-check state/plan files before feeding third-party tools","Guard renderer calls with recover() when inputs come from outside your control"],"tags":["go","panic","ephemeral","state-file","version-mismatch"],"backgroundTag":null,"analyzedSha":"3561785c48c1ce615e7c50261bd351f26053efa2","analyzedAt":"2026-08-15T23:27:16.226Z","schemaVersion":2},"datasetVersion":"2026-08-16T03:17:38.424Z"}