TutorialsTerraformCommands › terraform output

Terraform Commands · Command 7 of 8

terraform output

Reads the current state and prints the values published by outputs.tf. It never contacts Azure and never changes anything — it's just a window into what a completed apply already recorded.

Codey the Sr Developer, standing with a pointer, ready to walk through the guide
Touches real Azure resources → no Reads → state only Formats → human, -json, -raw

What this command does in detail

Every output block in outputs.tf (or bootstrap/main.tf's own outputs) gets computed and saved into state during terraform apply. This command simply reads those saved values back out and prints them — nothing more. It's the equivalent of checking a receipt after a purchase, rather than making a new one.

Where to run it from working directory & output formats

terraform -chdir=terraform output
terraform -chdir=terraform output -raw ui_webapp_url
terraform -chdir=terraform output -json github_secrets
  • No arguments — prints every output, formatted for a person to read.
  • -raw <name> — one output's value, with no quotes or extra formatting; only works for a plain string or number, not an object.
  • -json [name] — structured JSON, either everything or one named output; the right choice for objects like outputs.tf's database or github_secrets, and for feeding into another script.

Precondition what must already be true

  • terraform init completed, connected to the same backend the resources were created through.
  • At least one successful terraform apply has already run — before that, state has no output values to show.
  • No Azure login is strictly required just to read state, but you do need the same Storage Blob Data Contributor access to the state container that init needed.

Postcondition what becomes true after it succeeds

  • Nothing changes — this is a pure read.
  • The requested value(s) are printed to standard output, in the requested format.
  • An output marked sensitive is hidden (shown as <sensitive>) when listing all outputs at once, but its real value is shown if you ask for that one output by name directly — a deliberate “you asked for it specifically” exception worth knowing about. None of this project's current outputs are marked sensitive (the database password is intentionally left out of every output).

How this project uses it real examples

Publishing the GitHub Actions job summary.github/workflows/terraform.yml
echo '## Application workflow settings'
echo '```json'
terraform -chdir=terraform output -json github_secrets
echo '```'
echo 'API Web App name:'
terraform -chdir=terraform output -raw api_webapp_name
echo 'UI Web App name:'
terraform -chdir=terraform output -raw ui_webapp_name
echo 'Container registry:'
terraform -chdir=terraform output -raw container_registry_login_server

Right after a successful apply, the workflow uses exactly these two forms — structured JSON for the identifiers someone needs to paste into GitHub secrets, and raw strings for the two web app names and the registry — to write a copy-pasteable summary at the end of the run.

Locally, before running the app-settings scriptterraform/README.md
terraform output -json github_secrets

The same command works locally after connecting to the shared backend, which is how terraform/scripts/show_application_deployment_secrets.ps1 /.sh retrieve the values they print.

Common errors and how to fix them

What you seeLikely causeHow to fix it
“Warning: No outputs found”No apply has succeeded yet in this state, so there's nothing to read.Run terraform apply first.
“Output ... not found”The output name was misspelled, or doesn't exist in outputs.tf.Check the exact output names defined in the file, or run terraform output with no arguments to list them all.
Error using -raw on an output-raw only works for a plain string or number; the requested output (like database or github_secrets) is a structured object.Use -json <name> instead.
Authorization error reading stateMissing Storage Blob Data Contributor access to the state container.Same fix as terraform init's equivalent error — verify your Azure login and the bootstrap role assignments.
Codey giving a thumbs up

The receipt is easy to read — last up, the command that checks your work without touching Azure at all.