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
fix(ec2): Vpc.fromVpcAttributes cannot be used with EKS #12569
Conversation
This PR has a fix similar to #12040, and introduces more explanations and safeguards around the mechanism of importing a VPC using `fromVpcAttributes()`. This is not the recommended way of importing VPCs, but many users really don't want to use lookups so we'd better make it a little safer. This PR contains: * A fix in the EKS library to have it stop logging subnet IDs to metadata if it looks like the subnet ID will lead to the aforementioned synthesis error (similar to the fix in the linked PR). * A validation in the EKS library to stop a similar-but-different error from occurring if people select multiple VPC subnet groups from a VPC imported from token lists; this can never work and we might as well tell them directly. * A metadata warning added to VPCs imported using `Vpc.fromVpcAttributes()`, to inform users that their VPC imported in this way has a good chance of not working in all cases they expect it to. * A mechanism to specify the length of deploy-time lists at synthesis time, by passing an `assumedLength` parameter to `Fn.split()`. This will produce a list that is safe for manipulation. * A note on how to use `Vpc.fromVpcAttributes()` in the `ec2` README. Fixes #12160.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@iliapolo can you take a look?
@@ -961,8 +961,13 @@ export class Cluster extends ClusterBase { | |||
|
|||
this.vpcSubnets = props.vpcSubnets ?? [{ subnetType: ec2.SubnetType.PUBLIC }, { subnetType: ec2.SubnetType.PRIVATE }]; | |||
|
|||
const selectedSubnetIds = this.vpcSubnets.map(s => this.vpc.selectSubnets(s).subnetIds); | |||
if (selectedSubnetIds.some(Token.isUnresolved) && selectedSubnetIds.length > 1) { | |||
throw new Error('eks.Cluster: cannot select multiple subnet groups from a VPC imported from list tokens with unknown length. Select only one subnet group, pass a length to Fn.split, or switch to Vpc.fromLookup.'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe refer to the docs for an example?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added do-not-merge
to let you address the minor comments
@@ -961,8 +961,13 @@ export class Cluster extends ClusterBase { | |||
|
|||
this.vpcSubnets = props.vpcSubnets ?? [{ subnetType: ec2.SubnetType.PUBLIC }, { subnetType: ec2.SubnetType.PRIVATE }]; | |||
|
|||
const selectedSubnetIds = this.vpcSubnets.map(s => this.vpc.selectSubnets(s).subnetIds); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const selectedSubnetIds = this.vpcSubnets.map(s => this.vpc.selectSubnets(s).subnetIds); | |
const selectedSubnetIdsPerGroup = this.vpcSubnets.map(s => this.vpc.selectSubnets(s).subnetIds); |
Or something, the current name makes it sound like these are individual subnets.
Thank you for contributing! Your pull request will be updated from master and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork). |
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
Thank you for contributing! Your pull request will be updated from master and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork). |
This PR has a fix similar to aws#12040, and introduces more explanations and safeguards around the mechanism of importing a VPC using `fromVpcAttributes()`. This is not the recommended way of importing VPCs, but many users really don't want to use lookups so we'd better make it a little safer. This PR contains: * A fix in the EKS library to have it stop logging subnet IDs to metadata if it looks like the subnet ID will lead to the aforementioned synthesis error (similar to the fix in the linked PR). * A validation in the EKS library to stop a similar-but-different error from occurring if people select multiple VPC subnet groups from a VPC imported from token lists; this can never work and we might as well tell them directly. * A metadata warning added to VPCs imported using `Vpc.fromVpcAttributes()`, to inform users that their VPC imported in this way has a good chance of not working in all cases they expect it to. * A mechanism to specify the length of deploy-time lists at synthesis time, by passing an `assumedLength` parameter to `Fn.split()`. This will produce a list that is safe for manipulation, and removes the limitations addressed by the previous bullets. * A note on how to use `Vpc.fromVpcAttributes()` in the `ec2` README. Fixes aws#12160. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
This PR has a fix similar to #12040, and introduces more explanations
and safeguards around the mechanism of importing a VPC using
fromVpcAttributes()
. This is not the recommended way of importingVPCs, but many users really don't want to use lookups so we'd better
make it a little safer.
This PR contains:
metadata if it looks like the subnet ID will lead to the
aforementioned synthesis error (similar to the fix in the linked
PR).
error from occurring if people select multiple VPC subnet groups
from a VPC imported from token lists; this can never work and we
might as well tell them directly.
Vpc.fromVpcAttributes()
, to inform users that their VPC importedin this way has a good chance of not working in all cases they
expect it to.
time, by passing an
assumedLength
parameter toFn.split()
. Thiswill produce a list that is safe for manipulation, and removes the limitations
addressed by the previous bullets.
Vpc.fromVpcAttributes()
in theec2
README.Fixes #12160.
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license