Last active
January 18, 2024 17:00
-
-
Save alanwill/9254414 to your computer and use it in GitHub Desktop.
AWS CloudFormation example that allows a security group rule to reference the same security group as the source.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"Description": "Create a VPC with a SG which references itself", | |
"AWSTemplateFormatVersion": "2010-09-09", | |
"Resources": { | |
"vpctester": { | |
"Type": "AWS::EC2::VPC", | |
"Properties": { | |
"CidrBlock": "172.16.0.0/23", | |
"EnableDnsSupport": false, | |
"EnableDnsHostnames": false, | |
"InstanceTenancy": "default", | |
"Tags": [ { "Key": "Name", "Value": "vpctester" } ] | |
} | |
}, | |
"sgtester": { | |
"Type": "AWS::EC2::SecurityGroup", | |
"DependsOn": "vpctester", | |
"Properties": { | |
"GroupDescription": "vpc tester sg", | |
"VpcId": { "Ref": "vpctester" } | |
} | |
}, | |
"sgtesteringress": { | |
"Type": "AWS::EC2::SecurityGroupIngress", | |
"DependsOn": "sgtester", | |
"Properties": { | |
"GroupId": { "Ref": "sgtester" }, | |
"IpProtocol": "tcp", | |
"FromPort": "0", | |
"ToPort": "65535", | |
"SourceSecurityGroupId": { "Ref": "sgtester" } | |
} | |
} | |
} | |
} |
Thanks, it was helpful
Thanks!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@SwathiKanduri the
groupId
relates to the security group for which this AWS::EC2::SecurityGroupIngress resource is actually an ingress rule. ThesourceSecurityGroupId
relates to the security group which we want to allow inbound traffic from. In this case they both refer tosgtester
because this is a self-referencing security group, but in the general casesourceSecurityGroupId
would refer to some other security group that we want to allow inbound traffic from.