{"record":{"id":"b5d7bbcdc11ffa78","repo":"hashicorp/terraform","slug":"raw-output-format-is-only-supported-for-single-out","errorCode":null,"errorMessage":"Raw output format is only supported for single outputs","messagePattern":"Raw output format is only supported for single outputs","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/command/views/output.go","lineNumber":124,"sourceCode":"// output values directly and without quotes or other formatting. This is\n// intended for use in shell scripting or other environments where the exact\n// type of an output value is not important.\ntype OutputRaw struct {\n\tview *View\n}\n\nvar _ Output = (*OutputRaw)(nil)\n\nfunc (v *OutputRaw) Output(name string, outputs map[string]*states.OutputValue) tfdiags.Diagnostics {\n\tvar diags tfdiags.Diagnostics\n\n\tif len(outputs) == 0 {\n\t\tdiags = diags.Append(noOutputsWarning())\n\t\treturn diags\n\t}\n\n\tif name == \"\" {\n\t\tdiags = diags.Append(fmt.Errorf(\"Raw output format is only supported for single outputs\"))\n\t\treturn diags\n\t}\n\n\toutput, ok := outputs[name]\n\tif !ok {\n\t\tdiags = diags.Append(missingOutputError(name))\n\t\treturn diags\n\t}\n\n\tstrV, err := convert.Convert(output.Value, cty.String)\n\tif err != nil {\n\t\tdiags = diags.Append(tfdiags.Sourceless(\n\t\t\ttfdiags.Error,\n\t\t\t\"Unsupported value for raw output\",\n\t\t\tfmt.Sprintf(\n\t\t\t\t\"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.\",\n\t\t\t\tname, output.Value.Type().FriendlyName(),\n\t\t\t),","sourceCodeStart":106,"sourceCodeEnd":142,"githubUrl":"https://github.com/hashicorp/terraform/blob/d32a084675427f5ac3f7d2868578ef8b2c1dc525/internal/command/views/output.go#L106-L142","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Add the specific output name: `terraform output -raw <name>`.","If you need every output raw, loop over names or use `-json` and parse with jq.","Pre-flight: run `terraform output` (no flags) to list available output names."],"exampleFix":"# before\nterraform output -raw\n\n# after\nterraform output -raw instance_ip","handlingStrategy":"validation","validationCode":"// pre-flight: ensure a name is supplied before choosing -raw\nif rawMode && name == \"\" {\n    names := outputNames(outputs)\n    if len(names) != 1 {\n        return errors.New(\"-raw requires a single output name; available: \" + strings.Join(names, \", \"))\n    }\n    name = names[0]\n}","typeGuard":"func isSingleStringOutput(outputs map[string]*states.OutputValue, name string) bool {\n    if name == \"\" || len(outputs) == 0 { return false }\n    v, ok := outputs[name]\n    if !ok { return false }\n    t := v.Value.Type()\n    return t == cty.String || t == cty.Number || t == cty.Bool\n}","tryCatchPattern":"// top-level wrapper: downgrade to a helpful usage error\ndiags := rawOutput.Output(name, outputs)\nfor _, d := range diags {\n    if strings.Contains(d.Description().Summary, \"single outputs\") {\n        return fmt.Errorf(\"usage: terraform output -raw <name>; got %d outputs\", len(outputs))\n    }\n}","preventionTips":["Always pass an explicit output name when scripting with -raw.","Pin output names in a single-source constants file when used by shell scripts.","List outputs first with `terraform output` when in doubt."],"tags":["output","raw-format","cli-usage","argument-validation"],"backgroundTag":null,"analyzedSha":"d32a084675427f5ac3f7d2868578ef8b2c1dc525","analyzedAt":"2026-08-11T18:43:52.779Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}