{"record":{"id":"a9a138978c3d8030","repo":"opentofu/opentofu","slug":"error-in-marshaling-resource-drift-w","errorCode":null,"errorMessage":"error in marshaling resource drift: %w","messagePattern":"error in marshaling resource drift: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/command/jsonplan/plan.go","lineNumber":271,"sourceCode":"\t// output.ResourceDrift\n\tif len(p.DriftedResources) > 0 {\n\t\t// In refresh-only mode, we render all resources marked as drifted,\n\t\t// including those which have moved without other changes. In other plan\n\t\t// modes, move-only changes will be included in the planned changes, so\n\t\t// we skip them here.\n\t\tvar driftedResources []*plans.ResourceInstanceChangeSrc\n\t\tif p.UIMode == plans.RefreshOnlyMode {\n\t\t\tdriftedResources = p.DriftedResources\n\t\t} else {\n\t\t\tfor _, dr := range p.DriftedResources {\n\t\t\t\tif dr.Action != plans.NoOp {\n\t\t\t\t\tdriftedResources = append(driftedResources, dr)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\toutput.ResourceDrift, err = MarshalResourceChanges(driftedResources, schemas)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"error in marshaling resource drift: %w\", err)\n\t\t}\n\t}\n\n\tif err := output.marshalRelevantAttrs(p); err != nil {\n\t\treturn nil, fmt.Errorf(\"error marshaling relevant attributes for external changes: %w\", err)\n\t}\n\n\t// output.ResourceChanges\n\tif p.Changes != nil {\n\t\toutput.ResourceChanges, err = MarshalResourceChanges(p.Changes.Resources, schemas)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"error in marshaling resource changes: %w\", err)\n\t\t}\n\t}\n\n\t// output.OutputChanges\n\tif output.OutputChanges, err = MarshalOutputChanges(p.Changes); err != nil {\n\t\treturn nil, fmt.Errorf(\"error in marshaling output changes: %w\", err)","sourceCodeStart":253,"sourceCodeEnd":289,"githubUrl":"https://github.com/opentofu/opentofu/blob/3561785c48c1ce615e7c50261bd351f26053efa2/internal/command/jsonplan/plan.go#L253-L289","documentation":"Wrapper for the drift stage: MarshalResourceChanges failed while encoding p.DriftedResources (drifted resources, NoOp-filtered except in refresh-only mode). The wrapped error is the real cause - typically 'no schema found for ...' for a drifted resource or a decode failure.","triggerScenarios":"Marshaling a plan whose drifted resources reference a resource type missing from the supplied provider schemas, or whose before/after values fail decoding/JSON encoding.","commonSituations":"'tofu plan -refresh-only' followed by JSON export where the provider schema is unavailable or versions drifted; refresh-only plans keep even NoOp drift entries, widening exposure.","solutions":["Run 'tofu init' so provider schemas match the plan's providers","Regenerate the plan in the same environment before exporting JSON","Unwrap the error: if it is the schema error, fix provider availability; if encoding, check versions","Report an issue with the unwrapped cause if both steps check out"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"if _, err := jsonplan.Marshal(config, plan, sf, schemas); err != nil {\n    if strings.Contains(err.Error(), \"marshaling resource drift\") {\n        // root cause is usually a missing provider schema for a drifted resource: tofu init + replan\n    }\n    return err\n}","preventionTips":["For refresh-only plans, ensure schemas for every drifted resource are available","Run 'tofu init' before exporting JSON in the reading environment","Keep drift-review pipelines on a pinned OpenTofu/provider set"],"tags":["go","json","plan","drift","error-wrapping"],"backgroundTag":null,"analyzedSha":"3561785c48c1ce615e7c50261bd351f26053efa2","analyzedAt":"2026-08-15T23:27:16.226Z","schemaVersion":2},"datasetVersion":"2026-08-16T03:17:38.424Z"}