Skip to content

Commit

Permalink
fix(elbv2): unable to specify load balancer name
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Elad Ben-Israel committed Jan 7, 2019
1 parent f43b4d4 commit b053cdb
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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();
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

};

0 comments on commit b053cdb

Please sign in to comment.