Quick Answer
# List all resources in state
terraform state list
# Then use the exact address shown
terraform state show 'aws_instance.web[0]'
The Error
No instance found for the given address!
This command requires that the address references one specific instance.
Or:
Error: No matching resource found.
What Causes This
- Wrong address format — missing index, quotes, or module prefix
- Resource doesn’t exist in state — never created, already destroyed, or renamed
- Wrong workspace — resource is in a different workspace
- State file mismatch — local state vs remote state
Solution 1: List Resources First
# List everything
terraform state list
# Filter by resource type
terraform state list | grep aws_instance
# Filter by module
terraform state list | grep "module.vpc"
Output:
aws_instance.web[0]
aws_instance.web[1]
module.vpc.aws_vpc.main
module.vpc.aws_subnet.public[0]
module.vpc.aws_subnet.public[1]
module.vpc.aws_subnet.private[0]
Use the exact address from the list.
Solution 2: Correct Address Formats
Simple Resource
terraform state show aws_instance.web
count Resources
# Must include the index in quotes
terraform state show 'aws_instance.web[0]'
terraform state show 'aws_instance.web[1]'
# Without quotes, the shell interprets brackets
terraform state show aws_instance.web[0] # ❌ Shell glob
terraform state show 'aws_instance.web[0]' # ✅ Quoted
for_each Resources
# String keys in quotes
terraform state show 'aws_instance.web["primary"]'
terraform state show 'aws_instance.web["secondary"]'
# Escape for shell
terraform state show 'aws_instance.web["us-east-1a"]'
Module Resources
terraform state show 'module.vpc.aws_vpc.main'
terraform state show 'module.vpc.aws_subnet.public[0]'
terraform state show 'module.database["prod"].aws_db_instance.main'
Data Sources
terraform state show 'data.aws_ami.ubuntu'
terraform state show 'data.aws_availability_zones.available'
Solution 3: Check Your Workspace
# Show current workspace
terraform workspace show
# List all workspaces
terraform workspace list
# Switch if needed
terraform workspace select production
terraform state list
Solution 4: Resource Was Renamed or Moved
If you renamed a resource in code:
# Old: resource "aws_instance" "web" { ... }
# New: resource "aws_instance" "app" { ... }
The old name still exists in state. Move it:
terraform state mv aws_instance.web aws_instance.app
For moved blocks (Terraform 1.1+):
moved {
from = aws_instance.web
to = aws_instance.app
}
Solution 5: Refresh State
Resource might have been deleted outside Terraform:
# Refresh state to match reality
terraform refresh
# Or plan with refresh
terraform plan -refresh-only
Common State Commands
| Command | Use Case |
|---|---|
terraform state list | List all resources |
terraform state show ADDRESS | Show resource details |
terraform state mv OLD NEW | Rename/move resource |
terraform state rm ADDRESS | Remove from state (keep infra) |
terraform state pull | Download remote state as JSON |
terraform state push | Upload local state to remote |
Hands-On Courses
- Terraform for Beginners on CopyPasteLearn
- Terraform By Example — practical code examples
Conclusion
Always run terraform state list first and use the exact address shown. Quote addresses with brackets ('aws_instance.web[0]') to prevent shell interpretation. Check that you’re in the right workspace and use terraform state mv when resources are renamed.
