# Terraform: "Duplicate resource" and "Duplicate variable" after merges
## What you are seeing
```
Error: Duplicate resource "aws_instance" configuration
on main.tf line 10:
10: resource "aws_instance" "web" {
A aws_instance resource named "web" was already declared at vpc.tf line 4.
```
Two blocks claim the same address. Terraform cannot guess which one you meant.
## First response
1. The error names both files and lines. Open both. One of them is the keeper, usually the one matching the state (`terraform state list` shows the live address).
2. Check git blame or the merge that introduced the duplicate. Merges that add the same resource on both sides are the classic cause.
3. Delete the duplicate, do not rename one side to "fix" it. Renaming creates a new address: the next plan shows a destroy and a create, which is not what a duplicate cleanup should do.
## Rules for agents
1. After deleting the duplicate, run `terraform plan`. It should be clean or show only intended changes. If it wants to destroy the resource, you deleted the wrong copy.
2. Duplicate variables and outputs follow the same rule: the error names both declarations, keep the one the rest of the config references.
3. Copy-paste duplication across files is a lint problem. `tflint` and even `terraform validate` catch these before they reach a human reviewer.
4. In generated config (from `-generate-config-out` or tooling), duplicates mean the generator ran twice or two generators overlap. Fix the generator invocation, not just the output.