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(ec2): user-defined subnet selectors #10112

Merged
merged 20 commits into from
Sep 16, 2020

Conversation

flemjame-at-amazon
Copy link
Contributor

Continuation of #8526

This change adds a feature to SubnetSelection which lets the user provide objects that implements the new ISubnetSelector interface. These objects will be used by the VPC class to choose the subnets from the VPC.

This commit also provides an implementation of an ISubnetSelector that lets the user select subnets that contain IP addresses.

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

rix0rrr
rix0rrr previously requested changes Sep 7, 2020
if (placement.subnetName !== undefined) {
if (placement.subnetGroupName !== undefined) {
throw new Error('Please use only \'subnetGroupName\' (\'subnetName\' is deprecated and has the same behavior)');
} else {
Annotations.of(this).addWarning('Usage of \'subnetName\' in SubnetSelection is deprecated, use \'subnetGroupName\' instead');
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 API contract misuse and should definitely remain an error that aborts the program.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The error still occurs if the user specifies both, like before. Now the user will get a friendly reminder that subnetName shouldn't be used, but still allows them to use it -- like before.

Should I change the behavior such that it throws an error?

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh I see, I misread.

Well, hmm. I guess it's maybe a little overkill, but fine.

@@ -460,17 +473,21 @@ abstract class VpcBase extends Resource implements IVpc {
subnets = this.selectSubnetObjectsByType(type);
}

if (selection.availabilityZones !== undefined) { // Filter by AZs, if specified
subnets = retainByAZ(subnets, selection.availabilityZones);
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't this at least lead to the appropriate filter class being prepended to the list?

Strictly speaking this method is protected, therefore has a public contract to other people that could have inherited from this class and are relying on its current behavior.

Copy link
Contributor Author

@flemjame-at-amazon flemjame-at-amazon Sep 8, 2020

Choose a reason for hiding this comment

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

Yes you're correct. That functionality is now in reifySelectionDefaults. I did the same for the one-per-az selection option.

@rix0rrr
Copy link
Contributor

rix0rrr commented Sep 7, 2020

Good stuff and great idea!

@mergify mergify bot dismissed rix0rrr’s stale review September 8, 2020 13:22

Pull request has been modified.

}

// Overwrite the provided placement filters
placement = { ...placement, subnetFilters: subnetFilters };
Copy link
Contributor

Choose a reason for hiding this comment

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

This leaves the existing .availabilityZones and .onePerAz booleans in place.

Are you sure they're not going to be interpreted again?

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 did remove their interpretation everywhere else but here, but I suppose there's no harm in removing them completely.

@rix0rrr rix0rrr changed the title feat(ec2): Subnet selector protocol for user-defined subnet selection logic feat(ec2): user-defined subnet selectors Sep 16, 2020
@mergify
Copy link
Contributor

mergify bot commented Sep 16, 2020

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: 68a6b3b
  • 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 Sep 16, 2020

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 491113d into aws:master Sep 16, 2020
@flemjame-at-amazon flemjame-at-amazon deleted the vpc-subnet-selection-protocol branch October 27, 2020 14:16
@buttnomaan9
Copy link

Hi, @rix0rrr is there a way to filter subnets based on tags?

@flemjame-at-amazon
Copy link
Contributor Author

@buttnomaan9 you can provide your own mechanism to filter subnets https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-ec2.SubnetFilter.html

@alexjfisher
Copy link

alexjfisher commented Oct 18, 2021

@buttnomaan9 you can provide your own mechanism to filter subnets https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-ec2.SubnetFilter.html

@flemjame-at-amazon I'm not sure this is actually possible. I've just tried to implement such a filter, but soon hit an issue. subnet doesn't have any methods that let you access tags, and AFAICT, when a VPC is imported, this information is not. This would be really useful though. Do you know what would have to change to make this possible?

(comment edited after rereading and noticing my poor choice of language. No offence intended.)

@flemjame-at-amazon
Copy link
Contributor Author

@buttnomaan9 you can provide your own mechanism to filter subnets https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-ec2.SubnetFilter.html

@flemjame-at-amazon I'm not sure this is actually possible. I've just tried to implement such a filter, but soon hit an issue. subnet doesn't have any methods that let you access tags, and AFAICT, when a VPC is imported, this information is not. This would be really useful though. Do you know what would have to change to make this possible?

(comment edited after rereading and noticing my poor choice of language. No offence intended.)

You would have to track tags outside of the subnet because it has no method to access tags, similarly with imported. The subnet filters allow users to fill in gaps in CDK with their own logic. It's more work, but you can do basically whatever you want.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants