hashicorp/terraform · error

could not interpret output

Error message

could not interpret output %s type: %w

What it means

Thrown inside tfeOutputToCtyValue after the DetailedType is JSON-marshaled but cty.Type.UnmarshalJSON cannot interpret that JSON as a valid cty type. The cty type encoding has a specific JSON format (type markers like "string", ["object",...], ["list",...], etc.); any deviation causes this error. The %w wraps the cty unmarshal error and includes the output ID.

Solutions

  1. Upgrade terraform to the latest release so its cty library understands newer type encodings
  2. Identify the offending output via TF_LOG and simplify its type in configuration
  3. Re-apply with a current terraform version to rewrite the state with a compatible type encoding
  4. If on self-hosted TFE, align TFE and terraform CLI versions to compatible release lines
Defensive patterns

Strategy: validation

Validate before calling

// Validate that the type JSON is a valid cty type before full conversion:
bufType, _ := json.Marshal(output.DetailedType)
var t cty.Type
if err := t.UnmarshalJSON(bufType); err != nil {
    log.Printf("[WARN] output %s type JSON is not a valid cty type: %v", output.ID, err)
}

Try / catch

_, err := state.GetRootOutputValues(ctx)
if err != nil && strings.Contains(err.Error(), "could not interpret output") {
    // cty cannot parse the type encoding from TFE — version mismatch likely
    return fmt.Errorf("cty type interpretation failed; align terraform and TFE versions: %w", err)
}

Prevention

When it happens

Trigger: The DetailedType JSON uses an unknown or malformed type marker; a nested type exceeds cty's supported depth; the type JSON is a valid JSON value but not a valid cty type specification; terraform's embedded cty version is older than the TFE server's type encoding.

Common situations: TFE server upgraded to emit a new type encoding before the terraform client supports it; a provider output with an exotic type (e.g. abstract type, optional object attributes) not supported by the client's cty version; corrupt state data.

Related errors


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

Appendix: source

Thrown at internal/cloud/state.go:673

	// 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 d32a084675)