{"record":{"id":"ff5955060026dd8e","repo":"opentofu/opentofu","slug":"ephemeral-resource-q-detected-in-the-plan-this-i","errorCode":null,"errorMessage":"ephemeral resource %q detected in the plan. This is an error in OpenTofu","messagePattern":"ephemeral resource %q detected in the plan\\. This is an error in OpenTofu","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/command/jsonplan/values.go","lineNumber":208,"sourceCode":"\t\tif r.Action == plans.Delete {\n\t\t\tcontinue\n\t\t}\n\n\t\tresource := Resource{\n\t\t\tAddress:      r.Addr.String(),\n\t\t\tType:         r.Addr.Resource.Resource.Type,\n\t\t\tName:         r.Addr.Resource.Resource.Name,\n\t\t\tProviderName: r.ProviderAddr.Provider.String(),\n\t\t\tIndex:        r.Addr.Resource.Key,\n\t\t}\n\n\t\tswitch r.Addr.Resource.Resource.Mode {\n\t\tcase addrs.ManagedResourceMode:\n\t\t\tresource.Mode = \"managed\"\n\t\tcase addrs.DataResourceMode:\n\t\t\tresource.Mode = \"data\"\n\t\tcase addrs.EphemeralResourceMode:\n\t\t\treturn ret, fmt.Errorf(\"ephemeral resource %q detected in the plan. This is an error in OpenTofu\", r.Addr.String())\n\t\tdefault:\n\t\t\treturn nil, fmt.Errorf(\"resource %s has an unsupported mode %s\",\n\t\t\t\tr.Addr.String(),\n\t\t\t\tr.Addr.Resource.Resource.Mode.String(),\n\t\t\t)\n\t\t}\n\n\t\tschema, schemaVer := schemas.ResourceTypeConfig(\n\t\t\tr.ProviderAddr.Provider,\n\t\t\tr.Addr.Resource.Resource.Mode,\n\t\t\tresource.Type,\n\t\t)\n\t\tif schema == nil {\n\t\t\treturn nil, fmt.Errorf(\"no schema found for %s\", r.Addr.String())\n\t\t}\n\t\tresource.SchemaVersion = schemaVer\n\t\tchangeV, err := r.Decode(schema)\n\t\tif err != nil {","sourceCodeStart":190,"sourceCodeEnd":226,"githubUrl":"https://github.com/opentofu/opentofu/blob/3561785c48c1ce615e7c50261bd351f26053efa2/internal/command/jsonplan/values.go#L190-L226","documentation":"While marshaling planned values for `tofu show -json` (jsonplan.marshalPlanResources), a resource change whose address has EphemeralResourceMode is refused. Ephemeral resources (managed via ephemeral blocks) are never persisted nor included in planned-change output, so encountering one in the changes set violates a core invariant — the message itself states 'This is an error in OpenTofu'.","triggerScenarios":"Calling jsonplan.Marshal (directly or via `tofu show -json` / `tofu show -json plan.tfplan`) on a plans.Changes that contains a ResourceInstanceChangeSrc for an ephemeral resource address (addrs.EphemeralResourceMode). Upstream plan walking normally excludes ephemeral resources, so this requires a defect in plan construction or a programmatically assembled changes set.","commonSituations":"Ordinary CLI users do not hit this. It can appear when running a dev/nightly OpenTofu build with a regression in ephemeral-resource handling, or when code that embeds OpenTofu puts ephemeral resources into plans.Changes manually.","solutions":["If you are on a development or unreleased build, switch to the latest stable OpenTofu release.","If you embed the engine, filter ephemeral-mode changes out of plans.Changes before calling jsonplan.Marshal.","If it reproduces on a stable release, report it to the OpenTofu maintainers with the config and plan — the message explicitly asks for it."],"exampleFix":"// before (embedding code): marshaling changes that may include ephemeral resources\nplanJSON, err := jsonplan.Marshal(plan, schemas)\n\n// after: strip ephemeral-mode changes before marshaling\nfiltered := filterEphemeral(plan.Changes)\nplanJSON, err := jsonplan.Marshal(planWithChanges(filtered), schemas)","handlingStrategy":"validation","validationCode":"// drop ephemeral-mode changes before handing plans.Changes to jsonplan (embedding code)\nfunc withoutEphemeral(changes []*plans.ResourceInstanceChangeSrc) []*plans.ResourceInstanceChangeSrc {\n\tout := changes[:0]\n\tfor _, c := range changes {\n\t\tif c.Addr.Resource.Resource.Mode != addrs.EphemeralResourceMode {\n\t\t\tout = append(out, c)\n\t\t}\n\t}\n\treturn out\n}","typeGuard":"func isEphemeralChange(c *plans.ResourceInstanceChangeSrc) bool {\n\treturn c.Addr.Resource.Resource.Mode == addrs.EphemeralResourceMode\n}","tryCatchPattern":null,"preventionTips":["Use stable OpenTofu releases in production pipelines.","Never assemble plans.Changes containing ephemeral resources programmatically."],"tags":["json","plan","ephemeral-resources","internal-invariant"],"backgroundTag":null,"analyzedSha":"3561785c48c1ce615e7c50261bd351f26053efa2","analyzedAt":"2026-08-15T23:27:16.226Z","schemaVersion":2},"datasetVersion":"2026-08-16T03:17:38.424Z"}