-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Add EC2 support for GetSecurityGroupsForVpc API operation (#12602) #12615
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
Add EC2 support for GetSecurityGroupsForVpc API operation (#12602) #12615
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Welcome to LocalStack! Thanks for raising your first Pull Request and landing in your contributions. Our team will reach out with any reviews or feedbacks that we have shortly. We recommend joining our Slack Community and share your PR on the #community channel to share your contributions with us. Please make sure you are following our contributing guidelines and our Code of Conduct.
All contributors have signed the CLA ✍️ ✅ |
bf228f3
to
b7cc833
Compare
I have read the CLA Document and I hereby sign the CLA |
How can I add label |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @iamramtin, thanks for raising the PR! I have added my review comments below. I will also add the semver label.
…#12602) Signed-off-by: Ramtin Mesgari <26694963+iamramtin@users.noreply.github.com>
b7cc833
to
cf63323
Compare
…oupName when adding ingress rules This avoids issues with security groups in different VPCs Signed-off-by: Ramtin Mesgari <26694963+iamramtin@users.noreply.github.com>
Signed-off-by: Ramtin Mesgari <26694963+iamramtin@users.noreply.github.com>
Signed-off-by: Ramtin Mesgari <26694963+iamramtin@users.noreply.github.com>
ae55ba2
to
facdeec
Compare
…p fixture (localstack#12602) Signed-off-by: Ramtin Mesgari <26694963+iamramtin@users.noreply.github.com>
facdeec
to
fd20316
Compare
…stack#12602) - Structure tests to validate core filtering functionality - Add SortingTransformer to normalize security group ordering in responses - Verify both initial VPC state and post-security-group addition state Signed-off-by: Ramtin Mesgari <26694963+iamramtin@users.noreply.github.com>
5332c4d
to
05ecace
Compare
@viren-nadkarni thanks for your review. I took a closer look at the other snapshot tests in the codebase and reworked my approach. I've removed the assertions and now rely on the snapshot framework for validation similar to other parity tests. I've also added some FIXME/TODOs to highlight potential issues / inconsistencies I came across. Let me know if this looks good, or if you'd prefer any further adjustments to the testing approach. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @iamramtin, the implementation currently breaks when a security group has tags. Could you please fix it and include the necessary test cases?
$ awslocal ec2 create-vpc --cidr-block 10.1.0.0/16 --query Vpc.VpcId
"vpc-596131631cff9cea1"
$ awslocal ec2 create-security-group --group-name hello --description world --vpc vpc-596131631cff9cea1 --tag-specifications "ResourceType=security-group,Tags=[{Key=colour,Value=blue}]"{
"GroupId": "sg-cbf52384c65ddc0b6",
"Tags": [
{
"Key": "colour",
"Value": "blue"
}
],
"SecurityGroupArn": "arn:aws:ec2:eu-central-1:000000000000:security-group/sg-cbf52384c65ddc0b6"
}
$ awslocal ec2 get-security-groups-for-vpc --vpc-id vpc-596131631cff9cea1
An error occurred (InternalError) when calling the GetSecurityGroupsForVpc operation (reached max retries: 4): exception while calling ec2.GetSecurityGroupsForVpc: Traceback (most recent call last):
File "/home/viren/.virtualenvs/ls_venv/lib/python3.11/site-packages/rolo/gateway/chain.py", line 166, in handle
handler(self, self.context, response)
File "/home/viren/repo/localstack/localstack-core/localstack/aws/handlers/service.py", line 113, in __call__
handler(chain, context, response)
File "/home/viren/repo/localstack/localstack-core/localstack/aws/handlers/service.py", line 83, in __call__
skeleton_response = self.skeleton.invoke(context)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/viren/repo/localstack/localstack-core/localstack/aws/skeleton.py", line 154, in invoke
return self.dispatch_request(serializer, context, instance)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/viren/repo/localstack/localstack-core/localstack/aws/skeleton.py", line 168, in dispatch_request
result = handler(context, instance) or {}
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/viren/repo/localstack/localstack-core/localstack/aws/forwarder.py", line 133, in _call
return handler(context, req)
^^^^^^^^^^^^^^^^^^^^^
File "/home/viren/repo/localstack/localstack-core/localstack/aws/skeleton.py", line 118, in __call__
return self.fn(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/viren/repo/localstack/localstack-core/localstack/aws/api/core.py", line 163, in operation_marker
return fn(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^
File "/home/viren/repo/localstack/localstack-core/localstack/services/ec2/provider.py", line 556, in get_security_groups_for_vpc
sgs = [
^
File "/home/viren/repo/localstack/localstack-core/localstack/services/ec2/provider.py", line 563, in <listcomp>
Tags=[{"Key": k, "Value": v} for k, v in (sg.get_tags() or {}).items()],
^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'list' object has no attribute 'items'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for bearing with me. If you could clarify these last concerns, we can merge this.
359355d
to
48a445d
Compare
…12602) Signed-off-by: Ramtin Mesgari <26694963+iamramtin@users.noreply.github.com>
48a445d
to
6bac29d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, thanks for the contribution @iamramtin!
Motivation
This PR adds support for the EC2 API's
GetSecurityGroupsForVpc
operation, which retrieves security groups associated with a specified VPC. This operation provides a convenient way to filter security groups by VPC ID, without having to use the more generic filters syntax ofDescribeSecurityGroups
.Changes
GetSecurityGroupsForVpc
EC2 API operationDescribeSecurityGroups
functionality with a VPC filterTesting
You can test this new functionality in the following way:
Additionally, the PR includes integration tests that verify regular functionality and edge cases.