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
terraform apply Command ReferenceReference for terraform apply in CI/CD: apply a saved plan non-interactively, use -auto-approve, and cap para…
terraform show Command ReferenceReference for terraform show in CI/CD: render a saved plan or state as human-readable or JSON for policy chec…
terraform state list Command ReferenceReference for terraform state list in CI/CD: enumerate and filter the resource addresses Terraform tracks, th…