hashicorp/terraform · error

could not interpret value %v as type %s for output %s: %w

Error message

could not interpret value %v as type %s for output %s: %w

What it means

The final step of tfeOutputToCtyValue coerces output.Value into the declared cty.Type via gocty.ToCtyValue. This fails when the stored value does not fit the declared type.

Source

Thrown at internal/cloud/state.go:678

// 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. Inspect the named output's value versus its declared type.
  2. Re-apply to rewrite the output consistently.
  3. Correct the output declaration to match the actual value.
  4. Recreate the offending output value if it is stale.

Example fix

# before: declared number but stored string -> could not interpret value as type
output "count" { value = var.count }   # var.count was changed type
# after: align declaration with the real value and re-apply
output "count" { value = tostring(var.count) }
terraform apply
Defensive patterns

Strategy: validation

Try / catch

outs, err := state.GetRootOutputValues(ctx)
if err != nil && strings.Contains(err.Error(), "could not interpret value") {
    // value/type mismatch; align the output declaration and re-apply
}

Prevention

When it happens

Trigger: A stored output value inconsistent with its declared type: e.g. a string where a number is declared, or an object missing required attributes.

Common situations: Corrupted state, manual state edits, or an output/provider type change between Terraform versions that left value and type out of sync.

Related errors


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