{"record":{"id":"ddc281b0207dd57a","repo":"hashicorp/terraform","slug":"error-in-marshalplanvariables-s","errorCode":null,"errorMessage":"error in marshalPlanVariables: %s","messagePattern":"error in marshalPlanVariables: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/command/jsonplan/plan.go","lineNumber":266,"sourceCode":"}\n\n// Marshal returns the json encoding of a terraform plan.\nfunc Marshal(\n\tconfig *configs.Config,\n\tp *plans.Plan,\n\tsf *statefile.File,\n\tschemas *terraform.Schemas,\n) ([]byte, error) {\n\toutput := newPlan()\n\toutput.TerraformVersion = version.String()\n\toutput.Timestamp = p.Timestamp.Format(time.RFC3339)\n\toutput.Applyable = p.Applyable\n\toutput.Complete = p.Complete\n\toutput.Errored = p.Errored\n\n\terr := output.marshalPlanVariables(p.VariableValues, config.Module.Variables)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"error in marshalPlanVariables: %s\", err)\n\t}\n\n\t// output.PlannedValues\n\terr = output.marshalPlannedValues(p.Changes, schemas)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"error in marshalPlannedValues: %s\", err)\n\t}\n\n\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 {","sourceCodeStart":248,"sourceCodeEnd":284,"githubUrl":"https://github.com/hashicorp/terraform/blob/c9def3e214014c1188faabfc4a5bde5095139765/internal/command/jsonplan/plan.go#L248-L284","documentation":"Top-level wrapper: output.marshalPlanVariables failed while serializing the plan's variables section. The inner failure is either a DynamicValue decode of a variable value (v.Decode(cty.DynamicPseudoType)) or a ctyjson.Marshal of a variable value or its default.","triggerScenarios":"Reached on every full Marshal call. marshalPlanVariables iterates p.VariableValues, decoding each DynamicValue and re-marshaling to JSON; any decode/type error or non-JSON-serializable value aborts and is wrapped here.","commonSituations":"Plan saved by a Terraform version that encoded variables in a form the current binary cannot decode; a variable whose value is of a cty type ctyjson cannot represent; corrupted plan file.","solutions":["Regenerate the plan with the current Terraform binary so variable encoding matches.","Inspect the wrapped inner error to find which variable failed.","Simplify or check unusual variable types (e.g. deeply nested object types) in the root module."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"out, err := jsonplan.Marshal(config, plan, sf, schemas)\nif err != nil {\n    // 'error in marshalPlanVariables' wraps the variable-specific failure;\n    // log err and inspect the inner message to find the offending variable.\n    return err\n}","preventionTips":["Produce and render plans with the same Terraform version.","Avoid unusual/recursive variable types that may not survive ctyjson round-tripping.","Validate variable values against their declared types before planning."],"tags":["variables","marshal","decode"],"analyzedSha":"c9def3e214014c1188faabfc4a5bde5095139765","analyzedAt":"2026-08-07T15:39:49.278Z","schemaVersion":2},"datasetVersion":"2026-08-07T21:17:07.882Z"}