Skip to content

Commit

Permalink
fix(elbv2): unable to specify load balancer name (#1486)
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 b61c7c9 commit 5b24583
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
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
Expand Up @@ -2,6 +2,7 @@ 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');

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();
},
};
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 5b24583

Please sign in to comment.