Skip to content
Latchkey

terraform output Command Reference

Read the values Terraform exposes for the next step in your pipeline.

terraform output prints the root module output values from state. In CI you pipe these into deploy steps, environment variables, or job summaries.

What it does

terraform output reads output values stored in state and prints them. With -raw it emits a single unquoted value ideal for shell capture; with -json it emits all outputs as structured JSON for parsing with jq.

Common flags and usage

  • [NAME]: print only one named output
  • -raw: print a single value with no quotes or formatting
  • -json: print all outputs as JSON
  • -no-color: disable color

Example

shell
- name: Capture endpoint
  run: |
    ENDPOINT=$(terraform output -raw api_endpoint)
    echo "API_ENDPOINT=${ENDPOINT}" >> "$GITHUB_ENV"

In CI

Use terraform output -raw when assigning to a shell variable so surrounding quotes do not break downstream steps. Outputs live in state, so the job must have run init against the real backend.

Key takeaways

  • output reads values from state; the directory must be initialized against the backend.
  • -raw emits an unquoted single value, ideal for shell capture.
  • -json plus jq lets you parse structured outputs for downstream steps.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →