-
Notifications
You must be signed in to change notification settings - Fork 9.2k
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
resource/aws_lb: Add Cross Zone Load Balancing support for NLBs #3537
Changes from all commits
9b8a2e6
e95bda4
4275243
efe96e4
7d0b535
75b269e
7c89b7c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -79,7 +79,7 @@ func TestAccAWSLB_basic(t *testing.T) { | |
}) | ||
} | ||
|
||
func TestAccAWSLB_networkLoadbalancer(t *testing.T) { | ||
func TestAccAWSLB_networkLoadbalancerBasic(t *testing.T) { | ||
var conf elbv2.LoadBalancer | ||
lbName := fmt.Sprintf("testaccawslb-basic-%s", acctest.RandStringFromCharSet(10, acctest.CharSetAlphaNum)) | ||
|
||
|
@@ -90,7 +90,7 @@ func TestAccAWSLB_networkLoadbalancer(t *testing.T) { | |
CheckDestroy: testAccCheckAWSLBDestroy, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccAWSLBConfig_networkLoadbalancer(lbName), | ||
Config: testAccAWSLBConfig_networkLoadbalancer(lbName, false), | ||
Check: resource.ComposeAggregateTestCheckFunc( | ||
testAccCheckAWSLBExists("aws_lb.lb_test", &conf), | ||
resource.TestCheckResourceAttr("aws_lb.lb_test", "name", lbName), | ||
|
@@ -128,6 +128,7 @@ func TestAccAWSLB_networkLoadbalancerEIP(t *testing.T) { | |
resource.TestCheckResourceAttrSet("aws_lb.test", "zone_id"), | ||
resource.TestCheckResourceAttrSet("aws_lb.test", "dns_name"), | ||
resource.TestCheckResourceAttrSet("aws_lb.test", "arn"), | ||
resource.TestCheckResourceAttr("aws_lb.test", "enable_cross_zone_load_balancing", "true"), | ||
resource.TestCheckResourceAttr("aws_lb.test", "load_balancer_type", "network"), | ||
resource.TestCheckResourceAttr("aws_lb.test", "subnet_mapping.#", "2"), | ||
), | ||
|
@@ -157,6 +158,7 @@ func TestAccAWSLBBackwardsCompatibility(t *testing.T) { | |
resource.TestCheckResourceAttr("aws_alb.lb_test", "tags.%", "1"), | ||
resource.TestCheckResourceAttr("aws_alb.lb_test", "tags.Name", "TestAccAWSALB_basic"), | ||
resource.TestCheckResourceAttr("aws_alb.lb_test", "enable_deletion_protection", "false"), | ||
resource.TestCheckResourceAttr("aws_alb.lb_test", "enable_cross_zone_load_balancing", "false"), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should create a test that ensures enabling/disabling works as expected 😄 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Any hints as to where I could look for an example? It's my first time digging into a largeish golang codebase. Is it sufficient to add the directive to (See added commit) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was unable to run the acceptance tests after the commit. As soon as I have a break I will. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My general workflow does usually involve adding a directive/parameter to the test configuration function for the new attribute. Generally speaking though, its usually easiest to just create a whole new acceptance test and configuration function so you don't wind up with needing to pass in way too many directives to a function. Copy paste of an existing is okay and generally encouraged for this situation as the testing is more important than any (potential) later refactoring. 👍 |
||
resource.TestCheckResourceAttr("aws_alb.lb_test", "idle_timeout", "30"), | ||
resource.TestCheckResourceAttr("aws_alb.lb_test", "ip_address_type", "ipv4"), | ||
resource.TestCheckResourceAttr("aws_alb.lb_test", "load_balancer_type", "application"), | ||
|
@@ -263,6 +265,35 @@ func TestAccAWSLB_tags(t *testing.T) { | |
}) | ||
} | ||
|
||
func TestAccAWSLB_networkLoadbalancer_updateCrossZone(t *testing.T) { | ||
var pre, post elbv2.LoadBalancer | ||
lbName := fmt.Sprintf("testaccawslb-nlbcz-%s", acctest.RandStringFromCharSet(10, acctest.CharSetAlphaNum)) | ||
|
||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
IDRefreshName: "aws_lb.lb_test", | ||
Providers: testAccProviders, | ||
CheckDestroy: testAccCheckAWSLBDestroy, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccAWSLBConfig_networkLoadbalancer(lbName, true), | ||
Check: resource.ComposeAggregateTestCheckFunc( | ||
testAccCheckAWSLBExists("aws_lb.lb_test", &pre), | ||
resource.TestCheckResourceAttr("aws_lb.lb_test", "enable_cross_zone_load_balancing", "true"), | ||
), | ||
}, | ||
{ | ||
Config: testAccAWSLBConfig_networkLoadbalancer(lbName, false), | ||
Check: resource.ComposeAggregateTestCheckFunc( | ||
testAccCheckAWSLBExists("aws_lb.lb_test", &post), | ||
resource.TestCheckResourceAttr("aws_lb.lb_test", "enable_cross_zone_load_balancing", "false"), | ||
testAccCheckAWSlbARNs(&pre, &post), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func TestAccAWSLB_updatedSecurityGroups(t *testing.T) { | ||
var pre, post elbv2.LoadBalancer | ||
lbName := fmt.Sprintf("testaccawslb-basic-%s", acctest.RandStringFromCharSet(10, acctest.CharSetAlphaNum)) | ||
|
@@ -861,10 +892,11 @@ resource "aws_lb" "lb_test" { | |
"${aws_subnet.alb_test_3.id}", | ||
] | ||
|
||
load_balancer_type = "network" | ||
internal = true | ||
idle_timeout = 60 | ||
enable_deletion_protection = false | ||
load_balancer_type = "network" | ||
internal = true | ||
idle_timeout = 60 | ||
enable_deletion_protection = false | ||
enable_cross_zone_load_balancing = false | ||
|
||
tags { | ||
Name = "testAccAWSLBConfig_networkLoadbalancer_subnets" | ||
|
@@ -902,13 +934,15 @@ resource "aws_subnet" "alb_test_3" { | |
} | ||
`, lbName) | ||
} | ||
func testAccAWSLBConfig_networkLoadbalancer(lbName string) string { | ||
|
||
func testAccAWSLBConfig_networkLoadbalancer(lbName string, cz bool) string { | ||
return fmt.Sprintf(`resource "aws_lb" "lb_test" { | ||
name = "%s" | ||
internal = true | ||
load_balancer_type = "network" | ||
|
||
enable_deletion_protection = false | ||
enable_deletion_protection = false | ||
enable_cross_zone_load_balancing = %t | ||
|
||
subnet_mapping { | ||
subnet_id = "${aws_subnet.alb_test.id}" | ||
|
@@ -938,7 +972,7 @@ resource "aws_subnet" "alb_test" { | |
} | ||
} | ||
|
||
`, lbName) | ||
`, lbName, cz) | ||
} | ||
|
||
func testAccAWSLBConfig_networkLoadBalancerEIP(lbName string) string { | ||
|
@@ -980,6 +1014,7 @@ resource "aws_route_table_association" "a" { | |
resource "aws_lb" "test" { | ||
name = "%s" | ||
load_balancer_type = "network" | ||
enable_cross_zone_load_balancing = true | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See my note above -- we'll probably want to just copy paste the handling of the new attribute to a new test and config or at least pass the true/false value for this attributes is a directive into the above config function and use |
||
subnet_mapping { | ||
subnet_id = "${aws_subnet.public.0.id}" | ||
allocation_id = "${aws_eip.lb.0.id}" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comment references Idle timeout (probably meant to be cross zone flag)