Skip to content

Commit

Permalink
add SecurityGroupArn to security groups
Browse files Browse the repository at this point in the history
  • Loading branch information
pinzon committed Dec 12, 2024
1 parent 57d0c0e commit cc825a7
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 0 deletions.
1 change: 1 addition & 0 deletions moto/ec2/models/security_groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ def __init__(
self.owner_id = ec2_backend.account_id
self.add_tags(tags or {})
self.is_default = is_default or False
self.arn = f"arn:aws:ec2:{ec2_backend.account_id}:{ec2_backend.region_name}:security-group/{group_id}"

# Append default IPv6 egress rule for VPCs with IPv6 support
if vpc_id:
Expand Down
2 changes: 2 additions & 0 deletions moto/ec2/responses/security_groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ def update_security_group_rule_descriptions_egress(self) -> str:
<requestId>59dbff89-35bd-4eac-99ed-be587EXAMPLE</requestId>
<return>true</return>
<groupId>{{ group.id }}</groupId>
<securityGroupArn>{{ group.arn }}</securityGroupArn>
<tagSet>
{% for tag in group.get_tags() %}
<item>
Expand Down Expand Up @@ -346,6 +347,7 @@ def update_security_group_rule_descriptions_egress(self) -> str:
<groupId>{{ group.id }}</groupId>
<groupName>{{ group.name }}</groupName>
<groupDescription>{{ group.description }}</groupDescription>
<securityGroupArn>{{ group.arn }}</securityGroupArn>
{% if group.vpc_id %}
<vpcId>{{ group.vpc_id }}</vpcId>
{% endif %}
Expand Down
1 change: 1 addition & 0 deletions tests/test_ec2/test_security_groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ def test_create_and_describe_vpc_security_group():

assert group_with.group_name == name
assert group_with.description == "test"
assert group_with.security_group_arn

# Trying to create another group with the same name in the same VPC should
# throw an error
Expand Down

0 comments on commit cc825a7

Please sign in to comment.