From 77fa6b743d8bbbafe07c093550b37ab794d30a71 Mon Sep 17 00:00:00 2001 From: Vinny Do Date: Mon, 21 Oct 2019 10:04:58 +1100 Subject: [PATCH] fix(elbv2): fix disabling proxy protocol v2 attribute for NetworkTargetGroup 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 5fe5fc5a23ba7..d5c0df41b598b 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(); + }, +};