Duplicate resource configuration / variable declaration Terraform Origin: Platform & cloud OSI layer 7 · Application Last updated 5 Nov 2026

Terraform: Error: Duplicate resource "aws_s3_bucket" configuration — A aws_s3_bucket resource named "logs" was already declared at main.tf:1

The same resource, variable, output or provider is declared twice in the module.

Exact message you may see Error: Duplicate resource "aws_s3_bucket" configurationA aws_s3_bucket resource named "logs" was already declared at main.tf:1Error: Duplicate variable declarationA variable named "region" was already declared at variables.tf:1,1-18Error: Duplicate provider configuration
Seen on: Terraform

Meaning

Terraform loads every .tf file in the directory as one module. A copied file (main copy.tf, .tf.bak named .tf), duplicated blocks, or moving code between files without removing the original causes this. Rename/remove duplicates; keep backups outside the folder or with non-.tf extension.

Common causes

  • Backup/copy files ending in .tf
  • Same block in two files
  • Variable declared in variables.tf and main.tf
  • Duplicate provider without alias
  • Merge conflicts leaving both sides

⚡ Quick fix

  1. grep -R 'resource "aws_s3_bucket" "logs"' *.tf and remove the duplicate
  2. Move backups out of the directory
  3. Give providers aliases when using several configs

Detailed fix by platform

Linux

  1. ls *.tf && grep -n 'variable "region"' *.tf

How to diagnose

  1. Files — Which declare it?
  2. Backups — .tf copies?
  3. Alias — Needed?

🔧 Still not fixed?

Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:

Where this error sits

Origin: Platform & cloud. Errors that are often confused with or caused by this one (click to open):

Invalid AWS Region — Terraform: Error: Invalid AWS Region: us-east-3 / Error: configuring Terraform AWS Provider: validating provider credentials: operation error STS: GetCallerIdentity (Terraform)Invalid AWS RegionInvalid character / Argument or block definition required — Terraform: Error: Invalid character — This character is not used within the language / Error: Argument or block definition required (Terraform)Invalid character / A…Missing required argument — Terraform: Error: Missing required argument — The argument "ami" is required, but no definition was found (Terraform)Missing required argu…No valid credential sources found (AWS provider) — Terraform: Error: No valid credential sources found — failed to refresh cached credentials, no EC2 IMDS role found / Error: configuring Terraform AWS Provider: no valid credential sources (Terraform)No valid credential s…Reference to undeclared resource — Terraform: Error: Reference to undeclared resource / Reference to undeclared input variable (Terraform)Reference to undeclar…Unsupported argument: An argument named "x" is not expected here — Terraform: Error: Unsupported argument — An argument named "enable_foo" is not expected here (Terraform)Unsupported argument:…Unsupported block type: Blocks of type "x" are not expected here — Terraform: Error: Unsupported block type — Blocks of type "versioning" are not expected here (Terraform)Unsupported block typ…Duplicate…

Explore the map of this error Full error map →

🧠 Still stuck? Analyze your error

Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.

💬 What worked for others

No tips yet — did something else fix this for you?

Share what worked for you

Tips are checked by an editor before they appear. Links are removed.