Skip to content

Commit

Permalink
fix(ec2): can't add non-default routes to subnets (#5332)
Browse files Browse the repository at this point in the history
* fixes using destinationCidrBlock to subnet route

* fix(ec2):
adds unit test for default routes

* chore(ec2): replace accidentally deleted test

* chore(ec2): run linter

* fix(ec2): update unit test to check route creation
  • Loading branch information
ialford authored and mergify[bot] committed Dec 13, 2019
1 parent f2edf9b commit e4309ab
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-ec2/lib/vpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1396,7 +1396,7 @@ export class Subnet extends Resource implements ISubnet {
const route = new CfnRoute(this, id, {
routeTableId: this.routeTable.routeTableId,
destinationCidrBlock: options.destinationCidrBlock || (options.destinationIpv6CidrBlock === undefined ? '0.0.0.0/0' : undefined),
destinationIpv6CidrBlock: options.destinationCidrBlock,
destinationIpv6CidrBlock: options.destinationIpv6CidrBlock,
[routerTypeToPropName(options.routerType)]: options.routerId,
});

Expand Down
48 changes: 46 additions & 2 deletions packages/@aws-cdk/aws-ec2/test/test.vpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { countResources, expect, haveResource, haveResourceLike, isSuperObject,
import { CfnOutput, Lazy, Stack, Tag } from '@aws-cdk/core';
import { Test } from 'nodeunit';
import { AclCidr, AclTraffic, CfnSubnet, CfnVPC, DefaultInstanceTenancy, GenericLinuxImage, InstanceType,
NatProvider, NetworkAcl, NetworkAclEntry, PrivateSubnet, Subnet, SubnetType, TrafficDirection, Vpc } from '../lib';
NatProvider, NetworkAcl, NetworkAclEntry, PrivateSubnet, PublicSubnet, RouterType, Subnet, SubnetType, TrafficDirection, Vpc } from '../lib';

export = {
"When creating a VPC": {
Expand Down Expand Up @@ -627,7 +627,49 @@ export = {
test.ok(natGatewayProvider.configuredGateways.length > 0);

test.done();
}
},
'Can add an IPv6 route'(test: Test) {
// GIVEN
const stack = getTestStack();

// WHEN
const vpc = new Vpc(stack, 'VPC');
(vpc.publicSubnets[0] as PublicSubnet).addRoute('SomeRoute', {
destinationIpv6CidrBlock: '2001:4860:4860::8888/32',
routerId: 'router-1',
routerType: RouterType.NETWORK_INTERFACE
});

// THEN

expect(stack).to(haveResourceLike("AWS::EC2::Route", {
DestinationIpv6CidrBlock: '2001:4860:4860::8888/32',
NetworkInterfaceId: 'router-1'
}));

test.done();
},
'Can add an IPv4 route'(test: Test) {
// GIVEN
const stack = getTestStack();

// WHEN
const vpc = new Vpc(stack, 'VPC');
(vpc.publicSubnets[0] as PublicSubnet).addRoute('SomeRoute', {
destinationCidrBlock: '0.0.0.0/0',
routerId: 'router-1',
routerType: RouterType.NETWORK_INTERFACE
});

// THEN

expect(stack).to(haveResourceLike("AWS::EC2::Route", {
DestinationCidrBlock: '0.0.0.0/0',
NetworkInterfaceId: 'router-1'
}));

test.done();
},
},

'NAT instances': {
Expand Down Expand Up @@ -680,6 +722,7 @@ export = {

test.done();
},

},

'Network ACL association': {
Expand Down Expand Up @@ -968,6 +1011,7 @@ export = {
test.deepEqual(subnetIds[0], subnet.subnetId);
test.done();
}

},
};

Expand Down

0 comments on commit e4309ab

Please sign in to comment.