Skip to content

Commit 33b983c

Browse files
feat(ec2): more router types (#20151)
Fixes #19057 https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-ec2-route.html#aws-resource-ec2-route-properties ---- ### All Submissions: * [ ] Have you followed the guidelines in our [Contributing guide?](https://github.com/aws/aws-cdk/blob/master/CONTRIBUTING.md) ### Adding new Unconventional Dependencies: * [ ] This PR adds new unconventional dependencies following the process described [here](https://github.com/aws/aws-cdk/blob/master/CONTRIBUTING.md/#adding-new-unconventional-dependencies) ### New Features * [ ] Have you added the new feature to an [integration test](https://github.com/aws/aws-cdk/blob/master/INTEGRATION_TESTS.md)? * [ ] Did you use `yarn integ` to deploy the infrastructure and generate the snapshot (i.e. `yarn integ` without `--dry-run`)? *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent a14d914 commit 33b983c

File tree

2 files changed

+62
-0
lines changed

2 files changed

+62
-0
lines changed

packages/@aws-cdk/aws-ec2/lib/vpc.ts

+24
Original file line numberDiff line numberDiff line change
@@ -1811,6 +1811,11 @@ export interface AddRouteOptions {
18111811
* Type of router used in route
18121812
*/
18131813
export enum RouterType {
1814+
/**
1815+
* Carrier gateway
1816+
*/
1817+
CARRIER_GATEWAY = 'CarrierGateway',
1818+
18141819
/**
18151820
* Egress-only Internet Gateway
18161821
*/
@@ -1826,6 +1831,11 @@ export enum RouterType {
18261831
*/
18271832
INSTANCE = 'Instance',
18281833

1834+
/**
1835+
* Local Gateway
1836+
*/
1837+
LOCAL_GATEWAY = 'LocalGateway',
1838+
18291839
/**
18301840
* NAT Gateway
18311841
*/
@@ -1836,20 +1846,34 @@ export enum RouterType {
18361846
*/
18371847
NETWORK_INTERFACE = 'NetworkInterface',
18381848

1849+
/**
1850+
* Transit Gateway
1851+
*/
1852+
TRANSIT_GATEWAY = 'TransitGateway',
1853+
18391854
/**
18401855
* VPC peering connection
18411856
*/
18421857
VPC_PEERING_CONNECTION = 'VpcPeeringConnection',
1858+
1859+
/**
1860+
* VPC Endpoint for gateway load balancers
1861+
*/
1862+
VPC_ENDPOINT = 'VpcEndpoint',
18431863
}
18441864

18451865
function routerTypeToPropName(routerType: RouterType) {
18461866
return ({
1867+
[RouterType.CARRIER_GATEWAY]: 'carrierGatewayId',
18471868
[RouterType.EGRESS_ONLY_INTERNET_GATEWAY]: 'egressOnlyInternetGatewayId',
18481869
[RouterType.GATEWAY]: 'gatewayId',
18491870
[RouterType.INSTANCE]: 'instanceId',
1871+
[RouterType.LOCAL_GATEWAY]: 'localGatewayId',
18501872
[RouterType.NAT_GATEWAY]: 'natGatewayId',
18511873
[RouterType.NETWORK_INTERFACE]: 'networkInterfaceId',
1874+
[RouterType.TRANSIT_GATEWAY]: 'transitGatewayId',
18521875
[RouterType.VPC_PEERING_CONNECTION]: 'vpcPeeringConnectionId',
1876+
[RouterType.VPC_ENDPOINT]: 'vpcEndpointId',
18531877
})[routerType];
18541878
}
18551879

packages/@aws-cdk/aws-ec2/test/vpc.test.ts

+38
Original file line numberDiff line numberDiff line change
@@ -1869,6 +1869,44 @@ describe('vpc', () => {
18691869
expect(subnetIds).toEqual(expected.map(s => s.subnetId));
18701870

18711871
});
1872+
1873+
test('tests router types', () => {
1874+
// GIVEN
1875+
const stack = getTestStack();
1876+
const vpc = new Vpc(stack, 'Vpc');
1877+
1878+
// WHEN
1879+
(vpc.publicSubnets[0] as Subnet).addRoute('TransitRoute', {
1880+
routerType: RouterType.TRANSIT_GATEWAY,
1881+
routerId: 'transit-id',
1882+
});
1883+
(vpc.publicSubnets[0] as Subnet).addRoute('CarrierRoute', {
1884+
routerType: RouterType.CARRIER_GATEWAY,
1885+
routerId: 'carrier-gateway-id',
1886+
});
1887+
(vpc.publicSubnets[0] as Subnet).addRoute('LocalGatewayRoute', {
1888+
routerType: RouterType.LOCAL_GATEWAY,
1889+
routerId: 'local-gateway-id',
1890+
});
1891+
(vpc.publicSubnets[0] as Subnet).addRoute('VpcEndpointRoute', {
1892+
routerType: RouterType.VPC_ENDPOINT,
1893+
routerId: 'vpc-endpoint-id',
1894+
});
1895+
1896+
// THEN
1897+
Template.fromStack(stack).hasResourceProperties('AWS::EC2::Route', {
1898+
TransitGatewayId: 'transit-id',
1899+
});
1900+
Template.fromStack(stack).hasResourceProperties('AWS::EC2::Route', {
1901+
LocalGatewayId: 'local-gateway-id',
1902+
});
1903+
Template.fromStack(stack).hasResourceProperties('AWS::EC2::Route', {
1904+
CarrierGatewayId: 'carrier-gateway-id',
1905+
});
1906+
Template.fromStack(stack).hasResourceProperties('AWS::EC2::Route', {
1907+
VpcEndpointId: 'vpc-endpoint-id',
1908+
});
1909+
});
18721910
});
18731911
});
18741912

0 commit comments

Comments
 (0)