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(aws-ec2): Add SubnetFilter for Id and CIDR netmask #15373

Merged
merged 12 commits into from
Jul 30, 2021

Conversation

ABevier
Copy link
Contributor

@ABevier ABevier commented Jun 30, 2021

This PR adds a couple of basic SubnetFilters into the CDK directly so they don't have to be needlessly reimplemented. The SubnetIdSubnetFilter filters subnets by ID and the CidrMaskSubnetFilter filters subnets based on the CIDR netmask.

closes #15228

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

@gitpod-io
Copy link

gitpod-io bot commented Jun 30, 2021

@ABevier ABevier changed the title feat(aws-ec2) Add SubnetFilter for Id and CIDR netmask feat(aws-ec2): Add SubnetFilter for Id and CIDR netmask Jun 30, 2021
slmingol
slmingol previously approved these changes Jul 1, 2021
@peterwoodworth peterwoodworth added the @aws-cdk/aws-ec2 Related to Amazon Elastic Compute Cloud label Jul 6, 2021
constructor(mask: number) {
super();
if (mask < 16 || mask > 28 ) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Outsider comment: this check isn't necessary. The Subnet class should already prevent creation of a subnet that isn't like 28 >= cidr mask >= 16.

If AWS supports a different range of subnets in the future, this would need to update as well.

Copy link
Contributor

Choose a reason for hiding this comment

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

Agreed. I think this check is redundant.

@njlynch njlynch added effort/small Small work item – less than a day of effort p1 labels Jul 28, 2021
Copy link
Contributor

@njlynch njlynch left a comment

Choose a reason for hiding this comment

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

Looks good!

All really minor stuff. The docs I think need an update; the two code changes are optional (but recommended).

constructor(mask: number) {
super();
if (mask < 16 || mask > 28 ) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Agreed. I think this check is redundant.

Comment on lines 170 to 174
* `SubnetIdSubnetFilter`: chooses subnets from a list of ids
* `AvailabilityZoneSubnetFilter`: chooses subnets in the provided list of availability zones
* `OnePerAZSubnetFilter`: chooses at most one subnet per availability zone
* `ContainsIpAddressesSubnetFilter`: chooses a subnet which contains *any* of the listed ip addresses
* `CidrMaskSubnetFilter`: chooses subnets that have the provided CIDR netmask
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a good enhancement to the documentation. However, since the various classes are all private (not exported) it probably makes more sense to replace the class names here with the static factory method names.

}

private retainByCidrMask(subnets: ISubnet[], netmask: number): ISubnet[] {
Copy link
Contributor

Choose a reason for hiding this comment

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

~ (Nit) I would probably just inline this; I don't know that making it its own method adds anything here.

@mergify mergify bot dismissed njlynch’s stale review July 29, 2021 17:53

Pull request has been modified.

Copy link
Contributor

@njlynch njlynch left a comment

Choose a reason for hiding this comment

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

Thanks for the changes!

@mergify
Copy link
Contributor

mergify bot commented Jul 30, 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: AutoBuildProject89A8053A-LhjRyN9kxr8o
  • Commit ID: 3e5cb65
  • 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 407b02d into aws:master Jul 30, 2021
@mergify
Copy link
Contributor

mergify bot commented Jul 30, 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).

TikiTDO pushed a commit to TikiTDO/aws-cdk that referenced this pull request Aug 3, 2021
This PR adds a couple of basic SubnetFilters into the CDK directly so they don't have to be needlessly reimplemented.  The `SubnetIdSubnetFilter` filters subnets by ID and the `CidrMaskSubnetFilter` filters subnets based on the CIDR netmask.

closes aws#15228
----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
hollanddd pushed a commit to hollanddd/aws-cdk that referenced this pull request Aug 26, 2021
This PR adds a couple of basic SubnetFilters into the CDK directly so they don't have to be needlessly reimplemented.  The `SubnetIdSubnetFilter` filters subnets by ID and the `CidrMaskSubnetFilter` filters subnets based on the CIDR netmask.

closes aws#15228
----

*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 effort/small Small work item – less than a day of effort p1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

(aws-ec2): Allow selecting subnets by Id or CIDR mask
6 participants