From b053cdb609f035d1576bbbca71f21f2deb41d9b1 Mon Sep 17 00:00:00 2001 From: Elad Ben-Israel Date: Mon, 7 Jan 2019 11:07:20 +0200 Subject: [PATCH 1/2] fix(elbv2): unable to specify load balancer name Since #973, the renames of CFN properties from "name" to "xxxName" were removed. But the ELBv2 library still used `loadBalancerName`. The reason this was not discovered was because we are splatting `additionalProps` of type `any`, and this caused the type checker to stop verifying property names. Fixes #1481 --- .../lib/shared/base-load-balancer.ts | 2 +- .../test/alb/test.load-balancer.ts | 19 +++++++++++++++++++ .../test/nlb/test.load-balancer.ts | 19 +++++++++++++++++++ 3 files changed, 39 insertions(+), 1 deletion(-) diff --git a/packages/@aws-cdk/aws-elasticloadbalancingv2/lib/shared/base-load-balancer.ts b/packages/@aws-cdk/aws-elasticloadbalancingv2/lib/shared/base-load-balancer.ts index a70ef98fcd4d2..0e98adc7123d0 100644 --- a/packages/@aws-cdk/aws-elasticloadbalancingv2/lib/shared/base-load-balancer.ts +++ b/packages/@aws-cdk/aws-elasticloadbalancingv2/lib/shared/base-load-balancer.ts @@ -104,7 +104,7 @@ export abstract class BaseLoadBalancer extends cdk.Construct implements route53. this.vpc = baseProps.vpc; const resource = new CfnLoadBalancer(this, 'Resource', { - loadBalancerName: baseProps.loadBalancerName, + name: baseProps.loadBalancerName, subnets: subnets.map(s => s.subnetId), scheme: internetFacing ? 'internet-facing' : 'internal', loadBalancerAttributes: new cdk.Token(() => renderAttributes(this.attributes)), diff --git a/packages/@aws-cdk/aws-elasticloadbalancingv2/test/alb/test.load-balancer.ts b/packages/@aws-cdk/aws-elasticloadbalancingv2/test/alb/test.load-balancer.ts index ea995361ae531..18894e7e9c7ba 100644 --- a/packages/@aws-cdk/aws-elasticloadbalancingv2/test/alb/test.load-balancer.ts +++ b/packages/@aws-cdk/aws-elasticloadbalancingv2/test/alb/test.load-balancer.ts @@ -4,6 +4,7 @@ import s3 = require('@aws-cdk/aws-s3'); import cdk = require('@aws-cdk/cdk'); import { Test } from 'nodeunit'; import elbv2 = require('../../lib'); +import { Stack } from '@aws-cdk/cdk'; export = { 'Trivial construction: internet facing'(test: Test) { @@ -186,4 +187,22 @@ export = { test.done(); }, + + 'loadBalancerName'(test: Test) { + // GIVEN + const stack = new Stack(); + const vpc = new ec2.VpcNetwork(stack, 'Stack'); + + // WHEN + new elbv2.ApplicationLoadBalancer(stack, 'ALB', { + loadBalancerName: 'myLoadBalancer', + vpc + }); + + // THEN + expect(stack).to(haveResource('AWS::ElasticLoadBalancingV2::LoadBalancer', { + Name: 'myLoadBalancer' + })); + test.done(); + }, }; diff --git a/packages/@aws-cdk/aws-elasticloadbalancingv2/test/nlb/test.load-balancer.ts b/packages/@aws-cdk/aws-elasticloadbalancingv2/test/nlb/test.load-balancer.ts index bc69a591ad94c..5cfa73c785550 100644 --- a/packages/@aws-cdk/aws-elasticloadbalancingv2/test/nlb/test.load-balancer.ts +++ b/packages/@aws-cdk/aws-elasticloadbalancingv2/test/nlb/test.load-balancer.ts @@ -75,4 +75,23 @@ export = { test.done(); }, + + 'loadBalancerName'(test: Test) { + // GIVEN + const stack = new cdk.Stack(); + const vpc = new ec2.VpcNetwork(stack, 'Stack'); + + // WHEN + new elbv2.NetworkLoadBalancer(stack, 'ALB', { + loadBalancerName: 'myLoadBalancer', + vpc + }); + + // THEN + expect(stack).to(haveResource('AWS::ElasticLoadBalancingV2::LoadBalancer', { + Name: 'myLoadBalancer' + })); + test.done(); + } + }; From 7347cbeb97f73e1bfa937e427155a5c63eff35f7 Mon Sep 17 00:00:00 2001 From: Elad Ben-Israel Date: Mon, 7 Jan 2019 11:49:28 +0200 Subject: [PATCH 2/2] Fix tslint error --- .../aws-elasticloadbalancingv2/test/alb/test.load-balancer.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/@aws-cdk/aws-elasticloadbalancingv2/test/alb/test.load-balancer.ts b/packages/@aws-cdk/aws-elasticloadbalancingv2/test/alb/test.load-balancer.ts index 18894e7e9c7ba..7f804951972b4 100644 --- a/packages/@aws-cdk/aws-elasticloadbalancingv2/test/alb/test.load-balancer.ts +++ b/packages/@aws-cdk/aws-elasticloadbalancingv2/test/alb/test.load-balancer.ts @@ -2,9 +2,9 @@ import { expect, haveResource, ResourcePart } from '@aws-cdk/assert'; import ec2 = require('@aws-cdk/aws-ec2'); import s3 = require('@aws-cdk/aws-s3'); import cdk = require('@aws-cdk/cdk'); +import { Stack } from '@aws-cdk/cdk'; import { Test } from 'nodeunit'; import elbv2 = require('../../lib'); -import { Stack } from '@aws-cdk/cdk'; export = { 'Trivial construction: internet facing'(test: Test) {