aws / aws-cdk

The AWS Cloud Development Kit is a framework for defining cloud infrastructure in code
https://aws.amazon.com/cdk
Apache License 2.0
11.4k stars 3.79k forks source link

EC2: Security Groups lookup by Owner #30331

Open eschirle opened 2 months ago

eschirle commented 2 months ago

Describe the feature

SecurityGroup.fromLookupByName() provides an option for looking up a security group by name - but this fails if multiple SGs are found with the provided name.

This feature is for the ability to filter security groups by Owner as well.

Use Case

I have a use case where I'd like to use a Baseline SecurityGroup for Lambda Functions that are a part of a custom construct to avoid creating a new SG and using up more Hyperplane ENIs. I can lookup by name "BaselineSecurityGroup", but my VPC is shared across multiple micro accounts, and so multiple SecurityGroups are returned.

This feature would include the option to filter SecurityGroups by SecurityGroupName and Owner, so that I can grab the SG when there are multiple with the same name in a single VPC.

Proposed Solution

Either adding an optional owner input to fromLookupByName or add a new method fromLookupByNameAndOwner in security-group.ts

public static fromLookupByName(scope: Construct, id: string, securityGroupName: string, vpc: IVpc, owner?: string) { return this.fromLookupAttributes(scope, id, { securityGroupName, vpc, owner }); }

Other Information

No response

Acknowledgements

CDK version used

2.142.0

Environment details (OS name and version, etc.)

N/A

eschirle commented 2 months ago

I created a PR with a possible solution for this #30334

khushail commented 2 months ago

@eschirle , this makes sense to me. Thanks for reporting and volunteering for PR contribution !

eschirle commented 1 month ago

@eschirle , this makes sense to me. Thanks for reporting and volunteering for PR contribution !

Hi @khushail - I made some updates to the PR today and marked it as ready for review. I was able to run unit tests and integration tests in my development environment but I think it needs some additional changes to pass validation.
Could you please take a look?

khushail commented 1 month ago

@eschirle , thanks for your contribution. Usually community PRs ar first reviewed by approved community reviewers and then by Core CDK Team and you could also ask for help in the mentioned slack channel in this doc. Here are the approved guidelines.