Skip to main content
In this lesson we focus on two practical Terraform CLI inspection commands: terraform show and terraform output. You have likely encountered these commands during day-to-day Terraform usage. Here we formalize their roles from a state-inspection perspective, show common usage patterns, and explain how they fit into automation and debugging workflows.

terraform show

terraform show reads a Terraform state file (local or remote) or a saved plan file and renders its contents in a human-readable format. Because Terraform stores state as JSON, terraform show is the convenient way to inspect what Terraform knows about resources without parsing raw JSON yourself. Example resource declaration (the declared intent in HCL):
When you run terraform show against the applied state, Terraform renders the resource including computed attributes, provider defaults, and the full resource ID that were not explicitly declared in configuration. For example:
Key points:
  • The HCL configuration expresses your declarative intent: attributes you explicitly set.
  • The state (what terraform show renders) contains computed values, provider defaults, and full resource identifiers—the actual recorded state after terraform apply.
  • terraform show can also render saved plan files (for example, terraform show plan.tfplan) so you can inspect a planned change in the same human-readable format.
  • For programmatic consumption, use terraform show -json to obtain a machine-readable JSON representation of the state or plan.
terraform show reads the state or a saved plan file and formats it for humans. It reports what is recorded in state or plan—it does not actively query the provider for live resource properties.
In production and enterprise environments, terraform show is essential for auditing deployed resource properties, debugging drift against known configuration, and validating that applied infrastructure matches expectations.

terraform output

terraform output retrieves values declared in output blocks from the state. Outputs are state-level metadata used to export important values (for example, IP addresses, resource IDs, or endpoints) so they can be consumed by external systems or downstream automation. Example output block in main.tf:
Run terraform output to display exported values:
Useful flags and variations:
  • terraform output -json — produces machine-readable JSON suitable for CI/CD pipelines and scripts.
  • terraform output <NAME> — prints a single output value by name.
  • Sensitive outputs: mark outputs with sensitive = true in your configuration to avoid displaying secrets in interactive output. Note how you handle sensitive outputs in automation and logs.
Use terraform output (and terraform output -json) in CI/CD pipelines to retrieve values from state (for example, IPs or resource IDs) and pass them to downstream steps like configuration management, DNS updates, or deployment scripts.

Command quick reference

Best practices

  • Keep output blocks minimal and purposeful—export only what downstream consumers require.
  • Avoid exporting secrets; if you must, mark them as sensitive = true and secure access to state.
  • Use terraform show -json or terraform output -json when integrating with automation to avoid brittle parsing of human-readable output.
  • Rely on these commands for auditing and debugging; remember they reflect Terraform’s recorded state (or saved plan), not necessarily the current live provider state.

Summary

  • terraform show provides full visibility into the state or a saved plan in a human-readable format, including computed attributes and provider defaults.
  • terraform output returns a controlled set of exported values defined by output blocks in your configuration—these are the stable interface between Terraform and external systems or modules.
  • Both are read-only inspection tools that are essential for auditing, debugging, and integrating Terraform into automation workflows.
Links and references:

Watch Video