Skip to content

Commit

Permalink
add test case for adding / deleting subnets
Browse files Browse the repository at this point in the history
  • Loading branch information
elchead committed Sep 5, 2023
1 parent 525b02a commit fe68d86
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 7 deletions.
11 changes: 6 additions & 5 deletions internal/service/elbv2/load_balancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -1048,11 +1048,12 @@ func customizeDiffNLB(_ context.Context, diff *schema.ResourceDiff, v interface{
// Get diff for subnets.
o, n := diff.GetChange("subnets")
os, ns := o.(*schema.Set), n.(*schema.Set)
if del := os.Difference(ns).List(); len(del) > 0 {
if err := diff.ForceNew("subnets"); err != nil {
return err
}
}
// TODO the test cases do not see adding subnets because they are only known after apply
//if del := os.Difference(ns).List(); len(del) > 0 {
// if err := diff.ForceNew("subnets"); err != nil {
// return err
// }
//}
o, n = diff.GetChange("subnet_mapping")
os, ns = o.(*schema.Set), n.(*schema.Set)
if del := os.Difference(ns).List(); len(del) > 0 {
Expand Down
35 changes: 33 additions & 2 deletions internal/service/elbv2/load_balancer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1351,7 +1351,7 @@ func TestAccELBV2LoadBalancer_NetworkLoadBalancer_updateSecurityGroups(t *testin
})
}

func TestAccELBV2LoadBalancer_NetworkLoadBalancer_updateSubnets(t *testing.T) {
func TestAccELBV2LoadBalancer_NetworkLoadBalancer_addSubnets(t *testing.T) {
ctx := acctest.Context(t)
var pre, post elbv2.LoadBalancer
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
Expand All @@ -1374,14 +1374,45 @@ func TestAccELBV2LoadBalancer_NetworkLoadBalancer_updateSubnets(t *testing.T) {
Config: testAccLoadBalancerConfig_nlbSubnets(rName, 3),
Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckLoadBalancerExists(ctx, resourceName, &post),
testAccCheckLoadBalancerRecreated(&post, &pre),
testAccCheckLoadBalancerNotRecreated(&post, &pre),
resource.TestCheckResourceAttr(resourceName, "subnets.#", "3"),
),
},
},
})
}

func TestAccELBV2LoadBalancer_NetworkLoadBalancer_deleteSubnets(t *testing.T) {
ctx := acctest.Context(t)
var pre, post elbv2.LoadBalancer
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
resourceName := "aws_lb.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(ctx, t) },
ErrorCheck: acctest.ErrorCheck(t, elbv2.EndpointsID),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
CheckDestroy: testAccCheckLoadBalancerDestroy(ctx),
Steps: []resource.TestStep{
{
Config: testAccLoadBalancerConfig_nlbSubnets(rName, 3),
Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckLoadBalancerExists(ctx, resourceName, &pre),
resource.TestCheckResourceAttr(resourceName, "subnets.#", "3"),
),
},
{
Config: testAccLoadBalancerConfig_nlbSubnets(rName, 2),
Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckLoadBalancerExists(ctx, resourceName, &post),
testAccCheckLoadBalancerRecreated(&post, &pre),
resource.TestCheckResourceAttr(resourceName, "subnets.#", "2"),
),
},
},
})
}

func TestAccELBV2LoadBalancer_updateDesyncMitigationMode(t *testing.T) {
ctx := acctest.Context(t)
if testing.Short() {
Expand Down

0 comments on commit fe68d86

Please sign in to comment.