0
0
Terraformcloud~30 mins

Terraform show for state inspection - Mini Project: Build & Apply

Choose your learning style9 modes available
Terraform show for state inspection
📖 Scenario: You are managing cloud infrastructure using Terraform. You want to inspect the current state of your deployed resources to understand what Terraform has created and is managing.
🎯 Goal: Learn how to use terraform show to inspect the Terraform state file and understand the current infrastructure state.
📋 What You'll Learn
Create a Terraform state file with a simple resource
Configure Terraform to manage an AWS S3 bucket
Use terraform show to inspect the state
Output the state information in JSON format
💡 Why This Matters
🌍 Real World
Terraform state inspection is essential for understanding what resources are managed and their current configuration, helping avoid drift and troubleshoot issues.
💼 Career
Cloud engineers and DevOps professionals use Terraform state inspection daily to verify infrastructure and ensure deployments are as expected.
Progress0 / 4 steps
1
Create a Terraform configuration with an AWS S3 bucket
Create a file named main.tf with a resource block for an AWS S3 bucket named my-example-bucket in the us-east-1 region. Use the AWS provider with version constraint "~> 4.0".
Terraform
Need a hint?

Start by defining the AWS provider and then add a resource block for the S3 bucket with the exact name my-example-bucket.

2
Initialize Terraform and create the state file
Add a line to initialize Terraform by running terraform init in your terminal. Then add a line to create the infrastructure with terraform apply -auto-approve. (Note: For this exercise, just add these commands as comments in a file named commands.sh.)
Terraform
Need a hint?

Write the commands as comments so you remember the steps to initialize and apply Terraform.

3
Use terraform show to inspect the state
Add a comment line with the command terraform show -json terraform.tfstate > state.json to export the current Terraform state to a JSON file named state.json.
Terraform
Need a hint?

This command exports the Terraform state in JSON format so you can inspect it easily.

4
Add output to display the S3 bucket name from the state
Add an output block in main.tf named bucket_name that outputs the bucket name from the resource aws_s3_bucket.my_example_bucket.bucket.
Terraform
Need a hint?

Outputs help you see important values from your Terraform state after applying.