Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

r/aws_lb_listener: update tags after creation #26194

Merged
merged 6 commits into from
Aug 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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