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): additional validation around Subnet Types #4668

Merged
merged 3 commits into from
Oct 27, 2019

Conversation

rix0rrr
Copy link
Contributor

@rix0rrr rix0rrr commented Oct 24, 2019

Try to improve the usability around VPCs and certain Subnet Type
configurations.

  • Make clear that ISOLATED does not mean "no Internet access at all",
    just no Internet access from the point of view of the current VPC.

  • If people configure natGateways=0, tell them that they probably meant
    to configure no PRIVATE subnets.

  • If people DO configure PRIVATE subnets, make sure they also configure
    PUBLIC subnets, otherwise we won't be able to place the NAT gateways
    anywhere useful.

  • If people end up with a VPC without PRIVATE subnets, the default
    behavior of selectSubnets is pretty useless, because it can never
    work, and that's not what people are used to from the CDK. Dynamically
    adjust the selection default to whatever subnet types are available.

Fixes #3704.


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

Try to improve the usability around VPCs and certain Subnet Type
configurations.

- Make clear that ISOLATED does not mean "no Internet access at all",
  just no Internet access from the point of view of the current VPC.

- If people configure natGateways=0, tell them that they probably meant
  to configure no PRIVATE subnets.

- If people DO configure PRIVATE subnets, make sure they also configure
  PUBLIC subnets, otherwise we won't be able to place the NAT gateways
  anywhere useful.

- If people end up with a VPC without PRIVATE subnets, the default
  behavior of `selectSubnets` is pretty useless, because it can never
  work, and that's not what people are used to from the CDK. Dynamically
  adjust the selection default to whatever subnet types *are* available.

Fixes #3704.
@rix0rrr rix0rrr self-assigned this Oct 24, 2019
@mergify
Copy link
Contributor

mergify bot commented Oct 24, 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 24, 2019
@@ -166,7 +165,7 @@ export interface SubnetSelection {
*
* At most one of `subnetType` and `subnetGroupName` can be supplied.
*
* @default SubnetType.PRIVATE
* @default SubnetType.PRIVATE (or ISOLATED or PUBLIC if there are no PRIVATE subnets)
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure this description of @default is super clear... ISOLATED or PUBLIC? I don't think this is a valid value... Do you mean whichever value resolves to a subnet first in that order?

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 do mean that. I can come up with a description of that behavior that is super technically correct ("The first one out of PRIVATE, ISOLATED, PUBLIC that has subnets of that type configured"), but not one that's easy to read.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, @rix0rrr I like you proposed change (and the value should be -). It should be something like:

/**
 * @default - the default subnet type will be the first available type in the following order: PRIVATE, ISOLATE, PUBLIC
 */

Something like that.

@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

@@ -166,7 +165,7 @@ export interface SubnetSelection {
*
* At most one of `subnetType` and `subnetGroupName` can be supplied.
*
* @default SubnetType.PRIVATE
* @default SubnetType.PRIVATE (or ISOLATED or PUBLIC if there are no PRIVATE subnets)
Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, @rix0rrr I like you proposed change (and the value should be -). It should be something like:

/**
 * @default - the default subnet type will be the first available type in the following order: PRIVATE, ISOLATE, PUBLIC
 */

Something like that.

new Vpc(stack, 'VPC', {
natGateways: 0,
});
}, /make sure you don't configure any PRIVATE subnets/);
Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps provide the rationale for this in the error message or an accompanying link to an issue or doc

@mergify
Copy link
Contributor

mergify bot commented Oct 27, 2019

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

1 similar comment
@mergify
Copy link
Contributor

mergify bot commented Oct 27, 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 9a96c37 into master Oct 27, 2019
@mergify mergify bot deleted the huijbers/vpcs-subnet-types branch October 27, 2019 15:26
@ChrisLahaye
Copy link

What about NAT instances (https://docs.aws.amazon.com/vpc/latest/userguide/VPC_NAT_Instance.html)? They have zero NAT gateways and one or more private subnets, therefore failing this validation.

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 with only private subnet fails with error
6 participants