From b053cdb609f035d1576bbbca71f21f2deb41d9b1 Mon Sep 17 00:00:00 2001 From: Elad Ben-Israel Date: Mon, 7 Jan 2019 11:07:20 +0200 Subject: [PATCH] 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(); + } + };