Skip to content

Commit

Permalink
Network interface unit test and comment out out-of-scope constructs
Browse files Browse the repository at this point in the history
  • Loading branch information
Leonardo Gama committed Jul 2, 2024
1 parent a1ddc1b commit bad7ffc
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 19 deletions.
39 changes: 20 additions & 19 deletions packages/@aws-cdk/aws-vpcv2-alpha/test/integ.route-v2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import * as vpc_v2 from '../lib/vpc-v2';
import { IntegTest } from '@aws-cdk/integ-tests-alpha';
import * as cdk from 'aws-cdk-lib';
import { Ipv4Cidr, Ipv6Cidr, SubnetV2 } from '../lib/subnet-v2';
import { CarrierGateway, EgressOnlyInternetGateway, InternetGateway, NatGateway, NetworkInterface, Route, RouteTable, TransitGateway, VPNGateway, VpcPeeringConnection } from '../lib/route';
// import { CarrierGateway, TransitGateway } from '../lib/route';
import { EgressOnlyInternetGateway, InternetGateway, NatGateway, NetworkInterface, Route, RouteTable, VPNGateway, VpcPeeringConnection } from '../lib/route';
import { GatewayVpcEndpoint, GatewayVpcEndpointAwsService, SubnetType } from 'aws-cdk-lib/aws-ec2';
import { Fn } from 'aws-cdk-lib';
//import { log } from 'console';
Expand All @@ -25,14 +26,14 @@ const app = new cdk.App();

const stacks: {[id: string] : cdk.Stack} = {
'default': new cdk.Stack(app, 'aws-cdk-routev2-alpha', {stackName: 'DefaultVpcDeploy'}),
'cgw': new cdk.Stack(app, 'aws-cdk-routev2-carriergw-alpha', {stackName: 'CarrierGatewayVpc'}), // failing
// 'cgw': new cdk.Stack(app, 'aws-cdk-routev2-carriergw-alpha', {stackName: 'CarrierGatewayVpc'}),
'eigw': new cdk.Stack(app, 'aws-cdk-routev2-egressonlyigw-alpha', {stackName: 'EgressOnlyIgwVpc'}),
'igw': new cdk.Stack(app, 'aws-cdk-routev2-igw-alpha', {stackName: 'InternetGatewayVpc'}),
'vpgw': new cdk.Stack(app, 'aws-cdk-routev2-virtualprivategw-alpha', {stackName: 'VirtualPrivateGwVpc'}),
'natgw_pub': new cdk.Stack(app, 'aws-cdk-routev2-publicnatgw-alpha', {stackName: 'NatGwPubVpc'}),
'natgw_priv': new cdk.Stack(app, 'aws-cdk-routev2-privatenatgw-alpha', {stackName: 'NatGwPrivVpc'}),
'nif': new cdk.Stack(app, 'aws-cdk-routev2-networkif-alpha', {stackName: 'NetworkInterfaceVpc'}),
'tgw': new cdk.Stack(app, 'aws-cdk-routev2-transitgw-alpha', {stackName: 'TransitGwVpc'}), // failing
// 'tgw': new cdk.Stack(app, 'aws-cdk-routev2-transitgw-alpha', {stackName: 'TransitGwVpc'}),
'vpcpc': new cdk.Stack(app, 'aws-cdk-routev2-vpcpeerconnection-alpha', {stackName: 'VpcPeerConnection'}),
'dynamodb': new cdk.Stack(app, 'aws-cdk-routev2-dynamodbendpoint-alpha', {stackName: 'DynamodbEndpointVpc'}),
};
Expand All @@ -56,7 +57,7 @@ for (const stackName in stacks) {
if (stackName == 'eigw') {
const subnet = new SubnetV2(stacks[stackName], stackName + 'Subnet', {
vpc: vpc,
availabilityZone: 'us-east-1a',
availabilityZone: 'us-west-1a',
cidrBlock: new Ipv4Cidr('10.0.0.0/24'),
subnetType: SubnetType.PRIVATE_WITH_EGRESS,
routeTable: routeTables[stackName],
Expand All @@ -66,7 +67,7 @@ for (const stackName in stacks) {
// use empty ipv6 that doesn't overlap
const subnet = new SubnetV2(stacks[stackName], stackName + 'Subnet', {
vpc: vpc,
availabilityZone: 'us-east-1a',
availabilityZone: 'us-west-1a',
cidrBlock: new Ipv4Cidr('10.0.0.0/24'),
ipv6CidrBlock: new Ipv6Cidr(Fn.select(0, vpc.ipv6CidrBlocks)),
subnetType: SubnetType.PRIVATE_WITH_EGRESS,
Expand All @@ -80,14 +81,14 @@ const user2Vpc = new vpc_v2.VpcV2(stacks.vpcpc, 'vpcpc-user2', {
primaryAddressBlock: vpc_v2.IpAddresses.ipv4('10.128.0.0/16'),
});

const carrierGw = new CarrierGateway(stacks.cgw, 'testCGW', {
vpcId: vpcs.cgw.vpcId,
});
new Route(stacks.cgw, 'testCGWRoute', {
routeTable: routeTables.cgw,
destination: vpc_v2.IpAddresses.ipv4('0.0.0.0/0'),
target: carrierGw,
});
// const carrierGw = new CarrierGateway(stacks.cgw, 'testCGW', {
// vpcId: vpcs.cgw.vpcId,
// });
// new Route(stacks.cgw, 'testCGWRoute', {
// routeTable: routeTables.cgw,
// destination: vpc_v2.IpAddresses.ipv4('0.0.0.0/0'),
// target: carrierGw,
// });

const eigw = new EgressOnlyInternetGateway(stacks.eigw, 'testEOIGW', {
vpcId: vpcs.eigw.vpcId,
Expand Down Expand Up @@ -159,12 +160,12 @@ new Route(stacks.nif, 'testNetIntRoute', {
target: networkInterface,
});

const transitGw = new TransitGateway(stacks.tgw, 'testTGW');
new Route(stacks.tgw, 'testTransitGWRoute', {
routeTable: routeTables.tgw,
destination: vpc_v2.IpAddresses.ipv4('0.0.0.0/0'),
target: transitGw,
});
// const transitGw = new TransitGateway(stacks.tgw, 'testTGW');
// new Route(stacks.tgw, 'testTransitGWRoute', {
// routeTable: routeTables.tgw,
// destination: vpc_v2.IpAddresses.ipv4('0.0.0.0/0'),
// target: transitGw,
// });

const vpcPeerConn = new VpcPeeringConnection(stacks.vpcpc, 'testVPCPC', {
vpcId: vpcs.vpcpc.vpcId,
Expand Down
41 changes: 41 additions & 0 deletions packages/@aws-cdk/aws-vpcv2-alpha/test/route.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -657,4 +657,45 @@ describe('EC2 Routing', () => {
});
});

test('Route to network interface', () => {
const nif = new route.NetworkInterface(stack, 'TestNIF', {
subnet: mySubnet,
});
new route.Route(stack, 'TestRoute', {
routeTable: routeTable,
destination: vpc.IpAddresses.ipv4('0.0.0.0/0'),
target: nif,
});
Template.fromStack(stack).templateMatches({
Resources: {
// Network interface should be in stack
TestNIFNetworkInterface7A9E3A76: {
Type: 'AWS::EC2::NetworkInterface',
Properties: {
SubnetId: {
Ref: 'TestSubnet2A4BE4CA',
},
},
},
// Route linking IP to IGW should be in stack
TestRoute4CB59404: {
Type: 'AWS::EC2::Route',
Properties: {
DestinationCidrBlock: '0.0.0.0/0',
NetworkInterfaceId: {
'Fn::GetAtt': [
'TestNIFNetworkInterface7A9E3A76', 'Id',
],
},
RouteTableId: {
'Fn::GetAtt': [
'TestRouteTableC34C2E1C', 'RouteTableId',
],
},
},
},
},
});
});

});

0 comments on commit bad7ffc

Please sign in to comment.