# Error: Duplicate resource "aws_instance" configuration: a resource with the address "module.ec2.aws_instance.web" already exists

- **ID:** `terraform/duplicate-resource-name-in-module`
- **Domain:** terraform
- **Category:** config_error
- **Verification:** ai_generated
- **Fix Rate:** 90%

## Root Cause

Two or more resource blocks with the same resource type and name exist within the same module, causing a duplicate definition.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| Terraform v1.5.0 | active | — | — |
| Terraform v1.6.0 | active | — | — |
| Terraform v1.7.0 | active | — | — |

## Workarounds

1. **Remove or rename one of the duplicate resource blocks in the module configuration file. For example, change `resource "aws_instance" "web"` to `resource "aws_instance" "web2"` and update references.** (95% success)
   ```
   Remove or rename one of the duplicate resource blocks in the module configuration file. For example, change `resource "aws_instance" "web"` to `resource "aws_instance" "web2"` and update references.
   ```
2. **Use a single resource block with count or for_each if multiple instances are needed: `resource "aws_instance" "web" { count = 2 ... }`** (90% success)
   ```
   Use a single resource block with count or for_each if multiple instances are needed: `resource "aws_instance" "web" { count = 2 ... }`
   ```

## Dead Ends

- **Add count or for_each to the duplicate resource block** — Count/for_each creates multiple instances but doesn't resolve duplicate block definitions. (85% fail)
- **Rename the module call in the root module** — The duplicate is within the same module, not at the call site. (75% fail)
- **Delete the .terraform directory and re-run init** — The config file itself has duplicates; init doesn't fix config errors. (90% fail)
