Skip to content

Commit

Permalink
Merge pull request #26194 from hashicorp/b-aws_lb_listener_tags
Browse files Browse the repository at this point in the history
r/aws_lb_listener: update tags after creation
  • Loading branch information
johnsonaj authored Aug 9, 2022
2 parents e98dbe6 + c7903d2 commit c7fb276
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 0 deletions.
7 changes: 7 additions & 0 deletions .changelog/26194.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
```release-note:bug
resource/aws_lb_listener: Fix `ValidationError` when tags are added on `create`
```

```release-note:bug
resource/aws_lb_target_group: Fix `ValidationError` when tags are added on `create`
```
7 changes: 7 additions & 0 deletions internal/service/elbv2/const.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package elbv2

const (
ErrValidationError = "ValidationError"

TagsOnCreationErrMessage = "cannot specify tags on creation"
)
8 changes: 8 additions & 0 deletions internal/service/elbv2/listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,14 @@ func resourceListenerCreate(d *schema.ResourceData, meta interface{}) error {
output, err = retryListenerCreate(conn, params)
}

// Tags are not supported on creation with some load balancer types (i.e. Gateway)
// Retry creation without tags
if params.Tags != nil && tfawserr.ErrMessageContains(err, ErrValidationError, TagsOnCreationErrMessage) {
log.Printf("[WARN] ELBv2 Listener (%s) create failed (%s) with tags. Trying create without tags.", lbArn, err)
params.Tags = nil
output, err = retryListenerCreate(conn, params)
}

if err != nil {
return fmt.Errorf("creating ELBv2 Listener (%s): %w", lbArn, err)
}
Expand Down
5 changes: 5 additions & 0 deletions internal/service/elbv2/listener_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,7 @@ func TestAccELBV2Listener_LoadBalancerARN_gatewayLoadBalancer(t *testing.T) {
resource.TestCheckResourceAttrPair(resourceName, "load_balancer_arn", lbResourceName, "arn"),
resource.TestCheckResourceAttr(resourceName, "protocol", ""),
resource.TestCheckResourceAttr(resourceName, "port", "0"),
resource.TestCheckResourceAttr(resourceName, "tags.Name", rName),
),
},
},
Expand Down Expand Up @@ -1238,6 +1239,10 @@ resource "aws_lb_listener" "test" {
target_group_arn = aws_lb_target_group.test.id
type = "forward"
}
tags = {
Name = %[1]q
}
}
`, rName))
}
Expand Down
8 changes: 8 additions & 0 deletions internal/service/elbv2/target_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,14 @@ func resourceTargetGroupCreate(d *schema.ResourceData, meta interface{}) error {
resp, err = conn.CreateTargetGroup(params)
}

// Tags are not supported on creation with some protocol types(i.e. GENEVE)
// Retry creation without tags
if params.Tags != nil && tfawserr.ErrMessageContains(err, ErrValidationError, TagsOnCreationErrMessage) {
log.Printf("[WARN] ELBv2 Target Group (%s) create failed (%s) with tags. Trying create without tags.", groupName, err)
params.Tags = nil
resp, err = conn.CreateTargetGroup(params)
}

if err != nil {
return fmt.Errorf("creating LB Target Group: %w", err)
}
Expand Down
5 changes: 5 additions & 0 deletions internal/service/elbv2/target_group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -924,6 +924,7 @@ func TestAccELBV2TargetGroup_Geneve_basic(t *testing.T) {
testAccCheckTargetGroupExists(resourceName, &conf),
resource.TestCheckResourceAttr(resourceName, "port", "6081"),
resource.TestCheckResourceAttr(resourceName, "protocol", elbv2.ProtocolEnumGeneve),
resource.TestCheckResourceAttr(resourceName, "tags.Name", rName),
),
},
{
Expand Down Expand Up @@ -2164,6 +2165,10 @@ resource "aws_lb_target_group" "test" {
port = 80
protocol = "HTTP"
}
tags = {
Name = %[1]q
}
}
`, rName)
}
Expand Down

0 comments on commit c7fb276

Please sign in to comment.