The Terraform state file is the backbone of Terraform’s operations, containing all the information about your managed resources. But state files can be complex and difficult to read in raw form. The terraform show
command provides a human-readable view of your state or plan files, making it easier to understand your infrastructure and debug issues.
terraform show
. This outputs the latest state of your infrastructure in a readable format.-state
flag, e.g., terraform show -state=example.tfstate
.terraform show example.tfplan
.Suppose you have deployed an EC2 instance and want to inspect its current state. Running terraform show
will display information like this:
# aws_instance.example:
resource "aws_instance" "example" {
ami = "ami-123456"
instance_type = "t2.micro"
id = "i-0abcd1234efgh5678"
tags = {
Name = "example-instance"
}
}
If you’ve saved a plan file to example.tfplan
using terraform plan -out=example.tfplan
, you can view its contents by running:
terraform show example.tfplan
This allows you to review the planned actions without applying them.
Imagine you’re collaborating with a team, and someone wants to confirm the current configuration of a specific resource. By running terraform show
, you can provide a detailed, easy-to-read summary of the resource’s state without exposing the raw state file.
The terraform show
command makes it easier to understand and analyze your Terraform-managed resources. Whether inspecting the current state or reviewing a saved plan, this command is a valuable tool for maintaining visibility and control over your infrastructure.