TerraformPilot

DevOps

Fix Terraform Error: State Show No Instance Found

Fix terraform state show no instance found errors. Correct resource address format for count, for_each, modules, and data sources. List resources

LLuca Berton1 min read

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

#
  1. Wrong address format — missing index, quotes, or module prefix
  2. Resource doesn't exist in state — never created, already destroyed, or renamed
  3. Wrong workspace — resource is in a different workspace
  4. 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

#
CommandUse Case
terraform state listList all resources
terraform state show ADDRESSShow resource details
terraform state mv OLD NEWRename/move resource
terraform state rm ADDRESSRemove from state (keep infra)
terraform state pullDownload remote state as JSON
terraform state pushUpload local state to remote

Hands-On Courses

#

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.

#Terraform#Troubleshooting#DevOps#Error Fix#Infrastructure as Code

Share this article