Created
October 30, 2017 23:58
-
-
Save dkalintsev/fdcd1520321723628bf402ddf4014e5f to your computer and use it in GitHub Desktop.
Example for how to supply optional Security Groups to a LaunchConfig (or EC2 instance)
This file contains 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
{ | |
"AWSTemplateFormatVersion" : "2010-09-09", | |
"Parameters": { | |
"PrimarySG": { | |
"Description": "Primary Security Group for the instance", | |
"Type": "String", | |
"Default": "sg-863ab0e0", | |
"ConstraintDescription": "must be an EC2 security group id" | |
}, | |
"AdditionalSGs": { | |
"Description": "Additional security groups for the instance", | |
"Type": "CommaDelimitedList", | |
"Default": "sg-e23ab084,sg-bb27addd", | |
"ConstraintDescription": "must be a list of EC2 security group ids" | |
} | |
}, | |
"Conditions" : { | |
"MoreSGs": { "Fn::Not": [ | |
{ "Fn::Equals": [ "", | |
{ "Fn::Join": [ "", { "Ref": "AdditionalSGs" } ] } | |
] } | |
] } | |
}, | |
"Resources": { | |
"InstanceLaunchConfig": { | |
"Type": "AWS::AutoScaling::LaunchConfiguration", | |
"Properties": { | |
"InstanceType": "t2.nano", | |
"KeyName": "SecretKey", | |
"ImageId": "ami-deadbeef", | |
"SecurityGroups": { | |
"Fn::If": [ | |
"MoreSGs", | |
{ "Fn::Split": [ ",", | |
{ "Fn::Join": [ ",", [ | |
{ "Ref": "PrimarySG" }, | |
{ "Fn::Join": [ ",", { "Ref": "AdditionalSGs" } ] } | |
] ] } | |
] }, | |
{ "Fn::Split": [ ",", | |
{ "Ref": "PrimarySG" } | |
] } | |
] | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment