hashicorp/terraform · error

could not marshal output %s type: %w

Error message

could not marshal output %s type: %w

What it means

tfeOutputToCtyValue first re-marshals output.DetailedType to JSON via json.Marshal. This wraps a failure of that marshal, which is extremely rare since DetailedType is normally a plain JSON-shaped value coming straight from the API.

Source

Thrown at internal/cloud/state.go:667

		// If the header field is either absent or invalid then we'll
		// just choose zero, which effectively means that we'll just use
		// the caller's requested interval instead. If the caller has no
		// requested interval or it is zero, then we will disable snapshots.
		s.stateSnapshotInterval = time.Duration(0)
	}

	// We will only enable snapshots for intervals greater than zero
	log.Printf("[TRACE] Intermediate state interval is set by header to %v", s.stateSnapshotInterval)
	s.enableIntermediateSnapshots = s.stateSnapshotInterval > 0
}

// tfeOutputToCtyValue decodes a combination of TFE output value and detailed-type to create a
// cty value that is suitable for use in terraform.
func tfeOutputToCtyValue(output tfe.StateVersionOutput) (cty.Value, error) {
	var result cty.Value
	bufType, err := json.Marshal(output.DetailedType)
	if err != nil {
		return result, fmt.Errorf("could not marshal output %s type: %w", output.ID, err)
	}

	var ctype cty.Type
	err = ctype.UnmarshalJSON(bufType)
	if err != nil {
		return result, fmt.Errorf("could not interpret output %s type: %w", output.ID, err)
	}

	result, err = gocty.ToCtyValue(output.Value, ctype)
	if err != nil {
		return result, fmt.Errorf("could not interpret value %v as type %s for output %s: %w", result, ctype.FriendlyName(), output.ID, err)
	}

	return result, nil
}

View on GitHub (pinned to c9def3e214)

Solutions

  1. Retry; could be a transient malformed response.
  2. Upgrade go-tfe and Terraform to the latest release.
  3. If reproducible, report it with the output ID and state version.
Defensive patterns

Strategy: try-catch

Try / catch

outs, err := state.GetRootOutputValues(ctx)
if err != nil && strings.Contains(err.Error(), "could not marshal output") {
    // internal/protocol-level; retry once, then upgrade TF/go-tfe and report if persistent
}

Prevention

When it happens

Trigger: output.DetailedType contains a non-JSON-encodable Go value, essentially an internal or protocol-level bug or a malformed API response.

Common situations: Almost never seen in normal use; indicates a go-tfe or TFE protocol regression producing an invalid DetailedType.

Related errors


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