Skip to content

Commit

Permalink
fix: disabling NLB cross zone load balancing had no effect on current…
Browse files Browse the repository at this point in the history
… NLBs (#682)

* fix: disabling NLB cross zone load balancing had no effect on current NLBs

Signed-off-by: Sandor Szücs <[email protected]>

* fix golden file tests

Signed-off-by: Sandor Szücs <[email protected]>

---------

Signed-off-by: Sandor Szücs <[email protected]>
  • Loading branch information
szuecs authored Feb 13, 2024
1 parent f50f746 commit c898480
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 2 deletions.
4 changes: 2 additions & 2 deletions aws/cf_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,11 +300,11 @@ func generateTemplate(spec *stackSpec) (string, error) {
)
}

if spec.nlbCrossZone && spec.loadbalancerType == LoadBalancerTypeNetwork {
if spec.loadbalancerType == LoadBalancerTypeNetwork {
lbAttrList = append(lbAttrList,
cloudformation.ElasticLoadBalancingV2LoadBalancerLoadBalancerAttribute{
Key: cloudformation.String("load_balancing.cross_zone.enabled"),
Value: cloudformation.String("true"),
Value: cloudformation.String(fmt.Sprintf("%t", spec.nlbCrossZone)),
},
)
}
Expand Down
14 changes: 14 additions & 0 deletions aws/cf_template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,20 @@ func TestGenerateTemplate(t *testing.T) {
require.Equal(t, attributes[0].Value.Literal, "true")
},
},
{
name: "nlb cross zone load balancing can be disabled for Network load balancers",
spec: &stackSpec{
loadbalancerType: LoadBalancerTypeNetwork,
nlbCrossZone: false,
},
validate: func(t *testing.T, template *cloudformation.Template) {
require.NotNil(t, template.Resources["LB"])
properties := template.Resources["LB"].Properties.(*cloudformation.ElasticLoadBalancingV2LoadBalancer)
attributes := []cloudformation.ElasticLoadBalancingV2LoadBalancerLoadBalancerAttribute(*properties.LoadBalancerAttributes)
require.Equal(t, attributes[0].Key.Literal, "load_balancing.cross_zone.enabled")
require.Equal(t, attributes[0].Value.Literal, "false")
},
},
{
name: "nlb HTTP listener should not be enabled when HTTP is disabled",
spec: &stackSpec{
Expand Down
4 changes: 4 additions & 0 deletions testdata/ingress_nlb/output/templates/ing.cf
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@
"Ref": "IpAddressType"
},
"LoadBalancerAttributes": [
{
"Key": "load_balancing.cross_zone.enabled",
"Value": "false"
},
{
"Key": "access_logs.s3.enabled",
"Value": "false"
Expand Down
4 changes: 4 additions & 0 deletions testdata/ingress_rg_shared_nlb/output/templates/shared.cf
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@
"Ref": "IpAddressType"
},
"LoadBalancerAttributes": [
{
"Key": "load_balancing.cross_zone.enabled",
"Value": "false"
},
{
"Key": "access_logs.s3.enabled",
"Value": "false"
Expand Down
4 changes: 4 additions & 0 deletions testdata/rg_nlb/output/templates/rg.cf
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@
"Ref": "IpAddressType"
},
"LoadBalancerAttributes": [
{
"Key": "load_balancing.cross_zone.enabled",
"Value": "false"
},
{
"Key": "access_logs.s3.enabled",
"Value": "false"
Expand Down

0 comments on commit c898480

Please sign in to comment.