Repository: getmoto/moto
Pull request #8960 (2025-06-09 19:14:06)

EC2: VPC: Fix typo in referenced group
## Motivation

This pr fixes a typo in `ModifySecurityGroupRule`. Attempting to modify a security group rule with a security group association would fail as `ReferencedGroupId` was misspelled.

codecov[bot]: ## [Codecov](https://app.codecov.io/gh/getmoto/moto/pull/8960?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=getmoto) Report
All modified and coverable lines are covered by tests :white_check_mark:
> Project coverage is 92.85%. Comparing base [(`cde945a`)](https://app.codecov.io/gh/getmoto/moto/commit/cde945aee9d322fb89fc1069fa9582eeb6a17fd5?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=getmoto) to head [(`a94e84f`)](https://app.codecov.io/gh/getmoto/moto/commit/a94e84fbf8970afde263ce36b5e38f6b588c369b?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=getmoto).

<details><summary>Additional details and impacted files</summary>


```diff
@@           Coverage Diff           @@
##           master    #8960   +/-   ##
=======================================
  Coverage   92.85%   92.85%           
=======================================
  Files        1287     1287           
  Lines      112812   112812           
=======================================
  Hits       104752   104752           
  Misses       8060     8060           
```

| [Flag](https://app.codecov.io/gh/getmoto/moto/pull/8960/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=getmoto) | Coverage Δ | |
|---|---|---|
| [servertests](https://app.codecov.io/gh/getmoto/moto/pull/8960/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=getmoto) | `28.54% <0.00%> (ø)` | |
| [unittests](https://app.codecov.io/gh/getmoto/moto/pull/8960/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=getmoto) | `92.83% <100.00%> (ø)` | |

Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=getmoto#carryforward-flags-in-the-pull-request-comment) to find out more.

</details>

[:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/getmoto/moto/pull/8960?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=getmoto).   
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=getmoto).

<details><summary> :rocket: New features to boost your workflow: </summary>

- :snowflake: [Test Analytics](https://docs.codecov.com/docs/test-analytics): Detect flaky tests, report on failures, and find test suite problems.
- :package: [JS Bundle Analysis](https://docs.codecov.com/docs/javascript-bundle-analysis): Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
</details>
cloutierMat: The test failure is related to test proxy and shouldn't be related to the current pr. Any known flakes with the proxy test?

Patch:
diff --git a/moto/ec2/models/security_groups.py b/moto/ec2/models/security_groups.py
index cf3f02d3a..a2e2f00ee 100644
--- a/moto/ec2/models/security_groups.py
+++ b/moto/ec2/models/security_groups.py
@@ -808,7 +808,7 @@ class SecurityGroupBackend:
             cidr_ipv4 = new_rule.get("CidrIpv4")
             cidr_ipv6 = new_rule.get("CidrIpv6")
             prefix_list_id = new_rule.get("PrefixListId")
-            reference_group_id = new_rule.get("ReferenceGroupId")
+            reference_group_id = new_rule.get("ReferencedGroupId")
 
             set_param_count = sum(
                 item is not None


Test patch:
diff --git a/tests/test_ec2/test_security_groups.py b/tests/test_ec2/test_security_groups.py
index 9a979c062..d04ee943a 100644
--- a/tests/test_ec2/test_security_groups.py
+++ b/tests/test_ec2/test_security_groups.py
@@ -1018,6 +1018,59 @@ def test_modify_security_group_rules(ec2_client=None, vpc_id=None, sg_id=None):
     assert response["SecurityGroupRules"][0]["Description"] == "first modification"
 
 
+@ec2_aws_verified(create_vpc=True, create_sg=True)
+@pytest.mark.aws_verified
+def test_modify_security_group_rules_with_referenced_group_id(
+    ec2_client=None, vpc_id=None, sg_id=None
+):
+    client = ec2_client
+    group_id = sg_id
+
+    ip_permissions = [
+        {
+            "IpProtocol": "tcp",
+            "FromPort": 30900,
+            "ToPort": 31000,
+            "UserIdGroupPairs": [
+                {
+                    "GroupId": group_id,
+                }
+            ],
+        }
+    ]
+    rule_id = client.authorize_security_group_ingress(
+        GroupId=group_id, IpPermissions=ip_permissions
+    )["SecurityGroupRules"][0]["SecurityGroupRuleId"]
+
+    client.modify_security_group_rules(
+        GroupId=group_id,
+        SecurityGroupRules=[
+            {
+                "SecurityGroupRuleId": rule_id,
+                "SecurityGroupRule": {
+                    "IpProtocol": "tcp",
+                    "FromPort": 39900,
+                    "ToPort": 40000,
+                    "ReferencedGroupId": group_id,
+                },
+            }
+        ],
+    )
+    response = client.describe_security_group_rules(
+        Filters=[
+            {"Name": "group-id", "Values": [group_id]},
+            {"Name": "security-group-rule-id", "Values": [rule_id]},
+        ]
+    )
+    assert len(response["SecurityGroupRules"]) == 1
+    assert response["SecurityGroupRules"][0]["IpProtocol"] == "tcp"
+    assert response["SecurityGroupRules"][0]["FromPort"] == 39900
+    assert response["SecurityGroupRules"][0]["ToPort"] == 40000
+    assert (
+        response["SecurityGroupRules"][0]["ReferencedGroupInfo"]["GroupId"] == group_id
+    )
+
+
 @mock_aws
 @pytest.mark.parametrize("use_vpc", [True, False], ids=["Use VPC", "Without VPC"])
 def test_sec_group_rule_limit(use_vpc):