Skip to content

Instantly share code, notes, and snippets.

@rkive
Created August 24, 2012 18:14
Show Gist options
  • Save rkive/3453821 to your computer and use it in GitHub Desktop.
Save rkive/3453821 to your computer and use it in GitHub Desktop.
Coffin template showing duplicate keys are not created in coffin compile
## Cloudformation Description Resource
@Description "A simple MySQL RDS test stack"
@Param.String 'home1', Default: '192.168.0.1/32'
@Param.String 'home2', Default: '192.168.0.2/32'
## Expected: This SecurityGroup should have two entries with IP addresses and two entries with EC2 Securitygroup names within DBSecurityGroupIngress.
## Acctual Result: Only the last item if the duplicate key is in the compiled JSON.
@AWS.RDS.DBSecurityGroup "ec2instances",
GroupDescription: "We should see 2 CIDRP and 2 EC2SecurityGroupName entries here."
DBSecurityGroupIngress:
CIDRIP: "10.10.10.10/32"
CIDRIP: "10.11.11.11/32"
EC2SecurityGroupName: "sampleGroup1"
EC2SecurityGroupName: "sampleGroup2"
## We can get around this by creating the array ahead of time. However, I must build them in JSON directly. 2 styles presented.
rdsOfficesIngress = [
{ "CIDRIP": "10.12.12.12/32" },
{ "CIDRIP": "10.12.12.12/32" },
{ "EC2SecurityGroupName": "sampleGroup3" },
{ "EC2SecurityGroupName": "sampleGroup4" }
]
homesParamsIngress = [
{ "CIDRIP": @Params.home1 },
{ "CIDRIP": @Params.home2 }
]
## Create the DB group just passing in the pre-built array.
@AWS.RDS.DBSecurityGroup "offices",
GroupDescription: "Security Group for offices to RDS"
DBSecurityGroupIngress: rdsOfficesIngress
@AWS.RDS.DBSecurityGroup "homes",
GroupDescription: "Security Group for homes to RDS"
DBSecurityGroupIngress: homesParamsIngress
## This will susccsfully create a single RDS instances with 2 Security Groups.
@AWS.RDS.DBInstance 'testDB',
Engine: 'MySQL'
DBName: 'testDB'
Port: '3306'
AllocatedStorage: '5'
MasterUsername: 'masterUsername'
MasterUserPassword: 'masterPassword'
DBInstanceClass: 'db.m1.small'
DBSecurityGroups: [
@Resources.ec2instances
@Resources.offices
]
## An Example of where two key/value pairs with the same key would cause confusion. Only udp is in the output on the duplicate IpProtocol.
@AWS.EC2.SecurityGroup 'LoadBalancerSecurityGroup',
GroupDescription: 'security group to allow the load balancer to talk to the service instance'
SecurityGroupIngress: [
IpProtocol: 'tcp'
IpProtocol: 'udp'
FromPort: '80'
ToPort: '80'
SourceSecurityGroupOwnerId: '1234'
SourceSecurityGroupName: 'Test_Name'
]
{
"AWSTemplateFormatVersion": "2010-09-09",
"Description": "A simple MySQL RDS test stack",
"Parameters": {
"home1": {
"Default": "192.168.0.1/32",
"Type": "String"
},
"home2": {
"Default": "192.168.0.2/32",
"Type": "String"
}
},
"Resources": {
"ec2instances": {
"Type": "AWS::RDS::DBSecurityGroup",
"Properties": {
"GroupDescription": "We should see 2 CIDRP and 2 EC2SecurityGroupName entries here.",
"DBSecurityGroupIngress": {
"CIDRIP": "10.11.11.11/32",
"EC2SecurityGroupName": "sampleGroup2"
}
}
},
"offices": {
"Type": "AWS::RDS::DBSecurityGroup",
"Properties": {
"GroupDescription": "Security Group for offices to RDS",
"DBSecurityGroupIngress": [
{
"CIDRIP": "10.12.12.12/32"
},
{
"CIDRIP": "10.12.12.12/32"
},
{
"EC2SecurityGroupName": "sampleGroup3"
},
{
"EC2SecurityGroupName": "sampleGroup4"
}
]
}
},
"homes": {
"Type": "AWS::RDS::DBSecurityGroup",
"Properties": {
"GroupDescription": "Security Group for homes to RDS",
"DBSecurityGroupIngress": [
{
"CIDRIP": {
"Ref": "home1"
}
},
{
"CIDRIP": {
"Ref": "home2"
}
}
]
}
},
"testDB": {
"Type": "AWS::RDS::DBInstance",
"Properties": {
"Engine": "MySQL",
"DBName": "testDB",
"Port": "3306",
"AllocatedStorage": "5",
"MasterUsername": "masterUsername",
"MasterUserPassword": "masterPassword",
"DBInstanceClass": "db.m1.small",
"DBSecurityGroups": [
{
"Ref": "ec2instances"
},
{
"Ref": "offices"
}
]
}
},
"LoadBalancerSecurityGroup": {
"Type": "AWS::EC2::SecurityGroup",
"Properties": {
"GroupDescription": "security group to allow the load balancer to talk to the service instance",
"SecurityGroupIngress": [
{
"IpProtocol": "udp",
"FromPort": "80",
"ToPort": "80",
"SourceSecurityGroupOwnerId": "1234",
"SourceSecurityGroupName": "Test_Name"
}
]
}
}
},
"Outputs": {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment