From 8b598c49730cf6bb126fa68825cf5f28d9373475 Mon Sep 17 00:00:00 2001 From: Vinny Do Date: Wed, 23 Oct 2019 21:07:19 +1100 Subject: [PATCH] fix(elbv2): fix disabling proxy protocol v2 attribute for NetworkTargetGroup (#4596) fixes #4574 --- .../lib/nlb/network-target-group.ts | 4 +- .../test/nlb/test.target-group.ts | 52 +++++++++++++++++++ 2 files changed, 54 insertions(+), 2 deletions(-) create mode 100644 packages/@aws-cdk/aws-elasticloadbalancingv2/test/nlb/test.target-group.ts diff --git a/packages/@aws-cdk/aws-elasticloadbalancingv2/lib/nlb/network-target-group.ts b/packages/@aws-cdk/aws-elasticloadbalancingv2/lib/nlb/network-target-group.ts index 054dffc5c622b..571e81aa2bde8 100644 --- a/packages/@aws-cdk/aws-elasticloadbalancingv2/lib/nlb/network-target-group.ts +++ b/packages/@aws-cdk/aws-elasticloadbalancingv2/lib/nlb/network-target-group.ts @@ -54,8 +54,8 @@ export class NetworkTargetGroup extends TargetGroupBase implements INetworkTarge this.listeners = []; - if (props.proxyProtocolV2) { - this.setAttribute('proxy_protocol_v2.enabled', 'true'); + if (props.proxyProtocolV2 != null) { + this.setAttribute('proxy_protocol_v2.enabled', props.proxyProtocolV2 ? 'true' : 'false'); } this.addTarget(...(props.targets || [])); diff --git a/packages/@aws-cdk/aws-elasticloadbalancingv2/test/nlb/test.target-group.ts b/packages/@aws-cdk/aws-elasticloadbalancingv2/test/nlb/test.target-group.ts new file mode 100644 index 0000000000000..cf00f7356faf3 --- /dev/null +++ b/packages/@aws-cdk/aws-elasticloadbalancingv2/test/nlb/test.target-group.ts @@ -0,0 +1,52 @@ +import { expect, haveResource } from '@aws-cdk/assert'; +import cdk = require('@aws-cdk/core'); +import { Test } from 'nodeunit'; +import elbv2 = require('../../lib'); + +export = { + 'Enable proxy protocol v2 attribute for target group'(test: Test) { + // GIVEN + const stack = new cdk.Stack(); + + // WHEN + new elbv2.NetworkTargetGroup(stack, 'Group', { + port: 80, + proxyProtocolV2: true + }); + + // THEN + expect(stack).to(haveResource('AWS::ElasticLoadBalancingV2::TargetGroup', { + TargetGroupAttributes: [ + { + Key: 'proxy_protocol_v2.enabled', + Value: 'true' + } + ] + })); + + test.done(); + }, + + 'Disable proxy protocol v2 for attribute target group'(test: Test) { + // GIVEN + const stack = new cdk.Stack(); + + // WHEN + new elbv2.NetworkTargetGroup(stack, 'Group', { + port: 80, + proxyProtocolV2: false + }); + + // THEN + expect(stack).to(haveResource('AWS::ElasticLoadBalancingV2::TargetGroup', { + TargetGroupAttributes: [ + { + Key: 'proxy_protocol_v2.enabled', + Value: 'false' + } + ] + })); + + test.done(); + }, +};