How to fix Error: Error creating ELB: DuplicateLoadBalancerName in Terraform

TerraformINTERMEDIATEHIGHUpdated Dec 30, 2025ยท 126 views

This error occurs when Terraform attempts to create an Elastic Load Balancer that already exists in AWS, usually due to state file mismatches or resource replacement ordering issues. The load balancer may exist in AWS but not be tracked in your Terraform state.

Quick fix

Fixes DuplicateLoadBalancerName

aws elb describe-load-balancers --load-balancer-names my-elb-name
  1. Check if the load balancer exists in AWS
  2. Check Terraform state for the resource
  3. Import the existing load balancer (if missing from state)
  4. Delete the orphaned load balancer if import isn't needed
terraform โ€” error
aws elb describe-load-balancers --load-balancer-names my-elb-name
Error: Error creating ELB: DuplicateLoadBalancerName

What this error means

The DuplicateLoadBalancerName error means AWS already has a load balancer with the name you're trying to create. This typically happens when there's a mismatch between your Terraform state file and the actual AWS resources. The error can occur in several scenarios: the ELB was created but the state file wasn't updated, Terraform is attempting to replace an ELB with the same name without destroying the old one first, or multiple deployments are trying to create the same load balancer.

Typical symptoms

  • Terraform apply fails with 'DuplicateLoadBalancerName' error message
  • The load balancer exists in AWS console but not in terraform state
  • Error occurs when modifying load balancer configuration (subnets, listeners, etc.)
  • Multiple environments or CI/CD runs conflict due to naming collision
  • Terraform attempts to replace the load balancer but fails before completion

Common causes

  1. State file is out of sync - the ELB exists in AWS but Terraform state doesn't know about it
  2. Load balancer replacement ordering - Terraform tries to create new ELB before destroying the old one
  3. Multiple concurrent deployments using the same load balancer name
  4. Previous Terraform run failed after creating the ELB but before saving to state
  5. Manual deletion of load balancer from AWS console while Terraform still expects it

How to fix "Error: Error creating ELB: DuplicateLoadBalancerName"

1Check if the load balancer exists in AWS

First, verify that the load balancer actually exists in AWS. Open the AWS console, navigate to EC2 > Load Balancers, and search for the load balancer name mentioned in the error.

bash
aws elb describe-load-balancers --load-balancer-names my-elb-name

If the load balancer exists in AWS, proceed to the next steps. If it doesn't exist, the issue may be different.

2Check Terraform state for the resource

Verify whether the load balancer is tracked in your Terraform state:

bash
terraform state list | grep aws_elb
terraform state show aws_elb.my_elb_name

If the resource is NOT in the state but EXISTS in AWS, the load balancer is orphaned and you need to import it.

3Import the existing load balancer (if missing from state)

If the load balancer exists in AWS but not in Terraform state, import it using the load balancer name:

bash
terraform import aws_elb.my_elb_name my-elb-name

Or in Terraform v1.5.0+, use an import block in your configuration:

hcl
import {
  to = aws_elb.my_elb_name
  id = "my-elb-name"
}

Then run terraform apply to finalize the import.

4Delete the orphaned load balancer if import isn't needed

If you don't want to keep the existing load balancer, delete it from AWS and re-run Terraform:

bash
aws elb delete-load-balancer --load-balancer-name my-elb-name
terraform apply

Be cautious with this approach if the load balancer is serving production traffic.

5Fix replacement ordering (for ALB/NLB)

If you're modifying the load balancer configuration and getting replacement errors, ensure Terraform destroys the old resource before creating the new one. Add a lifecycle block to your load balancer resource:

hcl
resource "aws_elb" "example" {
  name = "my-elb"
  # ... other configuration ...

  lifecycle {
    create_before_destroy = false
  }
}

This ensures the old load balancer is destroyed first before the new one is created, preventing name collisions.

6Ensure unique load balancer names

If running multiple environments or CI/CD pipelines, use unique names for each load balancer to prevent conflicts:

hcl
resource "aws_elb" "example" {
  name = "my-elb-${var.environment}"
  # Or use a timestamp/random suffix
  # name = "my-elb-${random_string.lb_suffix.result}"
}

This prevents naming collisions when multiple deployments run simultaneously.

Advanced notes

State file corruption or synchronization issues can cause this error. If the above steps don't resolve the issue, try refreshing the Terraform state: terraform refresh or terraform apply -refresh=true. This will sync your state file with the current AWS resources. In rare cases, you may need to manually edit the state file or use terraform state rm to remove conflicting resources, but this should only be done as a last resort. For Classic Load Balancers (ELB), AWS also enforces uniqueness at the region level, so the same name cannot exist twice in one region. For Application/Network Load Balancers (ALB/NLB), DNS names are automatically generated, but the load balancer name must still be unique.

Frequently asked questions

What does "DuplicateLoadBalancerName" mean?
The DuplicateLoadBalancerName error means AWS already has a load balancer with the name you're trying to create. This typically happens when there's a mismatch between your Terraform state file and the actual AWS resources. The error can occur in several scenarios: the ELB was created but the state file wasn't updated, Terraform is attempting to replace an ELB with the same name without destroying the old one first, or multiple deployments are trying to create the same load balancer.
How do I fix "DuplicateLoadBalancerName"?
This error occurs when Terraform attempts to create an Elastic Load Balancer that already exists in AWS, usually due to state file mismatches or resource replacement ordering issues. The load balancer may exist in AWS but not be tracked in your Terraform state.
What causes "DuplicateLoadBalancerName"?
State file is out of sync - the ELB exists in AWS but Terraform state doesn't know about it Load balancer replacement ordering - Terraform tries to create new ELB before destroying the old one Multiple concurrent deployments using the same load balancer name
Is the "DuplicateLoadBalancerName" error serious?
Yes. This is a high-severity error that usually blocks work until it is fixed, but the steps above resolve it.

Official resources & further reading