hashicorp/terraform · error

error marshaling relevant attributes for external changes: %

Error message

error marshaling relevant attributes for external changes: %s

What it means

Top-level wrapper: output.marshalRelevantAttrs failed. That function encodes each RelevantAttributes entry's cty.Path via encodePath; a failure means a path step could not be JSON-encoded (typically surfacing errors 618 or 619).

Source

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

		// 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)
				}
			}
		}
		output.ResourceDrift, err = MarshalResourceChanges(driftedResources, schemas)
		if err != nil {
			return nil, fmt.Errorf("error in marshaling resource drift: %s", err)
		}
	}

	if err := output.marshalRelevantAttrs(p); err != nil {
		return nil, fmt.Errorf("error marshaling relevant attributes for external changes: %s", err)
	}

	// output.ResourceChanges
	if p.Changes != nil {
		output.ResourceChanges, err = MarshalResourceChanges(p.Changes.Resources, schemas)
		if err != nil {
			return nil, fmt.Errorf("error in marshaling resource changes: %s", err)
		}
	}

	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 {

View on GitHub (pinned to c9def3e214)

Solutions

  1. Inspect the inner error (often 618/619) to see which step/key failed.
  2. Report as a renderer bug if it occurs on a common attribute type.
  3. As a workaround, isolate the configuration/reference that produces the problematic attribute path and avoid it.
Defensive patterns

Strategy: try-catch

Try / catch

out, err := jsonplan.Marshal(config, plan, sf, schemas)
if err != nil {
    // inner error is usually a path-step marshal failure (618/619);
    // capture it for diagnostics rather than ignoring.
    return err
}

Prevention

When it happens

Trigger: plan.RelevantAttributes contains an entry whose path has an unsupported step type or an index key/attribute name that cannot marshal. Reached on every full Marshal call when relevant attributes exist.

Common situations: Rare. Usually tied to a path-encoding bug or an exotic value type used as an index key in a cross-resource reference; can follow internal changes to how relevant attributes are recorded.

Related errors


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