Repository: aws-cloudformation/cfn-lint

Issue:
E2506 prevents using SourceSecurityGroupId for non-vpc security groups
https://github.com/aws-cloudformation/cfn-lint/blob/4a7af2bd53a9ad1ccaba3a509437c53102ade522/src/cfnlint/rules/resources/ectwo/SecurityGroupIngress.py#L33-L40

I couldn't see any reason in the [cloudformation reference](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-ec2-security-group-rule-1.html#cfn-ec2-security-group-rule-sourcesecuritygroupid) that this wouldn't be valid, and I was able successfully create the following stack, where SecurityGroupB seems to be correctly restricted to traffic from SecurityGroupA. I _think_ that this rule is incorrect, unless I'm missing something

```yaml
AWSTemplateFormatVersion: '2010-09-09'
Resources:
  SecurityGroupA:
    Type: AWS::EC2::SecurityGroup
    Properties:
      GroupDescription: Group A
      SecurityGroupIngress:
        - FromPort: 80
          ToPort: 80
          IpProtocol: tcp
          CidrIp: 0.0.0.0/0

  SecurityGroupB:
    Type: AWS::EC2::SecurityGroup
    Properties:
      GroupDescription: Group B
      SecurityGroupIngress:
        - FromPort: 80
          ToPort: 80
          IpProtocol: tcp
          SourceSecurityGroupId:
            Fn::GetAtt:
              - SecurityGroupA
              - GroupId
```


Discussion:
Yea it'd be nice to know what this rule is for. Also getting this error..
This is an older rule and needs a refresh as there have been some changes from ec2-classic.  

Validated the following scenarios:
* `SourceSecurityGroupId` works for Default VPC (when `VpcId` is NOTspecified)
* `SourceSecurityGroupName` works  for Default VPC (when `VpcId` is NOTspecified)
* `SourceSecurityGroupName` doesn't work when VpcId is specified

Docs:

```
SourceSecurityGroupId
    The ID of the security group. You must specify either the security group ID or the security group name in the request. For security groups in a nondefault VPC, you must specify the security group ID.
    Required: No
    Type: String
    Update requires: [No interruption](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/using-cfn-updating-stacks-update-behaviors.html#update-no-interrupt)

SourceSecurityGroupName
    [Default VPC] The name of the source security group. You must specify either the security group ID or the security group name. You can't specify the group name in combination with an IP address range. Creates rules that grant full ICMP, UDP, and TCP access.

    For security groups in a nondefault VPC, you must specify the group ID.

    Required: No
    Type: String
    Update requires: [No interruption](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/using-cfn-updating-stacks-update-behaviors.html#update-no-interrupt)
```

Resolving patch:
diff --git a/src/cfnlint/rules/resources/ectwo/SecurityGroupIngress.py b/src/cfnlint/rules/resources/ectwo/SecurityGroupIngress.py
--- a/src/cfnlint/rules/resources/ectwo/SecurityGroupIngress.py
+++ b/src/cfnlint/rules/resources/ectwo/SecurityGroupIngress.py
@@ -36,19 +36,6 @@ def check_ingress_rule(self, vpc_id, properties, path):
                     )
                 )
 
-        else:
-            if properties.get("SourceSecurityGroupId", None):
-                path_error = path[:] + ["SourceSecurityGroupId"]
-                message = (
-                    "SourceSecurityGroupId shouldn't be specified for "
-                    "Non-Vpc Security Group at {0}"
-                )
-                matches.append(
-                    RuleMatch(
-                        path_error, message.format("/".join(map(str, path_error)))
-                    )
-                )
-
         return matches
 
     def match(self, cfn):


Test patch:
diff --git a/test/unit/rules/resources/ec2/test_sg_ingress.py b/test/unit/rules/resources/ec2/test_sg_ingress.py
--- a/test/unit/rules/resources/ec2/test_sg_ingress.py
+++ b/test/unit/rules/resources/ec2/test_sg_ingress.py
@@ -27,5 +27,5 @@ def test_file_positive(self):
     def test_file_negative(self):
         """Test failure"""
         self.helper_file_negative(
-            "test/fixtures/templates/bad/properties_sg_ingress.yaml", 2
+            "test/fixtures/templates/bad/properties_sg_ingress.yaml", 1
         )