hashicorp/terraform · error

could not interpret value

Error message

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

What it means

Thrown inside tfeOutputToCtyValue as the final conversion step when gocty.ToCtyValue cannot coerce the output's stored Value into the interpreted cty type. This means the type was parsed successfully (537 passed) but the actual value does not fit — for example a string value where a number type is declared, or a null where a non-nullable type is expected. The %w wraps the gocty error and includes the value, type, and output ID for diagnosis.

Solutions

  1. Review the TF_LOG output to see the mismatched value and type for the named output
  2. Correct the output in configuration or re-run apply with a consistent provider version to rewrite the state
  3. If the state is corrupted, use terraform taint/replace on the resource producing the output, or manually fix via state pull/push
  4. Pin the provider to the version that originally wrote the state to read it, then upgrade in a controlled manner
Defensive patterns

Strategy: validation

Validate before calling

// Validate value-type consistency before conversion:
bufType, _ := json.Marshal(output.DetailedType)
var t cty.Type
_ = t.UnmarshalJSON(bufType)
if _, err := gocty.ToCtyValue(output.Value, t); err != nil {
    log.Printf("[WARN] output %s value does not match type %s: %v", output.ID, t.FriendlyName(), err)
}

Try / catch

_, err := state.GetRootOutputValues(ctx)
if err != nil && strings.Contains(err.Error(), "could not interpret value") {
    // value/type mismatch in the stored state; the output needs to be rewritten
    return fmt.Errorf("state output value/type mismatch; re-apply to rewrite state: %w", err)
}

Prevention

When it happens

Trigger: The stored output value and its declared type disagree (data/type mismatch); a null value for a type that does not permit null; a number value stored as a JSON string but typed as number in a way gocty rejects; schema drift between the value the provider produced and the type recorded in state.

Common situations: Provider version change that altered an output's value encoding without updating the recorded type; manual state edits that changed a value but not its type; state written by one provider version read by another with different nullability semantics.

Related errors


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

Appendix: 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 d32a084675)