From 1d7198a51c94d9431b7e1b1b6a84e01ba1daf308 Mon Sep 17 00:00:00 2001 From: Hironao OTSUBO Date: Wed, 6 Feb 2019 18:52:04 +0900 Subject: [PATCH] fix(elbv2): fix specifying TargetGroup name (#1684) TargetGroup construct passes targetGroupName prop to underlying CfnTargetGroup, but the correct name is Name, not TargetGroupName. Fixes #1674 --- .../lib/shared/base-target-group.ts | 2 +- .../test/alb/test.listener.ts | 20 +++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/packages/@aws-cdk/aws-elasticloadbalancingv2/lib/shared/base-target-group.ts b/packages/@aws-cdk/aws-elasticloadbalancingv2/lib/shared/base-target-group.ts index 5932132991260..447262e1d8c1d 100644 --- a/packages/@aws-cdk/aws-elasticloadbalancingv2/lib/shared/base-target-group.ts +++ b/packages/@aws-cdk/aws-elasticloadbalancingv2/lib/shared/base-target-group.ts @@ -213,7 +213,7 @@ export abstract class TargetGroupBase extends cdk.Construct implements ITargetGr this.targetType = baseProps.targetType; this.resource = new CfnTargetGroup(this, 'Resource', { - targetGroupName: baseProps.targetGroupName, + name: baseProps.targetGroupName, targetGroupAttributes: new cdk.Token(() => renderAttributes(this.attributes)), targetType: new cdk.Token(() => this.targetType), targets: new cdk.Token(() => this.targetsJson), diff --git a/packages/@aws-cdk/aws-elasticloadbalancingv2/test/alb/test.listener.ts b/packages/@aws-cdk/aws-elasticloadbalancingv2/test/alb/test.listener.ts index dcf2c62c84ec1..061a578d03798 100644 --- a/packages/@aws-cdk/aws-elasticloadbalancingv2/test/alb/test.listener.ts +++ b/packages/@aws-cdk/aws-elasticloadbalancingv2/test/alb/test.listener.ts @@ -114,6 +114,26 @@ export = { test.done(); }, + 'Can configure name on TargetGroups'(test: Test) { + // GIVEN + const stack = new cdk.Stack(); + const vpc = new ec2.VpcNetwork(stack, 'Stack'); + + // WHEN + new elbv2.ApplicationTargetGroup(stack, 'TargetGroup', { + vpc, + port: 80, + targetGroupName: 'foo' + }); + + // THEN + expect(stack).to(haveResource('AWS::ElasticLoadBalancingV2::TargetGroup', { + Name: 'foo' + })); + + test.done(); + }, + 'Can add target groups with and without conditions'(test: Test) { // GIVEN const stack = new cdk.Stack();