0
0
TerraformHow-ToBeginner · 3 min read

How to Use Terraform Show: Syntax, Example, and Tips

Use the terraform show command to display the contents of a Terraform state or plan file in a human-readable format. You can run terraform show [options] [path] to see details about your infrastructure or planned changes.
📐

Syntax

The basic syntax of terraform show is:

  • terraform show [options] [path]

Here, path is optional and can be a Terraform state file or a plan file. If no path is given, it shows the current state in your working directory.

Options include -json to output in JSON format for easier parsing.

bash
terraform show [options] [path]
💻

Example

This example shows how to create a Terraform plan and then use terraform show to display its contents in a readable format.

bash
terraform init
terraform plan -out=tfplan
terraform show tfplan
Output
Refreshing Terraform state in-memory prior to plan... An execution plan has been generated and is shown below. Resource actions are indicated with the following symbols: + create Terraform will perform the following actions: # aws_instance.example will be created + resource "aws_instance" "example" { + ami = "ami-0c55b159cbfafe1f0" + instance_type = "t2.micro" ... } Plan: 1 to add, 0 to change, 0 to destroy.
⚠️

Common Pitfalls

Common mistakes when using terraform show include:

  • Trying to show a plan file that does not exist or was not created with terraform plan -out=filename.
  • Expecting terraform show to modify infrastructure; it only displays information.
  • Not using the -json flag when you need machine-readable output.

Always ensure the file path is correct and the file is a valid Terraform state or plan file.

bash
Incorrect:
terraform show myplan

Correct:
terraform plan -out=myplan
terraform show myplan
📊

Quick Reference

CommandDescription
terraform showShow current state in readable format
terraform show tfplanShow details of a saved plan file
terraform show -json tfplanShow plan in JSON format
terraform show terraform.tfstateShow details of a state file

Key Takeaways

Use terraform show to view state or plan files in a readable way.
Specify the file path to show a specific plan or state file.
Use -json option for machine-readable output.
Ensure the plan file exists before trying to show it.
Remember terraform show only displays info; it does not change infrastructure.