Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ec2): can't add non-default routes to subnets #5332

Merged
merged 6 commits into from
Dec 13, 2019
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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