Skip to content

Commit

Permalink
Unit test for EIGW + rename IRouter to IRouteTarget
Browse files Browse the repository at this point in the history
  • Loading branch information
Leonardo Gama committed Jun 25, 2024
1 parent 446664d commit a417a82
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 16 deletions.
24 changes: 12 additions & 12 deletions packages/@aws-cdk/aws-vpcv2-alpha/lib/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { IIpAddresses } from './vpc-v2';
import { Construct, IDependable } from 'constructs';
import { Resource } from 'aws-cdk-lib/core';

export interface IRouter {
export interface IRouteTarget {
readonly routerType: RouterType;
readonly routerId: string;
}
Expand Down Expand Up @@ -45,7 +45,7 @@ export interface VpcPeeringConnectionProps {
readonly peerRoleArn: string;
}

export class CarrierGateway extends Resource implements IRouter {
export class CarrierGateway extends Resource implements IRouteTarget {
public readonly routerId: string;
public readonly routerType: RouterType;

Expand All @@ -64,7 +64,7 @@ export class CarrierGateway extends Resource implements IRouter {
}
}

export class EgressOnlyInternetGateway extends Resource implements IRouter {
export class EgressOnlyInternetGateway extends Resource implements IRouteTarget {
public readonly routerId: string;
public readonly routerType: RouterType;

Expand All @@ -83,7 +83,7 @@ export class EgressOnlyInternetGateway extends Resource implements IRouter {
}
}

export class InternetGateway extends Resource implements IRouter {
export class InternetGateway extends Resource implements IRouteTarget {
public readonly routerId: string;
public readonly routerType: RouterType;
public readonly vpcId: string;
Expand All @@ -102,7 +102,7 @@ export class InternetGateway extends Resource implements IRouter {
}
}

export class VirtualPrivateGateway extends Resource implements IRouter {
export class VirtualPrivateGateway extends Resource implements IRouteTarget {
public readonly routerId: string;
public readonly routerType: RouterType;
public readonly vpcId: string;
Expand All @@ -123,7 +123,7 @@ export class VirtualPrivateGateway extends Resource implements IRouter {
}
}

export class NatGateway extends Resource implements IRouter {
export class NatGateway extends Resource implements IRouteTarget {
public readonly routerId: string;
public readonly routerType: RouterType;
public readonly allocationId?: string;
Expand Down Expand Up @@ -162,7 +162,7 @@ export class NatGateway extends Resource implements IRouter {
}
}

export class NetworkInterface extends Resource implements IRouter {
export class NetworkInterface extends Resource implements IRouteTarget {
public readonly routerId: string;
public readonly routerType: RouterType;

Expand All @@ -181,7 +181,7 @@ export class NetworkInterface extends Resource implements IRouter {
}
}

export class TransitGateway extends Resource implements IRouter {
export class TransitGateway extends Resource implements IRouteTarget {
public readonly routerId: string;
public readonly routerType: RouterType;

Expand All @@ -198,7 +198,7 @@ export class TransitGateway extends Resource implements IRouter {
}
}

export class VpcPeeringConnection extends Resource implements IRouter {
export class VpcPeeringConnection extends Resource implements IRouteTarget {
public readonly routerId: string;
public readonly routerType: RouterType;
public readonly peerRoleArn: string;
Expand All @@ -224,7 +224,7 @@ export class VpcPeeringConnection extends Resource implements IRouter {
export interface IRouteV2 {
readonly routeTable: IRouteTable;
readonly destination: IIpAddresses;
readonly target: IRouter | IVpcEndpoint;
readonly target: IRouteTarget | IVpcEndpoint;
}

export interface RouteProps {
Expand All @@ -241,7 +241,7 @@ export interface RouteProps {
/**
* The target gateway or endpoint of the route
*/
readonly target: IRouter | IVpcEndpoint;
readonly target: IRouteTarget | IVpcEndpoint;
}

/**
Expand All @@ -250,7 +250,7 @@ export interface RouteProps {
*/
export class Route extends Resource implements IRouteV2 {
public readonly destination: IIpAddresses;
public readonly target: IRouter | IVpcEndpoint;
public readonly target: IRouteTarget | IVpcEndpoint;
public readonly routeTable: IRouteTable;

/**
Expand Down
42 changes: 38 additions & 4 deletions packages/@aws-cdk/aws-vpcv2-alpha/test/route.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,16 @@ describe('EC2 Routing', () => {
enableDnsHostnames: true,
enableDnsSupport: true,
});
routeTable = new route.RouteTable(stack, 'TestRouteTable', {
vpcId: myVpc.vpcId,
});
mySubnet = new subnet.SubnetV2(stack, 'TestSubnet', {
vpc: myVpc,
availabilityZone: 'us-east-1a',
cidrBlock: new subnet.Ipv4Cidr('10.0.0.0/24'),
ipv6CidrBlock: new subnet.Ipv6Cidr(cdk.Fn.select(0, myVpc.ipv6CidrBlocks)),
subnetType: SubnetType.PRIVATE_WITH_EGRESS,
});
routeTable = new route.RouteTable(stack, 'TestRouteTable', {
vpcId: myVpc.vpcId,
routeTable: routeTable,
});
});

Expand All @@ -45,6 +46,39 @@ describe('EC2 Routing', () => {
destination: vpc.IpAddresses.ipv4('0.0.0.0/0'),
target: eigw,
});
Template.fromStack(stack).toJSON();
if (mySubnet) {}
// console.log(Template.fromStack(stack).toJSON().Resources);
Template.fromStack(stack).templateMatches({
Resources: {
// EIGW should be in stack
TestEIGW4E4CDA8D: {
Type: 'AWS::EC2::EgressOnlyInternetGateway',
Properties: {
VpcId: {
'Fn::GetAtt': [
'TestVpcE77CE678', 'VpcId',
],
},
},
},
// Route linking IP to EIGW should be in stack
TestRoute4CB59404: {
Type: 'AWS::EC2::Route',
Properties: {
DestinationCidrBlock: '0.0.0.0/0',
EgressOnlyInternetGatewayId: {
'Fn::GetAtt': [
'TestEIGW4E4CDA8D', 'Id',
],
},
RouteTableId: {
'Fn::GetAtt': [
'TestRouteTableC34C2E1C', 'RouteTableId',
],
},
},
},
}
});
});
});

0 comments on commit a417a82

Please sign in to comment.