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

fix(ec2): Vpc.fromVpcAttributes cannot be used with EKS #12569

Merged
merged 4 commits into from Jan 19, 2021

Conversation

rix0rrr
Copy link
Contributor

@rix0rrr rix0rrr commented Jan 18, 2021

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, and removes the limitations
    addressed by the previous bullets.
  • A note on how to use Vpc.fromVpcAttributes() in the ec2 README.

Fixes #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 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.
@rix0rrr rix0rrr requested a review from a team January 18, 2021 12:20
@rix0rrr rix0rrr self-assigned this Jan 18, 2021
@gitpod-io
Copy link

gitpod-io bot commented Jan 18, 2021

@github-actions github-actions bot added the @aws-cdk/aws-ec2 Related to Amazon Elastic Compute Cloud label Jan 18, 2021
@mergify mergify bot added the contribution/core This is a PR that came from AWS. label Jan 18, 2021
Copy link
Contributor

@eladb eladb left a 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.');
Copy link
Contributor

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?

@iliapolo iliapolo added the pr/do-not-merge This PR should not be merged at this time. label Jan 18, 2021
Copy link
Contributor

@iliapolo iliapolo left a 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);
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
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.

@rix0rrr rix0rrr removed the pr/do-not-merge This PR should not be merged at this time. label Jan 19, 2021
@mergify
Copy link
Contributor

mergify bot commented Jan 19, 2021

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-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildProject6AEA49D1-qxepHUsryhcu
  • Commit ID: 37e50b9
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

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

@mergify
Copy link
Contributor

mergify bot commented Jan 19, 2021

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).

@mergify mergify bot merged commit 1cdc244 into master Jan 19, 2021
@mergify mergify bot deleted the huijbers/eks-import-cluster branch January 19, 2021 09:07
mohanrajendran pushed a commit to mohanrajendran/aws-cdk that referenced this pull request Jan 24, 2021
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*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-ec2 Related to Amazon Elastic Compute Cloud contribution/core This is a PR that came from AWS.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cannot find right method to import existing vpc with ec2.Vpc.fromLookup or ec2.Vpc.fromVpcAttributes
5 participants