Skip to content

Commit

Permalink
Merge pull request #31767 from yannrouillard/fix/fix-endpoint-group-w…
Browse files Browse the repository at this point in the history
…eight-0-not-taken-into-account

fix: ensure endpoint group weight 0 is taken into account
  • Loading branch information
ewbankkit authored Jun 5, 2023
2 parents c58b72f + 0e70f6c commit 7c0740c
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
3 changes: 3 additions & 0 deletions .changelog/31767.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
resource/aws_globalaccelerator_endpoint_group: Fix bug updating `endpoint_configuration.weight` to `0`
```
2 changes: 1 addition & 1 deletion internal/service/globalaccelerator/endpoint_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ func expandEndpointConfiguration(tfMap map[string]interface{}) *globalaccelerato
apiObject.EndpointId = aws.String(v)
}

if v, ok := tfMap["weight"].(int); ok && v != 0 {
if v, ok := tfMap["weight"].(int); ok {
apiObject.Weight = aws.Int64(int64(v))
}

Expand Down
12 changes: 6 additions & 6 deletions internal/service/globalaccelerator/endpoint_group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func TestAccGlobalAcceleratorEndpointGroup_ALBEndpoint_clientIP(t *testing.T) {
CheckDestroy: testAccCheckEndpointGroupDestroy(ctx),
Steps: []resource.TestStep{
{
Config: testAccEndpointGroupConfig_albClientIP(rName, false),
Config: testAccEndpointGroupConfig_albClientIP(rName, false, 20),
Check: resource.ComposeTestCheckFunc(
testAccCheckEndpointGroupExists(ctx, resourceName, &v),
acctest.MatchResourceAttrGlobalARN(resourceName, "arn", "globalaccelerator", regexp.MustCompile(`accelerator/[^/]+/listener/[^/]+/endpoint-group/[^/]+`)),
Expand All @@ -124,14 +124,14 @@ func TestAccGlobalAcceleratorEndpointGroup_ALBEndpoint_clientIP(t *testing.T) {
ImportStateVerify: true,
},
{
Config: testAccEndpointGroupConfig_albClientIP(rName, true),
Config: testAccEndpointGroupConfig_albClientIP(rName, true, 0),
Check: resource.ComposeTestCheckFunc(
testAccCheckEndpointGroupExists(ctx, resourceName, &v),
acctest.MatchResourceAttrGlobalARN(resourceName, "arn", "globalaccelerator", regexp.MustCompile(`accelerator/[^/]+/listener/[^/]+/endpoint-group/[^/]+`)),
resource.TestCheckResourceAttr(resourceName, "endpoint_configuration.#", "1"),
resource.TestCheckTypeSetElemNestedAttrs(resourceName, "endpoint_configuration.*", map[string]string{
"client_ip_preservation_enabled": "true",
"weight": "20",
"weight": "0",
}),
resource.TestCheckTypeSetElemAttrPair(resourceName, "endpoint_configuration.*.endpoint_id", albResourceName, "id"),
resource.TestCheckResourceAttr(resourceName, "endpoint_group_region", acctest.Region()),
Expand Down Expand Up @@ -528,7 +528,7 @@ resource "aws_globalaccelerator_endpoint_group" "test" {
`, rName)
}

func testAccEndpointGroupConfig_albClientIP(rName string, clientIP bool) string {
func testAccEndpointGroupConfig_albClientIP(rName string, clientIP bool, weight int) string {
return acctest.ConfigCompose(acctest.ConfigVPCWithSubnets(rName, 2), fmt.Sprintf(`
resource "aws_lb" "test" {
name = %[1]q
Expand Down Expand Up @@ -596,7 +596,7 @@ resource "aws_globalaccelerator_endpoint_group" "test" {
endpoint_configuration {
endpoint_id = aws_lb.test.id
weight = 20
weight = %[3]d
client_ip_preservation_enabled = %[2]t
}
Expand All @@ -607,7 +607,7 @@ resource "aws_globalaccelerator_endpoint_group" "test" {
threshold_count = 3
traffic_dial_percentage = 100
}
`, rName, clientIP))
`, rName, clientIP, weight))
}

func testAccEndpointGroupConfig_instance(rName string) string {
Expand Down

0 comments on commit 7c0740c

Please sign in to comment.