0
0
Terraformcloud~5 mins

Terraform state list command - Commands & Configuration

Choose your learning style9 modes available
Introduction
When you use Terraform to create cloud resources, it keeps track of them in a state file. The 'terraform state list' command shows you all the resources Terraform knows about in that state. This helps you see what Terraform is managing right now.
When you want to see all the cloud resources Terraform is currently managing in your project.
When you need to check if a specific resource was created by Terraform.
When you want to verify the names of resources before running commands that target them.
When troubleshooting to confirm Terraform's view of your infrastructure matches reality.
When preparing to remove or modify resources and you want to list them first.
Commands
This command initializes the Terraform working directory. It downloads necessary provider plugins and prepares Terraform to work with your configuration and state.
Terminal
terraform init
Expected OutputExpected
Initializing the backend... Initializing provider plugins... - Finding latest version of hashicorp/aws... - Installing hashicorp/aws v4.0.0... - Installed hashicorp/aws v4.0.0 (signed by HashiCorp) Terraform has been successfully initialized! You may now begin working with Terraform. Try running "terraform plan" to see any changes that are required for your infrastructure.
This command applies your Terraform configuration to create or update resources. The '-auto-approve' flag skips the manual approval step to speed up the process.
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 - Automatically approve the apply without prompting for confirmation
This command lists all the resources currently tracked in the Terraform state file. It helps you see what Terraform is managing.
Terminal
terraform state list
Expected OutputExpected
aws_instance.example
Key Concept

If you remember nothing else, remember: 'terraform state list' shows all resources Terraform manages in your current state.

Common Mistakes
Running 'terraform state list' before 'terraform init'
Terraform needs to be initialized to download providers and set up the backend before it can read the state.
Always run 'terraform init' first to prepare your working directory.
Expecting 'terraform state list' to show resources not created by Terraform
Terraform only tracks resources it created or imported; other resources won't appear.
Use cloud provider consoles or CLI tools to see resources outside Terraform.
Summary
Run 'terraform init' to prepare your working directory and download providers.
Use 'terraform apply -auto-approve' to create or update resources without manual approval.
'terraform state list' shows all resources Terraform currently manages in your state file.