Skip to content

Commit

Permalink
Merge pull request #32941 from hashicorp/b-elbv2-dupe-name
Browse files Browse the repository at this point in the history
elbv2/lb: Check for duplicate name
  • Loading branch information
YakDriver committed Aug 10, 2023
2 parents 4955f25 + dc9ae76 commit 5e0fbe7
Show file tree
Hide file tree
Showing 3 changed files with 369 additions and 174 deletions.
3 changes: 3 additions & 0 deletions .changelog/32941.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
resource/aws_lb: Fix to avoid creating a load balancer with same name as an existing load balancer
```
13 changes: 13 additions & 0 deletions internal/service/elbv2/load_balancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,19 @@ func resourceLoadBalancerCreate(ctx context.Context, d *schema.ResourceData, met
} else {
name = id.PrefixedUniqueId("tf-lb-")
}

exist, err := FindLoadBalancer(ctx, conn, &elbv2.DescribeLoadBalancersInput{
Names: aws.StringSlice([]string{name}),
})

if err != nil && !tfresource.NotFound(err) {
return sdkdiag.AppendErrorf(diags, "reading ELBv2 Load Balancer (%s): %s", name, err)
}

if exist != nil {
return sdkdiag.AppendErrorf(diags, "ELBv2 Target Group (%s) already exists", name)
}

d.Set("name", name)

lbType := d.Get("load_balancer_type").(string)
Expand Down
Loading

0 comments on commit 5e0fbe7

Please sign in to comment.