AWS CloudFromation leverages existing security group

I want to use an existing security group in a cloudformation template. Now I have a template that creates 2 SG,

 "InstanceMember1": {
      "Type": "AWS::EC2::Instance",
      "Properties": {
        "SubnetId": {
          "Ref": "privateSubnetA"
        },
        "SecurityGroupIds": [
          {
            "Ref": "MongoSg"
          },
          {
            "Ref": "mongoTrafficSG"
          } 
        ],
    }
}

"MongoSg": {
      "Type": "AWS::EC2::SecurityGroup",
      "Properties": {
        "GroupDescription": "MongoDB security group",
        "SecurityGroupIngress": [
          {
            "IpProtocol": "tcp",
            "FromPort": "22",
            "ToPort": "22",
            "SourceSecurityGroupId": {
              "Ref": "bastionSG"
            }
          }
        ],
        "VpcId": "%%vpc-id%%",
      }
}
}

Now I want to add the security group identifier to the instance, any advice?

+4
source share
1 answer

you can simply specify the name of the security group: http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-ec2-instance.html#cfn-ec2-instance-securitygroups

 "InstanceMember1": {
      "Type": "AWS::EC2::Instance",
      "Properties": {
        "SubnetId": {
          "Ref": "privateSubnetA"
        },
        "SecurityGroups": [ "mysuperawesomealreadyexistinggroup"],
    }
}
+9
source

Source: https://habr.com/ru/post/1624094/


All Articles