hashicorp/terraform · error

Raw output format is only supported for single outputs

Error message

Raw output format is only supported for single outputs

What it means

Returned by the OutputRaw view (the `-raw` renderer for `terraform output`) when the caller passes an empty output name while the state contains one or more outputs. Raw mode prints a single bare value with no key, so it is only valid when the user names exactly one output; calling it with name="" is a usage error, not a state problem.

Solutions

  1. Add the specific output name: `terraform output -raw <name>`.
  2. If you need every output raw, loop over names or use `-json` and parse with jq.
  3. Pre-flight: run `terraform output` (no flags) to list available output names.

Example fix

# before
terraform output -raw

# after
terraform output -raw instance_ip
Defensive patterns

Strategy: validation

Validate before calling

// pre-flight: ensure a name is supplied before choosing -raw
if rawMode && name == "" {
    names := outputNames(outputs)
    if len(names) != 1 {
        return errors.New("-raw requires a single output name; available: " + strings.Join(names, ", "))
    }
    name = names[0]
}

Type guard

func isSingleStringOutput(outputs map[string]*states.OutputValue, name string) bool {
    if name == "" || len(outputs) == 0 { return false }
    v, ok := outputs[name]
    if !ok { return false }
    t := v.Value.Type()
    return t == cty.String || t == cty.Number || t == cty.Bool
}

Try / catch

// top-level wrapper: downgrade to a helpful usage error
diags := rawOutput.Output(name, outputs)
for _, d := range diags {
    if strings.Contains(d.Description().Summary, "single outputs") {
        return fmt.Errorf("usage: terraform output -raw <name>; got %d outputs", len(outputs))
    }
}

Prevention

When it happens

Trigger: Running `terraform output -raw` (no NAME argument) against a root module that defines at least one output value. The human/JSON renderers accept this and print all outputs; the raw renderer refuses.

Common situations: Forgetting the output name when scripting with `-raw`, copy-pasting a `-raw` invocation from a single-output module into a multi-output module, or wrapping `terraform output -raw` in a script that conditionally omits the name.

Related errors


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

Appendix: source

Thrown at internal/command/views/output.go:124

// output values directly and without quotes or other formatting. This is
// intended for use in shell scripting or other environments where the exact
// type of an output value is not important.
type OutputRaw struct {
	view *View
}

var _ Output = (*OutputRaw)(nil)

func (v *OutputRaw) Output(name string, outputs map[string]*states.OutputValue) tfdiags.Diagnostics {
	var diags tfdiags.Diagnostics

	if len(outputs) == 0 {
		diags = diags.Append(noOutputsWarning())
		return diags
	}

	if name == "" {
		diags = diags.Append(fmt.Errorf("Raw output format is only supported for single outputs"))
		return diags
	}

	output, ok := outputs[name]
	if !ok {
		diags = diags.Append(missingOutputError(name))
		return diags
	}

	strV, err := convert.Convert(output.Value, cty.String)
	if err != nil {
		diags = diags.Append(tfdiags.Sourceless(
			tfdiags.Error,
			"Unsupported value for raw output",
			fmt.Sprintf(
				"The -raw option only supports strings, numbers, and boolean values, but output value %q is %s.\n\nUse the -json option for machine-readable representations of output values that have complex types.",
				name, output.Value.Type().FriendlyName(),
			),

View on GitHub (pinned to d32a084675)