hashicorp/terraform · error

could not decode output %s (ID %s)

Error message

could not decode output %s (ID %s)

What it means

After fetching each output, Terraform converts it to a cty.Value via tfeOutputToCtyValue. This error means that conversion failed for a specific named output. Note the underlying cause is not wrapped into the message, so detail is lost.

Source

Thrown at internal/cloud/state.go:612

				return nil, ErrStateVersionUnauthorizedUpgradeState
			}

			return state.RootOutputValues, nil
		}

		if output.Sensitive {
			// Since this is a sensitive value, the output must be requested explicitly in order to
			// read its value, which is assumed to be present by callers
			sensitiveOutput, err := s.tfeClient.StateVersionOutputs.Read(ctx, output.ID)
			if err != nil {
				return nil, fmt.Errorf("could not read state version output %s: %w", output.ID, err)
			}
			output.Value = sensitiveOutput.Value
		}

		cval, err := tfeOutputToCtyValue(*output)
		if err != nil {
			return nil, fmt.Errorf("could not decode output %s (ID %s)", output.Name, output.ID)
		}

		result[output.Name] = &states.OutputValue{
			Value:     cval,
			Sensitive: output.Sensitive,
		}
	}

	return result, nil
}

func clamp(val, min, max int64) int64 {
	if val < min {
		return min
	} else if val > max {
		return max
	}
	return val

View on GitHub (pinned to c9def3e214)

Solutions

  1. Identify the named output and inspect its stored type and value.
  2. Re-write the state by re-applying with a compatible Terraform version.
  3. Remove or redefine the offending output and re-apply.
  4. Upgrade or downgrade Terraform to the version that wrote the state.

Example fix

# before: output stored with an incompatible/corrupt type -> could not decode output <name>
# after: redefine the output cleanly and re-apply to rewrite state
output "thing" { value = var.thing }   # plain, supported type
terraform apply
Defensive patterns

Strategy: validation

Try / catch

outs, err := state.GetRootOutputValues(ctx)
if err != nil && strings.Contains(err.Error(), "could not decode output") {
    // identify the named output, inspect its type/value, redefine and re-apply
}

Prevention

When it happens

Trigger: An output whose DetailedType/Value cannot be converted to a cty value: corrupted or unsupported type information, or a value/type mismatch in the stored state.

Common situations: State written by a future/incompatible Terraform version, or a corrupted output entry (e.g. from manual state edits).

Related errors


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