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
TL;DR: 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. Check git blame or the merge that introduced the duplicate. Delete the duplicate, do not rename one side to "fix" it.
The error
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.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.
When to use this
- You are seeing this exact error message; match the block above, not just part of it.
- The failing call matches the scenario in the title: Terraform.
- You want the fastest verified fix before digging through logs.
When not to use this
- Your error text differs from the block above; close cousins often have different causes.
- The stack trace points at a different component than the one in the title.
- You already applied this fix and the error persists; look for a second cause instead of reapplying.
Compatibility
- Not pinned to a specific version; follows current Terraform behavior.
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 2 · 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>