Table of Contents
The Error
The "moved" block refers to a resource that is not in the state
What Causes This
You added a moved block to refactor a resource name or move it to a module, but the original resource doesn’t exist in the current state. This happens when the resource was already moved, never existed, or state was modified.
How to Fix It
Solution 1: Remove the Moved Block
# If the migration already happened, just remove the moved block
# moved {
# from = aws_instance.old_name
# to = aws_instance.new_name
# }
# Keep only the new resource
resource "aws_instance" "new_name" {
# ...
}
Solution 2: Check Current State
# See what's actually in state
terraform state list
# Check if the resource exists under either name
terraform state show aws_instance.old_name 2>/dev/null
terraform state show aws_instance.new_name 2>/dev/null
Solution 3: Correct the Moved Block
# Make sure 'from' matches exactly what's in state
moved {
from = aws_instance.web # Must match state exactly
to = module.compute.aws_instance.web
}
# For indexed resources
moved {
from = aws_instance.web[0]
to = aws_instance.web["primary"]
}
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
Learn to avoid these errors with interactive, project-based 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.

