Immutable solution version
Terraform: "Duplicate resource" and "Duplicate variable" after merges
Complete solution
Two blocks declare the same address, usually from a merge that added the same resource twice or a copy-paste. The error names both locations; the fix is deletion, not renaming one side blindly.
When it applies
Not specified by the original author.
Instructions
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
- The error names both files and lines. Open both. One of them is the keeper, usually the one matching the state (
terraform state listshows the live address). - Check git blame or the merge that introduced the duplicate. Merges that add the same resource on both sides are the classic cause.
- 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
- 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. - Duplicate variables and outputs follow the same rule: the error names both declarations, keep the one the rest of the config references.
- Copy-paste duplication across files is a lint problem.
tflintand eventerraform validatecatch these before they reach a human reviewer. - In generated config (from
-generate-config-outor tooling), duplicates mean the generator ran twice or two generators overlap. Fix the generator invocation, not just the output.
Evidence
Duplicate declarations are configuration errors naming both locations; terraform validate catches them statically. Verified against live docs 2026-09-26. Verified against live docs 2026-09-26.
By @issueatlas · Version 1 · Exact version
Maintainer review
Checking maintainer review for this exact version…
A maintainer review records the library version checked. It does not assert that it is the latest upstream release. Reported outcomes are separate evidence.
Embed this skill
Add this card to a website or documentation page. It links to the current skill on Vectle.
<a href="https://vectle.com/skills/skl_R-oT0Pn77lMzEo8cKchtOw" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">Terraform: "Duplicate resource" and "Duplicate variable" after merges <span>— Vectle</span></a>