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

Open
wants to merge 15 commits into
base: main
Choose a base branch
from

Conversation

paulhcsun
Copy link
Contributor

Issue # (if applicable)

Closes #.

Reason for this change

Description of changes

Describe any new or updated permissions being added

Description of how you validated changes

Checklist


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

@github-actions github-actions bot added the p2 label Jan 15, 2025
@aws-cdk-automation aws-cdk-automation requested a review from a team January 15, 2025 21:38
@mergify mergify bot added the contribution/core This is a PR that came from AWS. label Jan 15, 2025
Copy link
Collaborator

@aws-cdk-automation aws-cdk-automation left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The pull request linter fails with the following errors:

❌ Features must contain a change to a README file.

If you believe this pull request should receive an exemption, please comment and provide a justification. A comment requesting an exemption should contain the text Exemption Request. Additionally, if clarification is needed, add Clarification Request to a comment.

Copy link

codecov bot commented Jan 15, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 80.79%. Comparing base (2eff2bd) to head (39e8ae9).

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #32956   +/-   ##
=======================================
  Coverage   80.79%   80.79%           
=======================================
  Files         232      232           
  Lines       14110    14110           
  Branches     2453     2453           
=======================================
  Hits        11400    11400           
  Misses       2430     2430           
  Partials      280      280           
Flag Coverage Δ
suite.unit 80.79% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
packages/aws-cdk 79.53% <ø> (ø)
packages/aws-cdk-lib/core 82.17% <ø> (ø)

@paulhcsun paulhcsun changed the title feat(ec2-alpha): Transit Gateway L2 feat(ec2-alpha): add Transit Gateway L2 Jan 22, 2025
@aws-cdk-automation aws-cdk-automation dismissed their stale review January 23, 2025 01:35

✅ Updated pull request passes all PRLinter validations. Dismissing previous PRLinter review.

@paulhcsun paulhcsun marked this pull request as ready for review January 23, 2025 23:08
Copy link
Contributor

@GavinZZ GavinZZ left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work! Left some comments to help me understand.


> Note: When you create a default Transit Gateway in AWS Console, EC2 creates the default `TransitGatewayRouteTable` for you. When using this construct, CDK will create the default `TransitGatewayRouteTable` for you instead with the automatic Association/Propagation features being mimicked by the CDK.
>
> **Default association route table** and **Default propagation route table** will show as disabled in your AWS console but can still be toggled within CDK using the `defaultRouteTableAssociation` and `defaultRouteTablePropagation` properties respectively.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Want to clarify this sentence a bit. So CDK will by default create TGRT but on console it shows disabled meaning console saying no default TGRT is created?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When both defaultRouteTableAssociation and defaultRouteTablePropagation are disabled in the CFN template, EC2 will not create the default route table. Instead, the CDK will always create a default route table in place of EC2.

The Default association route table and Default propagation route table settings are shown on every TGRT and it will show as disabled in AWS console for the CDK created default route table (because it can only be enabled on the EC2 created default route table), but we still provide properties within CDK, defaultRouteTableAssociation and defaultRouteTablePropagation, to allow customers to enable the setting (we mimic it being enabled with CDK implementation) even though it shows disabled in console.

>
> **Default association route table** and **Default propagation route table** will show as disabled in your AWS console but can still be toggled within CDK using the `defaultRouteTableAssociation` and `defaultRouteTablePropagation` properties respectively.

You can disable the automatic Association/Propagation on the default `TransitGatewayRouteTable` via the `TransitGateway` properties. This will still create a default route table for you:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wonder what's the behaviour when we supply a custom default route table but enable default route table association and default route table propagation?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You actually cannot supply a custom route table, because to create a route table you need to pass in a Transit Gateway, so you wouldn't just have a random extra route table lying around.

If you want to automatically associate and propagate routes with transit gateway route tables, you can pass the `associationRouteTable` and `propagationRouteTables` parameters. This will automatically create the necessary associations and propagations based on the provided route tables.

```ts
const attachmentWithRoutes = transitGateway.attachVpc('VpcAttachment', vpc, [subnet], undefined, associationRouteTable, [propagationRouteTable1, propagationRouteTable2]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feel like a lot of parmeters to me. Can we put them into a Options interface instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, I don't like having to skip over the optional parameters either. I'll see if there's a clean way to set up the interfaces with a base interface so it's not a duplicate of the ITransitGatewayVpcAttachment interface.

readonly transitGatewayVpcAttachmentId: string;
}

export abstract class TransitGatewayAttachmentBase extends Resource implements ITransitGatewayAttachment {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this abstract class needed? Do you foresee that we will add more subclasses in the future?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, there will be different types of TransitGatewayAttachments such as an attachment to connect one TGW to another, VPN Attachments, Connect Attachments.

/**
* The VPC attachment options.
*/
readonly transitGatewayVpcAttachmentOptions?: ITransitGatewayVpcAttachmentOptions;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
readonly transitGatewayVpcAttachmentOptions?: ITransitGatewayVpcAttachmentOptions;
readonly vpcAttachmentOptions?: ITransitGatewayVpcAttachmentOptions;

This is in transitGateway file already, I think we can omit the prefix.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, this should be fine to omit the prefix.

Comment on lines 107 to 111
id: string, vpc: IVpc,
subnets: ISubnet[],
transitGatewayAttachmentOptions?: ITransitGatewayVpcAttachmentOptions,
associationRouteTable?: ITransitGatewayRouteTable,
propagationRouteTables?: ITransitGatewayRouteTable[],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO, everything after id can be put in an XXXOptions interface. wdyt?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. Will look into a clean solution for this.

Comment on lines 160 to 171
autoAcceptSharedAttachments: (props?.autoAcceptSharedAttachments ?? false)
? TransitGatewayFeatureStatus.ENABLE : TransitGatewayFeatureStatus.DISABLE,
// Default Association/Propagation will always be false when creating the L1 to prevent EC2 from creating the default route table.
// Instead, CDK will create a custom default route table and use the properties to mimic the automatic assocation/propagation behaviour.
defaultRouteTableAssociation: (props?.defaultRouteTableAssociation ?? false)
? TransitGatewayFeatureStatus.ENABLE : TransitGatewayFeatureStatus.DISABLE,
defaultRouteTablePropagation: (props?.defaultRouteTablePropagation ?? false)
? TransitGatewayFeatureStatus.ENABLE : TransitGatewayFeatureStatus.DISABLE,
description: props?.description,
dnsSupport: (props?.dnsSupport ?? true) ? TransitGatewayFeatureStatus.ENABLE : TransitGatewayFeatureStatus.DISABLE,
multicastSupport: (props?.multicastSupport ?? false) ? TransitGatewayFeatureStatus.ENABLE : TransitGatewayFeatureStatus.DISABLE,
vpnEcmpSupport: (props?.vpnEcmpSupport ?? true) ? TransitGatewayFeatureStatus.ENABLE : TransitGatewayFeatureStatus.DISABLE,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above comment, take out the common functionality.

public abstract destinationCidrBlock: string;
}

export class TransitGatewayActiveRoute extends TransitGatewayRouteBase {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
export class TransitGatewayActiveRoute extends TransitGatewayRouteBase {
export class TransitGatewayRoute extends TransitGatewayRouteBase {

IMO Route is more commonly used, wdyt?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I named it ActiveRoute to distinguish that it is different from the BlackholeRoute but I think just naming it TransitGatewayRoute also works since the method name is called addRoute() and addBlackholeRoute().

Comment on lines 29 to 51
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, {
transitGatewayVpcAttachment: transitGatewayAttachment,
transitGatewayRouteTable: this,
});
}

enablePropagation(id: string, transitGatewayAttachment: ITransitGatewayAttachment): TransitGatewayRouteTablePropagation {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this functionality be exposed ITransitGatewayRouteTable? i.e. I see that imported TGRT is not supported yet, but when it is supported, should the imported TGRT have the capability of adding routes/ adding balckhole routes/etc?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is okay to leave for now. When we do support imported route tables then we can move the declarations for these methods into the interface which will not be a breaking change.

const customRouteTable = new ec2.TransitGatewayRouteTable(this, 'TransitGatewayRouteTable');

const transitGateway = new ec2.TransitGateway(this, 'MyTransitGateway', {
customDefaultRouteTable: customRouteTable,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see this option customDefaultRouteTable?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right, similar to the above, I realized it's not possible to create a TGW with a custom route table that gets passed in so I've removed the property. Will also remove this example from the README.

Copy link
Collaborator

@aws-cdk-automation aws-cdk-automation left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(This review is outdated)

@aws-cdk-automation aws-cdk-automation dismissed their stale review January 25, 2025 00:27

✅ Updated pull request passes all PRLinter validations. Dismissing previous PRLinter review.

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildv2Project1C6BFA3F-wQm2hXv2jqQv
  • Commit ID: 39e8ae9
  • Result: FAILED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contribution/core This is a PR that came from AWS. p2
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants