Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
velocity-cfn-template-sample.template.vm
{
"AWSTemplateFormatVersion" : "2010-09-09",
"Description" : "$description",
"Resources" : {
"$security_group.name" : {
"Type" : "AWS::EC2::SecurityGroup",
"DeletionPolicy" : "Delete",
"Properties" : {
"GroupDescription" : "$security_group.description",
"SecurityGroupIngress" : [
#foreach ( $ing in $security_group.ingress )
#if ( $foreach.hasNext )
{ "IpProtocol" : "$ing.protocol", "FromPort" : "$ing.from", "ToPort" : "$ing.to", "CidrIp" : "$ing.cidr" },
#else
{ "IpProtocol" : "$ing.protocol", "FromPort" : "$ing.from", "ToPort" : "$ing.to", "CidrIp" : "$ing.cidr" }
#end
#end
]
}
},
"$instance.name" : {
"Type" : "AWS::EC2::Instance",
"DeletionPolicy" : "Delete",
"Properties" : {
"Tags" : [
{ "Key" : "Name", "Value" : "$instance.name" }
],
"ImageId" : "$instance.id",
"InstanceType" : "$instance.type",
"AvailabilityZone" : "$availability_zone",
"SecurityGroups" : [ { "Ref" : "$security_group.name" } ],
"UserData" : { "Fn::Base64" : { "Fn::Join" : [ "", [
"#!/bin/bash -v\n",
"yum update -y aws-cfn-bootstrap\n",
"# wait for the EBS volume to show up\n",
#foreach ( $snapshot in $snapshots )
"while [ ! -e $snapshot.device ]; do echo Waiting for EBS volume to attach; sleep 5; done\n",
#end
"# mount EBS volume\n",
#foreach ( $snapshot in $snapshots )
"mount $snapshot.device $snapshot.path\n",
#end
"# start postgresql server\n",
"service postgresql start\n"
]]}}
}
},
"$volume.name" : {
"Type" : "AWS::EC2::Volume",
"DeletionPolicy" : "Delete",
"Properties" : {
"AvailabilityZone" : "$availability_zone",
"Encrypted" : "false",
"VolumeType" : "$volume.type",
"Size" : "$volume.size"
}
},
"MountPoint$volume.name" : {
"Type" : "AWS::EC2::VolumeAttachment",
"Properties" : {
"InstanceId" : { "Ref" : "$instance.name" },
"VolumeId" : { "Ref" : "$volume.name" },
"Device" : "$volume.device"
}
},
#foreach ( $snapshot in $snapshots )
#if ( $foreach.hasNext )
"DatabaseVolume$snapshot.name" : {
"Type" : "AWS::EC2::Volume",
"DeletionPolicy" : "Delete",
"Properties" : {
"AvailabilityZone" : "$availability_zone",
"SnapshotId" : "$snapshot.id",
"Encrypted" : "false",
"VolumeType" : "$snapshot.type",
"Size" : "$snapshot.size"
}
},
"MountPoint$snapshot.name" : {
"Type" : "AWS::EC2::VolumeAttachment",
"Properties" : {
"InstanceId" : { "Ref" : "$instance.name" },
"VolumeId" : { "Ref" : "DatabaseVolume$snapshot.name" },
"Device" : "$snapshot.device"
}
},
#else
"DatabaseVolume$snapshot.name" : {
"Type" : "AWS::EC2::Volume",
"DeletionPolicy" : "Delete",
"Properties" : {
"AvailabilityZone" : "$availability_zone",
"SnapshotId" : "$snapshot.id",
"Encrypted" : "false",
"VolumeType" : "$snapshot.type",
"Size" : "$snapshot.size"
}
},
"MountPoint$snapshot.name" : {
"Type" : "AWS::EC2::VolumeAttachment",
"Properties" : {
"InstanceId" : { "Ref" : "$instance.name" },
"VolumeId" : { "Ref" : "DatabaseVolume$snapshot.name" },
"Device" : "$snapshot.device"
}
}
}
#end
#end
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment