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):
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:
- The HCL configuration expresses your declarative intent: attributes you explicitly set.
- The state (what
terraform showrenders) contains computed values, provider defaults, and full resource identifiers—the actual recorded state afterterraform apply. terraform showcan 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 -jsonto 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.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:
terraform output to display exported values:
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 = truein 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
outputblocks minimal and purposeful—export only what downstream consumers require. - Avoid exporting secrets; if you must, mark them as
sensitive = trueand secure access to state. - Use
terraform show -jsonorterraform output -jsonwhen 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 showprovides full visibility into the state or a saved plan in a human-readable format, including computed attributes and provider defaults.terraform outputreturns a controlled set of exported values defined byoutputblocks 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.