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): network interface definitions for launch templates #29875

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

Conversation

pasiorovuo
Copy link

@pasiorovuo pasiorovuo commented Apr 17, 2024

This PR implements basic functionality for defining network interfaces as part of Launch Template.

Issue # (if applicable)

Fixes #14494

Reason for this change

Current Launch Template L2 is missing the ability to define multiple interfaces, their subnets etc. This functionality is required in advanced scenarios where instances need multiple public IP addresses or need to be multi-homed etc.

Description of changes

Multiple new types have been introduced in packages/aws-cdk-lib/aws-ec2/lib/launch-template.ts. Many of them are just renamed extends of the ec2-generated types. This made sense as the Cloudformation type definition is suitable, but I'm a bit uncertain if this violates the design requirement Do not “leak” the details or types of the CFN layer when defining your construct API.

Main type is NetworkInterface which defines the attributes for the interfaces. Additional changes are in LaunchTemplate constructor to accommodate the new functionality.

README has been updated to include a simple usage example.

Description of how you validated changes

A single test has been added. I have also verified the implementation by creating stacks in different configurations and deployed them. There too many combinations to check them all, so only a subset has been tested, unfortunately.

Checklist


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

…ations as part of Launch Template definitions
@github-actions github-actions bot added effort/medium Medium work item – several days of effort feature-request A feature should be added or improved. p2 labels Apr 17, 2024
@aws-cdk-automation aws-cdk-automation requested a review from a team April 17, 2024 21:30
@github-actions github-actions bot added the beginning-contributor [Pilot] contributed between 0-2 PRs to the CDK label Apr 17, 2024
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 has failed. See the aws-cdk-automation comment below for failure reasons. 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.

@aws-cdk-automation aws-cdk-automation dismissed their stale review April 18, 2024 05:11

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

@pasiorovuo
Copy link
Author

I do not know what the failing check is about.

@aws-cdk-automation aws-cdk-automation added the pr/needs-community-review This PR needs a review from a Trusted Community Member or Core Team Member. label Apr 18, 2024
@shikha372 shikha372 assigned shikha372 and unassigned shikha372 Apr 22, 2024
@aws-cdk-automation
Copy link
Collaborator

This PR cannot be merged because it has conflicts. Please resolve them. The PR will be considered stale and closed if it remains in an unmergeable state.

@pasiorovuo
Copy link
Author

This seems to be overlapping in parts with #28901. If it would be accepted, I could update this PR to account for the new types etc. introduced by it.

@@ -763,7 +1019,7 @@ export class LaunchTemplate extends Resource implements ILaunchTemplate, iam.IGr
tagSpecifications: tagsToken,
userData: userDataToken,
metadataOptions: this.renderMetadataOptions(props),
networkInterfaces,
networkInterfaces: networkInterfaces ? synthesizeNetworkInterfaces(networkInterfaces) : undefined,

Choose a reason for hiding this comment

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

I think that if networkInterfaces is defined, we should not be providing anything in securityGroupIds. Since the options provided in securityGroupsToken are not used at all unless props.networkInterfaces is undefined and props.associatePublicIpAddress is defined

On line securityGroupIds: networkInterfaces ? undefined : securityGroupsToken, right above

Choose a reason for hiding this comment

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

Would it be possible to also have unit tests in

that have cases for when different network interface options are provided and also a verification that when props.associatePublicIpAddress is incompatible with props.networkInterfaces, the correct error is thrown?

/**
* One or more private IPv4 addresses.
*
* @default A random IP address is assigned from one of the subnets.

Choose a reason for hiding this comment

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

I was never able to figure out how these defaults are resolved since the AWS documentation doesn't have any info
https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-ec2-launchtemplate-privateipadd.html

PrivateIpAddresses

    One or more private IPv4 addresses.

    Required: No

    Type: Array of [PrivateIpAdd](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-ec2-launchtemplate-privateipadd.html)

    Update requires: [No interruption](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/using-cfn-updating-stacks-update-behaviors.html#update-no-interrupt)

@chenhe95
Copy link

chenhe95 commented Jul 24, 2024

Hi Pasi. Thanks for looking into this! I actually had the exact same issue #30891 as the one you're trying to solve. Your PR looks very similar to my local prototype with the differences being in how security group IDs are handled and how the unit tests are done. I was also not sure how AWS determines default behaviors when input fields are left undefined. Left comments on those parts.

Nice work!

@chenhe95
Copy link

chenhe95 commented Sep 4, 2024

Hi Pasi! I am wondering if this ticket is still being worked on, since I am very invested in getting launch templates to be more configurable
Thank you for all the work so far!

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildv2Project1C6BFA3F-wQm2hXv2jqQv
  • Commit ID: 75af4a2
  • Result: SUCCEEDED
  • 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
beginning-contributor [Pilot] contributed between 0-2 PRs to the CDK effort/medium Medium work item – several days of effort feature-request A feature should be added or improved. p2 pr/needs-community-review This PR needs a review from a Trusted Community Member or Core Team Member.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

EC2 Launch Template: Vpc Subnets support
6 participants