0
0
Terraformcloud~5 mins

Terraform show for state inspection - Commands & Configuration

Choose your learning style9 modes available
Introduction
Sometimes you want to see what resources Terraform has created or plans to create without changing anything. Terraform show lets you look inside the saved state file to understand your infrastructure's current setup.
When you want to check the details of resources Terraform manages without applying changes
When you need to verify the current state of your infrastructure after deployment
When you want to debug or audit what Terraform knows about your resources
When you want to export the state information in a readable format
When you want to compare the actual deployed resources with your configuration
Commands
This command initializes the Terraform working directory, downloading necessary provider plugins and preparing the environment.
Terminal
terraform init
Expected OutputExpected
Initializing the backend... Initializing provider plugins... - Finding latest version of hashicorp/aws... - Installing hashicorp/aws v4.60.0... - Installed hashicorp/aws v4.60.0 (signed by HashiCorp) Terraform has been successfully initialized!
This command applies the Terraform configuration to create or update infrastructure without asking for confirmation.
Terminal
terraform apply -auto-approve
Expected OutputExpected
aws_instance.example: Creating... aws_instance.example: Still creating... [10s elapsed] aws_instance.example: Creation complete after 15s [id=i-0abcd1234efgh5678] Apply complete! Resources: 1 added, 0 changed, 0 destroyed.
-auto-approve - Skips interactive approval prompt
This command displays the current state of the infrastructure managed by Terraform in a human-readable format.
Terminal
terraform show
Expected OutputExpected
aws_instance.example: id = i-0abcd1234efgh5678 ami = ami-0c55b159cbfafe1f0 instance_type = t2.micro availability_zone = us-east-1a tags = { Name = "example-instance" }
Key Concept

If you remember nothing else from this pattern, remember: terraform show lets you peek inside your infrastructure's current state without making changes.

Common Mistakes
Running terraform show before terraform init
Terraform needs to initialize providers and backend before it can read the state properly, otherwise it may error or show incomplete info.
Always run terraform init first to prepare the working directory.
Expecting terraform show to modify infrastructure
terraform show only displays state information; it does not create, update, or delete resources.
Use terraform apply to make changes, terraform show only to inspect.
Summary
Run terraform init to prepare your environment.
Use terraform apply -auto-approve to deploy your infrastructure.
Use terraform show to inspect the current state of your deployed resources.