diff --git a/aws/cf_template.go b/aws/cf_template.go index c816a642..2e3e0654 100644 --- a/aws/cf_template.go +++ b/aws/cf_template.go @@ -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)), }, ) } diff --git a/aws/cf_template_test.go b/aws/cf_template_test.go index 706b32d7..103684d2 100644 --- a/aws/cf_template_test.go +++ b/aws/cf_template_test.go @@ -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{ diff --git a/testdata/ingress_nlb/output/templates/ing.cf b/testdata/ingress_nlb/output/templates/ing.cf index ac57a010..984e9cc0 100644 --- a/testdata/ingress_nlb/output/templates/ing.cf +++ b/testdata/ingress_nlb/output/templates/ing.cf @@ -112,6 +112,10 @@ "Ref": "IpAddressType" }, "LoadBalancerAttributes": [ + { + "Key": "load_balancing.cross_zone.enabled", + "Value": "false" + }, { "Key": "access_logs.s3.enabled", "Value": "false" diff --git a/testdata/ingress_rg_shared_nlb/output/templates/shared.cf b/testdata/ingress_rg_shared_nlb/output/templates/shared.cf index ac57a010..984e9cc0 100644 --- a/testdata/ingress_rg_shared_nlb/output/templates/shared.cf +++ b/testdata/ingress_rg_shared_nlb/output/templates/shared.cf @@ -112,6 +112,10 @@ "Ref": "IpAddressType" }, "LoadBalancerAttributes": [ + { + "Key": "load_balancing.cross_zone.enabled", + "Value": "false" + }, { "Key": "access_logs.s3.enabled", "Value": "false" diff --git a/testdata/rg_nlb/output/templates/rg.cf b/testdata/rg_nlb/output/templates/rg.cf index ac57a010..984e9cc0 100644 --- a/testdata/rg_nlb/output/templates/rg.cf +++ b/testdata/rg_nlb/output/templates/rg.cf @@ -112,6 +112,10 @@ "Ref": "IpAddressType" }, "LoadBalancerAttributes": [ + { + "Key": "load_balancing.cross_zone.enabled", + "Value": "false" + }, { "Key": "access_logs.s3.enabled", "Value": "false"