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(vpc): allow Vpc.fromLookup() to discover asymmetric subnets #4544

Merged
merged 2 commits into from
Oct 29, 2019

Conversation

skinny85
Copy link
Contributor

Previously, Vpc.fromLookup() required every subnet group to be in the same Availability Zones,
and for all subnets in all groups to cover all of those Availability Zones.
This loosens this requirement, so that now Vpc.fromLookup() works for VPCs of all shapes.

This also add a way to customize which tag of the subnet is considered when grouping subnets into groups when calling fromLookup().

Fixes #3407


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

@mergify
Copy link
Contributor

mergify bot commented Oct 17, 2019

Thanks so much for taking the time to contribute to the AWS CDK ❤️

We will shortly assign someone to review this pull request and help get it
merged. In the meantime, please take a minute to make sure you follow this
checklist
:

  • PR title type(scope): text
    • type: fix, feat, refactor go into CHANGELOG, chore is hidden
    • scope: name of module without aws- or cdk- prefix or postfix (e.g. s3 instead of aws-s3-deployment)
    • text: use all lower-case, do not end with a period, do not include issue refs
  • PR Description
    • Rationale: describe rationale of change and approach taken
    • Issues: indicate issues fixed via: fixes #xxx or closes #xxx
    • Breaking?: last paragraph: BREAKING CHANGE: <describe what changed + link for details>
  • Testing
    • Unit test added. Prefer to add a new test rather than modify existing tests
    • CLI or init templates change? Re-run/add CLI integration tests
  • Documentation
    • README: update module README to describe new features
    • API docs: public APIs must be documented. Copy from official AWS docs when possible
    • Design: for significant features, follow design process

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

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

@SomayaB SomayaB added the contribution/core This is a PR that came from AWS. label Oct 17, 2019
Copy link
Contributor

@rix0rrr rix0rrr left a comment

Choose a reason for hiding this comment

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

Sweet, thanks Adam!

tools/cdk-integ-tools/lib/integ-helpers.ts Outdated Show resolved Hide resolved
packages/@aws-cdk/aws-ec2/lib/vpc-lookup.ts Outdated Show resolved Hide resolved
@@ -1,4 +1,4 @@
export const VPC_PROVIDER = 'vpc-provider';
export const VPC_PROVIDER = 'vpc-provider2';
Copy link
Contributor

Choose a reason for hiding this comment

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

This seems dangerous. It means the CLI cannot possibly recognize both vpc-provider1 and vpc-provider2 requests at the same time, which means the CLI breaks backwards compatibility with old CX-api versions.

How do we make sure that the new CLI will still handle old frameworks?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Damn, you're right. That means we have to have a new provider, just for this case.

Will change.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Here's an interesting question.

We will have 2 very similar providers: the "old" VPC one, and the "new" VPC one that accepts asymmetric subnets. Their code will be quite similar. Should I:

a) have the new provider be completely separate from the old one - they should not share any code (as the old one is there only for backwards compatibility reasons); or

b) should I refactor the old one to have an abstract class, and then have both the old one and the new one inherit from this abstract class, to reduce code duplication?

@rix0rrr what do you think?

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe even have a single class and have them do something else based on the input format? Instead of adding a new provider you could also add a version number in the request.

But yes, otherwise let's share code. Maybe the V1 uses the V2, and applies additional restrictions on the output afterwards?

Also, we're going to need to bump the CX version number to tell people that they need to upgrade their CLI to use the new VPC provider (don't forget to add a "version upgrade" code path, which again can do nothing except push up the CX version number one).

Copy link
Contributor Author

@skinny85 skinny85 Oct 24, 2019

Choose a reason for hiding this comment

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

Maybe even have a single class and have them do something else based on the input format? Instead of adding a new provider you could also add a version number in the request.

I like this idea. That's what I did in the newest version. There's a new optional property for the request, returnAsymmetricSubnets, which Vpc.fromLookup() now uses, and it triggers the new behavior in the (existing) VPC provider.

Also, we're going to need to bump the CX version number to tell people that they need to upgrade their CLI to use the new VPC provider (don't forget to add a "version upgrade" code path, which again can do nothing except push up the CX version number one).

Can you expand what needs to be done here? I don't think I understood your comment fully. Is it just changing this to 1.15.0, or is there something else to be done here?

Copy link
Contributor

Choose a reason for hiding this comment

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

// (good), but UNLESS YOU ALSO IMPLEMENT 'upgradeAssemblyManifest' you will also

Copy link
Contributor Author

Choose a reason for hiding this comment

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

packages/aws-cdk/lib/context-providers/vpcs.ts Outdated Show resolved Hide resolved
@skinny85 skinny85 added the pr/do-not-merge This PR should not be merged at this time. label Oct 21, 2019
rix0rrr added a commit that referenced this pull request Oct 22, 2019
Make sure that the CLI will continue to be able to load old cloud
assemblies. We do this by using the CLI feature that it can directly
load Cloud Assemblies through its `--app` argument, hard copying
a couple of cloud assemblies into the test set and trying to synth
those.

In addition to adding a test for loading v0.36.0 assemblies, also
add tests for 2 common context provider requests (AZs and VPC),
to make sure new CLIs will continue to be able to handle these
context lookup requests.

Fixes #4475, pre-emptively adds a regression test for #4544.
@skinny85 skinny85 force-pushed the fix/vpc-import-issues branch from 29a6125 to 4742344 Compare October 22, 2019 17:28
@skinny85
Copy link
Contributor Author

Updated with comments. As to the question in #4544 (comment) , for this iteration, I kept the two providers completely separate, not sharing any code.

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

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

@rix0rrr
Copy link
Contributor

rix0rrr commented Oct 23, 2019

jd-carroll is adding CIDR lookup to the VPC provider here: #4591.

Heads up that depending on which PR lands first, the other one will need to be updated to integrate this change into both VPC providers.

@skinny85 skinny85 force-pushed the fix/vpc-import-issues branch from 4742344 to bf7ca5d Compare October 24, 2019 01:04
@skinny85
Copy link
Contributor Author

Updated with the latest comments.

jd-carroll is adding CIDR lookup to the VPC provider here: #4591.

Heads up that depending on which PR lands first, the other one will need to be updated to integrate this change into both VPC providers.

It should be fine. I looked at #4591, and it looks to me like the merge will be relatively straightforward. Feel free to merge that when it's ready, and I'll deal with resolving the conflicts with this PR.

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

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

@jd-carroll
Copy link
Contributor

@skinny85 @rix0rrr - I question how much of my code in #4591 will actually land (the general purpose of my PR has been debunk'd).

However, there may be some useful pieces related to #2232. Happy to amend my PR to include only changes related to that or happy to have the changes consumed by this PR. Whatever folks think is best!

@skinny85
Copy link
Contributor Author

@rix0rrr can you re-review please? Thanks!

mergify bot pushed a commit that referenced this pull request Oct 25, 2019
* fix(cli): add Cloud Assembly backwards compat tests

Make sure that the CLI will continue to be able to load old cloud
assemblies. We do this by using the CLI feature that it can directly
load Cloud Assemblies through its `--app` argument, hard copying
a couple of cloud assemblies into the test set and trying to synth
those.

In addition to adding a test for loading v0.36.0 assemblies, also
add tests for 2 common context provider requests (AZs and VPC),
to make sure new CLIs will continue to be able to handle these
context lookup requests.

Fixes #4475, pre-emptively adds a regression test for #4544.

* Address review comments
@skinny85 skinny85 force-pushed the fix/vpc-import-issues branch from bf7ca5d to 0d5c5c1 Compare October 28, 2019 18:42
@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • Result: FAILED
  • Build Logs (available for 30 days)

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

@skinny85
Copy link
Contributor Author

Added the toolkit versioning part.

Previously, Vpc.fromLookup() required every subnet group to be in the same Availability Zones,
and for all subnets in all groups to cover all of those Availability Zones.
This loosens this requirement, so that now Vpc.fromLookup() works for VPCs of all shapes.

This also add a way to customize which tag of the subnet is considered when grouping subnets into groups when calling fromLookup().

Fixes aws#3407
@skinny85 skinny85 force-pushed the fix/vpc-import-issues branch from 0d5c5c1 to 97b47bf Compare October 28, 2019 19:59
@skinny85
Copy link
Contributor Author

Fixed missing docs.

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

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

@@ -64,6 +64,11 @@ export function upgradeAssemblyManifest(manifest: AssemblyManifest): AssemblyMan
manifest = justUpgradeVersion(manifest, '1.10.0');
}

if (manifest.version === '1.10.0') {
Copy link
Contributor

Choose a reason for hiding this comment

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

Thank you for getting where I was going with this!

(Now that we've done it twice it will be a tradition ;) )

@skinny85 skinny85 removed the pr/do-not-merge This PR should not be merged at this time. label Oct 29, 2019
@mergify
Copy link
Contributor

mergify bot commented Oct 29, 2019

Thank you for contributing! Your pull request is now being automatically merged.

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

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

@mergify mergify bot merged commit 2ccb745 into aws:master Oct 29, 2019
@skinny85 skinny85 deleted the fix/vpc-import-issues branch October 29, 2019 22:32
@gsdwait
Copy link

gsdwait commented Nov 7, 2019

Any projections on when this might be included in a release. The vpc import restriction is preventing us from using CDK in our dev and production environments. I'll have to rebuild some code as CloudFormation if this isn't released soon. We're really excited about the CDK but for now this is a show stopper for us.

@jk21
Copy link

jk21 commented Nov 8, 2019

also looking forward for this!

@ranman
Copy link

ranman commented Nov 17, 2019

+1 also looking forward to this!

@jk21
Copy link

jk21 commented Nov 17, 2019

@ranman it is already in the new version! Works nice 👍

@ranman
Copy link

ranman commented Nov 17, 2019 via email

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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

VPC fromLookup fails with asymmetric subnets
8 participants