hashicorp/terraform · error

error in marshaling output changes: %s

Error message

error in marshaling output changes: %s

What it means

Top-level wrapper: MarshalOutputChanges(p.Changes) failed while building output_changes. The inner error comes from decoding an output change (oc.Decode()) or ctyjson.Marshal of its before/after/afterUnknown/sensitive values.

Source

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

	}

	if p.DeferredResources != nil {
		output.DeferredChanges, err = MarshalDeferredResourceChanges(p.DeferredResources, schemas)
		if err != nil {
			return nil, fmt.Errorf("error in marshaling deferred resource changes: %s", err)
		}
	}

	if p.DeferredActionInvocations != nil {
		output.DeferredActionInvocations, err = MarshalDeferredActionInvocations(p.DeferredActionInvocations, schemas)
		if err != nil {
			return nil, fmt.Errorf("error in marshaling deferred action invocations: %s", err)
		}
	}

	// output.OutputChanges
	if output.OutputChanges, err = MarshalOutputChanges(p.Changes); err != nil {
		return nil, fmt.Errorf("error in marshaling output changes: %s", err)
	}

	// output.Checks
	if p.Checks != nil && p.Checks.ConfigResults.Len() > 0 {
		output.Checks = jsonchecks.MarshalCheckStates(p.Checks)
	}

	// output.PriorState
	if sf != nil && !sf.State.Empty() {
		output.PriorState, err = jsonstate.Marshal(sf, schemas)
		if err != nil {
			return nil, fmt.Errorf("error marshaling prior state: %s", err)
		}
	}

	// output.Config
	output.Config, err = jsonconfig.Marshal(config, schemas)
	if err != nil {

View on GitHub (pinned to c9def3e214)

Solutions

  1. Inspect the inner error to identify which output failed.
  2. Simplify or temporarily isolate the problematic output to determine its type.
  3. Regenerate the plan with the current Terraform version.
Defensive patterns

Strategy: try-catch

Try / catch

outputs, err := jsonplan.MarshalOutputChanges(plan.Changes)
if err != nil {
    return fmt.Errorf("marshal output changes: %w", err)
}

Prevention

When it happens

Trigger: A root-module output change cannot be decoded or JSON-marshaled. Non-root outputs are skipped, so only root outputs are in play.

Common situations: An output value of a cty type ctyjson cannot represent; plan from a different Terraform version; corrupted plan file.

Related errors


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