Table of Contents
The Error
Error: Instance not found / Resource no longer exists
What Causes This
A resource exists in state but was deleted outside of Terraform (console, another tool, auto-scaling).
How to Fix It
Solution 1: Let Terraform Recreate
terraform plan # Detects drift
terraform apply # Recreates the resource
Solution 2: Remove from State
terraform state rm aws_instance.web
Solution 3: Prevent External Deletion
lifecycle { prevent_destroy = true }
# Or use API termination protection
resource "aws_instance" "critical" {
disable_api_termination = true
}
Prevention Tips
- Pin provider versions — avoid surprise breaking changes
- Use CI/CD — catch errors before they hit production
- Test with
terraform plan— always review before applying - Keep Terraform updated — newer versions have better error messages
- Use
terraform validate— catches syntax errors early
Hands-On Courses
- Terraform for Beginners on CopyPasteLearn
- Terraform By Example — practical code examples
- Terraform Cheat Sheet — quick reference for all commands
Related Articles
- Terraform Troubleshooting - Common Errors and Solutions
- Terraform Enabling and Using Debugging
- Debugging with TFLint
Conclusion
This error is common and fixable. Follow the solutions above, and check our Terraform course for hands-on training that covers real-world troubleshooting scenarios.

