Table of Contents
The Error
When working with Terraform, you may encounter this error:
Error: Duplicate resource aws_instance configuration
This error can block your entire workflow. Let’s understand why it happens and how to fix it.
What Causes This Error
Two resource blocks with identical type and name exist in the configuration, possibly across different .tf files.
How to Fix It
Solution 1
Rename one of the duplicate resources to a unique name.
Solution 2
Search across all .tf files: grep -r ‘resource aws_instance example’ .
Solution 3
If they should be one resource, merge the configurations and remove the duplicate.
Solution 4
Use for_each or count if you need multiple instances of the same resource type.
Prevention Tips
- Always run
terraform validatebeforeterraform plan - Use
terraform fmtto keep configuration clean and readable - Pin provider versions to avoid unexpected schema changes
- Review plan output carefully before applying
Learn More
- Terraform for Beginners Course — hands-on labs covering this topic
- Terraform By Example Book — real-world patterns and solutions
- Terraform Cheat Sheet — quick command reference
Related Articles
Conclusion
This error is common but straightforward to fix. The key is understanding the root cause and applying the correct solution for your specific situation. Following the prevention tips above will help you avoid this error in future projects.



