Search code examples
amazon-web-servicesyamlaws-cloudformationaws-security-group

AWS CloudFormation: SecurityGroup refers to another security group


This code throws a "Group Description Empty" when that part is full.

Resources:
  FormulationSG:
    Type: 'AWS::EC2::SecurityGroup'
    Properties:
      Tags:
        - Key: 'Name'
          Value: 'FormulationSG'
      VpcId: 'vpc-yyy00yyy'
      GroupDescription: 'Port Rules for Formulation and on Port 11.'
      SecurityGroupIngress:
        - IpProtocol: tcp
          CidrIp: 192.168.0.0/8
          FromPort: '11'
          ToPort: '11'
        - IpProtocol: tcp
          FromPort: '91'
          ToPort: '91'
          SourceSecurityGroupName: 'sg-1234567'

Ignore all the numbers were changed but the problem I am having is once I tried to source an existing security group 'sg-1234567' and it gives me an error message saying group description is invalid when it is already there in quotes.


Solution

  • SourceSecurityGroupName is for EC2 classic only. You are using VPC EC2 (which is recommended). Use SourceSecurityGroupId instead. You do not need to use quotes. This example will work fine:

    Resources:
      FormulationSG:
        Type: AWS::EC2::SecurityGroup
        Properties:
          Tags:
            - Key: Name
              Value: FormulationSG
          VpcId: vpc-yyy00yyy
          GroupDescription: Port Rules for Formulation and on Port 11.
          SecurityGroupIngress:
            - IpProtocol: tcp
              CidrIp: 192.168.0.0/8
              FromPort: 11
              ToPort: 11
          SecurityGroupIngress:
            - IpProtocol: tcp
              FromPort: 91
              ToPort: 91
              SourceSecurityGroupId: sg-1234567