hashicorp/terraform · error

error in marshalPlannedValues: %s

Error message

error in marshalPlannedValues: %s

What it means

Top-level wrapper: output.marshalPlannedValues failed while building planned_values (root module resources plus outputs). The inner error bubbles up from marshaling a planned resource change or a planned output.

Source

Thrown at internal/command/jsonplan/plan.go:272

	sf *statefile.File,
	schemas *terraform.Schemas,
) ([]byte, error) {
	output := newPlan()
	output.TerraformVersion = version.String()
	output.Timestamp = p.Timestamp.Format(time.RFC3339)
	output.Applyable = p.Applyable
	output.Complete = p.Complete
	output.Errored = p.Errored

	err := output.marshalPlanVariables(p.VariableValues, config.Module.Variables)
	if err != nil {
		return nil, fmt.Errorf("error in marshalPlanVariables: %s", err)
	}

	// output.PlannedValues
	err = output.marshalPlannedValues(p.Changes, schemas)
	if err != nil {
		return nil, fmt.Errorf("error in marshalPlannedValues: %s", err)
	}

	// output.ResourceDrift
	if len(p.DriftedResources) > 0 {
		// In refresh-only mode, we render all resources marked as drifted,
		// including those which have moved without other changes. In other plan
		// modes, move-only changes will be included in the planned changes, so
		// we skip them here.
		var driftedResources []*plans.ResourceInstanceChangeSrc
		if p.UIMode == plans.RefreshOnlyMode {
			driftedResources = p.DriftedResources
		} else {
			for _, dr := range p.DriftedResources {
				if dr.Action != plans.NoOp {
					driftedResources = append(driftedResources, dr)
				}
			}
		}

View on GitHub (pinned to c9def3e214)

Solutions

  1. Read the wrapped inner error to identify the offending resource or output address.
  2. Ensure provider versions match between plan and render (terraform init).
  3. Regenerate the plan from scratch.
Defensive patterns

Strategy: try-catch

Try / catch

out, err := jsonplan.Marshal(config, plan, sf, schemas)
if err != nil {
    // unwrap to find the planned resource/output that failed
    return fmt.Errorf("render plan: %w", err)
}

Prevention

When it happens

Trigger: Reached on every full Marshal call. Any sub-marshal of a planned resource or output fails (schema missing, decode error, ctyjson error) and is wrapped by this message.

Common situations: Provider schema problems for a planned resource; corrupted plan; version mismatch between the plan producer and renderer; an output value of a non-JSON-representable type.

Related errors


AI-assisted analysis of hashicorp/terraform@c9def3e214 (2026-08-07). Data as JSON: /api/errors/d4f5e7c6b3c5743c. Report an issue: GitHub.