terraform output: Usage, Options & Common CI Errors
Read the values Terraform exposes - for the next step in your pipeline.
terraform output prints the values of root module output variables. In CI you pipe these into deploy steps, environment variables, or job summaries.
What it does
terraform output reads the output values stored in state and prints them. With -raw it emits a single value with no quotes or formatting (ideal for shell capture); with -json it emits all outputs as structured JSON for parsing with jq.
Common usage
# Show all outputs
terraform output
# Capture one value for a later CI step (no quotes)
ENDPOINT=$(terraform output -raw api_endpoint)
# Emit JSON and parse with jq
terraform output -json | jq -r '.api_endpoint.value'Common error in CI: output not found / empty
output fails with "Error: Output ... not found" or prints nothing when the output is not declared, or when state is empty because the job ran in a fresh directory without init. Fix: confirm the output exists with a bare terraform output, ensure you ran terraform init against the real backend (outputs live in state), and apply before reading. Use terraform output -raw (not plain output) when assigning to a shell variable to avoid surrounding quotes breaking downstream steps.
Key options
| Option | Purpose |
|---|---|
| [NAME] | Print only one named output |
| -raw | Print a single value with no formatting |
| -json | Print all outputs as JSON |
| -no-color | Disable color |