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

feat(ec2-alpha): add Transit Gateway L2 #32956

Merged
merged 28 commits into from
Feb 3, 2025
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
50b9d34
WIP feat(ec2-alpha): transit gateway L2
paulhcsun Dec 3, 2024
d2af8a5
skeleton
paulhcsun Jan 9, 2025
a76835c
updated classes
paulhcsun Jan 15, 2025
9c0bf44
remove add/removeSubnetIds property + implement methods
paulhcsun Jan 15, 2025
353ca25
some unit tests + class updates
paulhcsun Jan 22, 2025
5f0c30b
update vpc attachment resource + unit tests
paulhcsun Jan 22, 2025
e123638
README draft
paulhcsun Jan 23, 2025
faf600d
integ snapshots + update attachment options
paulhcsun Jan 23, 2025
3b47333
fix unit test
paulhcsun Jan 23, 2025
c38c8b0
remove unused import
paulhcsun Jan 23, 2025
6bdd545
Merge branch 'main' into vpcv2-transit-gateway
paulhcsun Jan 23, 2025
55f16a3
Merge branch 'main' into vpcv2-transit-gateway
paulhcsun Jan 24, 2025
a5db2e5
remove unused test
paulhcsun Jan 24, 2025
4a53920
pr feedback
paulhcsun Jan 25, 2025
39e8ae9
Merge branch 'main' into vpcv2-transit-gateway
paulhcsun Jan 25, 2025
a00ecc7
add docstrings, update readme, add fromxxx linter exemption
paulhcsun Jan 27, 2025
7c7fbb7
fix unit tests
paulhcsun Jan 28, 2025
596ea55
add warnings when attaching VPC and update tests
paulhcsun Jan 29, 2025
1e87d20
update L1 values to pass undefined instead of CDK default + update tests
paulhcsun Jan 29, 2025
1db4acf
update route table interface + remove tgw L1 unused properties
paulhcsun Jan 30, 2025
418c436
add missing L1 prop
paulhcsun Jan 30, 2025
b0f24b7
add missing l1 prop
paulhcsun Jan 30, 2025
91a0a94
create tgw association interface + remove private _resource prop
paulhcsun Jan 31, 2025
c4d2815
Merge branch 'main' into vpcv2-transit-gateway
paulhcsun Jan 31, 2025
7cf64c8
linting
paulhcsun Jan 31, 2025
4b63235
Merge branch 'main' into vpcv2-transit-gateway
mergify[bot] Jan 31, 2025
f515acc
Merge branch 'main' into vpcv2-transit-gateway
mergify[bot] Feb 1, 2025
e63d92a
remove testing integ test
paulhcsun Feb 3, 2025
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
133 changes: 133 additions & 0 deletions packages/@aws-cdk/aws-ec2-alpha/lib/transit-gateway-attachment.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
import { IResource, Resource } from 'aws-cdk-lib/core';
import { ITransitGateway, TransitGatewayFeatureStatus } from './transit-gateway';
import { CfnTransitGatewayVpcAttachment, ISubnet, IVpc } from 'aws-cdk-lib/aws-ec2';
import { Construct } from 'constructs';
import { TransitGatewayRouteTableAssociation } from './transit-gateway-route-table-association';
import { TransitGatewayRouteTablePropagation } from './transit-gateway-route-table-propagation';

export interface ITransitGatewayAttachment extends IResource {
/**
* The ID of the transit gateway attachment.
* @attribute
*/
readonly transitGatewayAttachmentId: string;
}

export interface ITransitGatewayAttachmentOptions {
/**
* Enable or disable appliance mode support.
*
* @default - disable (false)
*/
readonly applianceModeSupport?: boolean;

/**
* Enable or disable DNS support.
*
* @default - disable (false)
*/
readonly dnsSupport?: boolean;

/**
* Enable or disable IPv6 support.
*
* @default - disable (false)
*/
readonly ipv6Support?: boolean;

/**
* Enables you to reference a security group across VPCs attached to a transit gateway.
*
* @default - disable (false)
*/
readonly securityGroupReferencingSupport?: boolean;
}

export interface TransitGatewayAttachmentProps {
/**
* A list of one or more subnets to place the attachment in.
* It is recommended to specify more subnets for better availability.
*/
readonly subnets: ISubnet[];

// WIP - probably will not expose these properties but will need to set them for the L1 behind the scenes
// /**
// * A list of one or more subnets to add.
// * You can specify at most one subnet per Availability Zone.
// * It is recommended to specify more subnets for better availability.
// */
// readonly addSubnets?: ISubnet[];

// /**
// * A list of one or more subnets to place the attachment in.
// * It is recommended to specify more subnets for better availability.
// */

// readonly removeSubnets?: ISubnet[];
/**
* The transit gateway this attachment gets assigned to.
*/
readonly transitGateway: ITransitGateway;

/**
* A VPC attachment(s) will get assigned to.
*/
readonly vpc: IVpc;

/**
* The VPC attachment options.
*/
readonly transitGatewayAttachmentOptions?: ITransitGatewayAttachmentOptions;
}

abstract class TransitGatewayAttachmentBase extends Resource implements ITransitGatewayAttachment {
public abstract readonly transitGatewayAttachmentId: string;

// addSubnets(subnets: ISubnet[]): void {
// return;
// }

// removeSubnets(subnets: ISubnet[]): void {
// return;
// }
}

export class TransitGatewayVpcAttachment extends TransitGatewayAttachmentBase {
public readonly transitGatewayAttachmentId: string;

constructor(scope: Construct, id: string, props: TransitGatewayAttachmentProps) {
super(scope, id);

const resource = new CfnTransitGatewayVpcAttachment(this, 'TransitGatewayAttachment', {
subnetIds: props.subnets.map((subnet) => subnet.subnetId),
transitGatewayId: props.transitGateway.transitGatewayId,
vpcId: props.vpc.vpcId,
options: props.transitGatewayAttachmentOptions ? {
applianceModeSupport: (props.transitGatewayAttachmentOptions?.applianceModeSupport ?? false)
? TransitGatewayFeatureStatus.ENABLE : TransitGatewayFeatureStatus.DISABLE,
dnsSupport: (props.transitGatewayAttachmentOptions?.dnsSupport ?? false)
? TransitGatewayFeatureStatus.ENABLE : TransitGatewayFeatureStatus.DISABLE,
ipv6Support: (props.transitGatewayAttachmentOptions?.ipv6Support ?? false)
? TransitGatewayFeatureStatus.ENABLE : TransitGatewayFeatureStatus.DISABLE,
securityGroupReferencingSupport: (props.transitGatewayAttachmentOptions?.securityGroupReferencingSupport ?? false)
? TransitGatewayFeatureStatus.ENABLE : TransitGatewayFeatureStatus.DISABLE,
} : undefined,
});

this.transitGatewayAttachmentId = resource.ref;

if (props.transitGateway.defaultRouteTableAssociation) {
new TransitGatewayRouteTableAssociation(this, id, {
transitGatewayAttachment: this,
transitGatewayRouteTable: props.transitGateway.defaultRouteTable,
});
}

if (props.transitGateway.defaultRouteTablePropagation) {
new TransitGatewayRouteTablePropagation(this, id + 'Propagation', {
transitGatewayAttachment: this,
transitGatewayRouteTable: props.transitGateway.defaultRouteTable,
});
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { IResource, Resource } from 'aws-cdk-lib/core';
import { ITransitGatewayAttachment } from './transit-gateway-attachment';
import { ITransitGatewayRouteTable } from './transit-gateway-route-table';
import { CfnTransitGatewayRouteTableAssociation } from 'aws-cdk-lib/aws-ec2';
import { Construct } from 'constructs';

export interface ITransitGatewayRouteTableAssociation extends IResource {
/**
* The ID of the transit gateway route table association.
*/
readonly transitGatewayRouteTableAssociationId: string;
}

export interface TransitGatewayRouteTableAssociationProps {
/**
* The ID of the transit gateway route table association.
*/
readonly transitGatewayAttachment: ITransitGatewayAttachment;

/**
* The ID of the transit gateway route table association.
*/
readonly transitGatewayRouteTable: ITransitGatewayRouteTable;
}

abstract class TransitGatewayRouteTableAssociationBase extends Resource implements ITransitGatewayRouteTableAssociation {
/**
* The ID of the transit gateway route table association.
*/
public abstract readonly transitGatewayRouteTableAssociationId: string;
}

export class TransitGatewayRouteTableAssociation extends TransitGatewayRouteTableAssociationBase {
/**
* The ID of the transit gateway route table association.
*/
public readonly transitGatewayRouteTableAssociationId: string;

constructor(scope: Construct, id: string, props: TransitGatewayRouteTableAssociationProps) {
super(scope, id);

const resource = new CfnTransitGatewayRouteTableAssociation(this, 'TransitGatewayRouteTableAssociation', {
transitGatewayAttachmentId: props.transitGatewayAttachment.transitGatewayAttachmentId,
transitGatewayRouteTableId: props.transitGatewayRouteTable.routeTableId,
});

this.transitGatewayRouteTableAssociationId = resource.ref;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { IResource, Resource } from 'aws-cdk-lib/core';
import { CfnTransitGatewayRouteTablePropagation } from 'aws-cdk-lib/aws-ec2';
import { Construct } from 'constructs';
import { ITransitGatewayAttachment } from './transit-gateway-attachment';
import { ITransitGatewayRouteTable } from './transit-gateway-route-table';

export interface ITransitGatewayRouteTablePropagation extends IResource {
/**
* The ID of the transit gateway route table propagation.
* @attribute
*/
readonly transitGatewayRouteTablePropagationId: string;
}

export interface TransitGatewayRouteTablePropagationProps {
/**
* The ID of the transit gateway route table propagation.
*/
readonly transitGatewayAttachment: ITransitGatewayAttachment;

/**
* The ID of the transit gateway route table propagation.
*/
readonly transitGatewayRouteTable: ITransitGatewayRouteTable;
}

abstract class TransitGatewayRouteTablePropagationBase extends Resource implements ITransitGatewayRouteTablePropagation {
/**
* The ID of the transit gateway route table propagation.
*/
public abstract readonly transitGatewayRouteTablePropagationId: string;
}

export class TransitGatewayRouteTablePropagation extends TransitGatewayRouteTablePropagationBase {
/**
* The ID of the transit gateway route table propagation.
*/
public readonly transitGatewayRouteTablePropagationId: string;

constructor(scope: Construct, id: string, props: TransitGatewayRouteTablePropagationProps) {
super(scope, id);

const resource = new CfnTransitGatewayRouteTablePropagation(this, 'TransitGatewayRouteTablePropagation', {
transitGatewayAttachmentId: props.transitGatewayAttachment.transitGatewayAttachmentId,
transitGatewayRouteTableId: props.transitGatewayRouteTable.routeTableId,
});

this.transitGatewayRouteTablePropagationId = resource.ref;
}
}
78 changes: 78 additions & 0 deletions packages/@aws-cdk/aws-ec2-alpha/lib/transit-gateway-route-table.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import { IResource, Resource } from 'aws-cdk-lib/core';
import { ITransitGateway } from './transit-gateway';
import { Construct } from 'constructs';
import { CfnTransitGatewayRouteTable, IRouteTable } from 'aws-cdk-lib/aws-ec2';
import { ITransitGatewayAttachment } from './transit-gateway-attachment';
import { TransitGatewayActiveRoute, TransitGatewayBlackholeRoute } from './transit-gateway-route';
import { TransitGatewayRouteTableAssociation } from './transit-gateway-route-table-association';
import { TransitGatewayRouteTablePropagation } from './transit-gateway-route-table-propagation';

export interface ITransitGatewayRouteTable extends IResource {
/**
* The ID of the transit gateway route table
* @attribute
*/
readonly routeTableId: string;
}

export interface TransitGatewayRouteTableProps {
/**
* The ID of the transit gateway
*/
readonly transitGateway: ITransitGateway;
}

abstract class TransitGatewayRouteTableBase extends Resource implements ITransitGatewayRouteTable, IRouteTable {
public abstract readonly routeTableId: string;
public abstract readonly transitGateway: ITransitGateway;

addRoute(id: string, transitGatewayAttachment: ITransitGatewayAttachment, destinationCidr: string): TransitGatewayActiveRoute {
return new TransitGatewayActiveRoute(this, id, {
transitGatewayRouteTable: this,
transitGatewayAttachment,
destinationCidrBlock: destinationCidr,
});
};

addBlackholeRoute(id: string, destinationCidr: string): TransitGatewayBlackholeRoute {
return new TransitGatewayBlackholeRoute(this, id, {
transitGatewayRouteTable: this,
destinationCidrBlock: destinationCidr,
});
}

addAssociation(id: string, transitGatewayAttachment: ITransitGatewayAttachment): TransitGatewayRouteTableAssociation {
return new TransitGatewayRouteTableAssociation(this, id, {
transitGatewayAttachment: transitGatewayAttachment,
transitGatewayRouteTable: this,
});
}

enablePropagation(id: string, transitGatewayAttachment: ITransitGatewayAttachment): TransitGatewayRouteTablePropagation {
return new TransitGatewayRouteTablePropagation(this, id, {
transitGatewayAttachment: transitGatewayAttachment,
transitGatewayRouteTable: this,
});
}
}

/**
* An AWS Transit Gateway route table
*
* @resource AWS::EC2::TransitGatewayRouteTable
*/
export class TransitGatewayRouteTable extends TransitGatewayRouteTableBase {
public readonly routeTableId: string;
public readonly transitGateway: ITransitGateway;

constructor(scope: Construct, id: string, props: TransitGatewayRouteTableProps) {
super(scope, id);

const resource = new CfnTransitGatewayRouteTable(this, id, {
transitGatewayId: props.transitGateway.transitGatewayId,
});

this.routeTableId = resource.ref;
this.transitGateway = props.transitGateway;
}
}
Loading
Loading