Skip to content

Instantly share code, notes, and snippets.

@sjlu
Created October 19, 2015 14:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sjlu/08012d4df3600ccb5b9a to your computer and use it in GitHub Desktop.
Save sjlu/08012d4df3600ccb5b9a to your computer and use it in GitHub Desktop.
CoreOS CloudFormation that includes its own VPC mapping
{
"Mappings": {
"RegionMap": {
"eu-central-1": {
"AMI": "ami-840a0899"
},
"ap-northeast-1": {
"AMI": "ami-6c5ac56c"
},
"us-gov-west-1": {
"AMI": "ami-796a085a"
},
"sa-east-1": {
"AMI": "ami-3396012e"
},
"ap-southeast-2": {
"AMI": "ami-f5ace5cf"
},
"ap-southeast-1": {
"AMI": "ami-46819614"
},
"us-east-1": {
"AMI": "ami-05783d60"
},
"us-west-2": {
"AMI": "ami-ed8b90dd"
},
"us-west-1": {
"AMI": "ami-2b29ee6f"
},
"eu-west-1": {
"AMI": "ami-eb97bc9c"
}
}
},
"Parameters": {
"KeyName": {
"Type": "String",
"Default": "sjlu@Steven-Lus-MacBook-Pro.local",
"Description": "EC2 SSH keypair name"
},
"ClusterSize": {
"Type": "Number",
"Default": "3",
"MinValue": "1",
"MaxValue": "12",
"Description": "Number of instances"
},
"InstanceType": {
"Type": "String",
"Default": "t2.micro",
"AllowedValues": [
"t2.micro",
"t2.small",
"t2.medium"
],
"Description": "EC2 HVM instance type"
},
"DiscoveryURL": {
"Type": "String",
"Default": "https://discovery.etcd.io/a3c891efd3ff5c6c7a55268fc737894e",
"Description": "etcd cluster discovery url; https://discovery.etcd.io/new"
},
"AdvertisedIPAddress": {
"Type": "String",
"Description": "etcd to span within a single region or multi-region",
"Default": "private",
"AllowedValues": [
"private",
"public"
]
}
},
"Resources": {
"VPC": {
"Type": "AWS::EC2::VPC",
"Properties": {
"CidrBlock": "172.16.0.0/16",
"Tags": [
{
"Key": "Application",
"Value": {
"Ref": "AWS::StackId"
}
}
]
}
},
"PublicSubnet": {
"Type": "AWS::EC2::Subnet",
"Properties": {
"CidrBlock": "172.16.0.0/24",
"VpcId": {
"Ref": "VPC"
},
"Tags": [
{
"Key": "Application",
"Value": {
"Ref": "AWS::StackId"
}
}
]
}
},
"InternetGateway": {
"Type": "AWS::EC2::InternetGateway",
"Properties": {
"Tags": [
{
"Key": "Application",
"Value": {
"Ref": "AWS::StackId"
}
}
]
}
},
"GatewayToInternet": {
"Type": "AWS::EC2::VPCGatewayAttachment",
"Properties": {
"VpcId": {
"Ref": "VPC"
},
"InternetGatewayId": {
"Ref": "InternetGateway"
}
}
},
"PublicRouteTable": {
"Type": "AWS::EC2::RouteTable",
"Properties": {
"VpcId": {
"Ref": "VPC"
},
"Tags": [
{
"Key": "Application",
"Value": {
"Ref": "AWS::StackId"
}
}
]
}
},
"PublicRoute": {
"Type": "AWS::EC2::Route",
"DependsOn": "GatewayToInternet",
"Properties": {
"RouteTableId": {
"Ref": "PublicRouteTable"
},
"DestinationCidrBlock": "0.0.0.0/0",
"GatewayId": {
"Ref": "InternetGateway"
}
}
},
"PublicSubnetRouteTableAssociation": {
"Type": "AWS::EC2::SubnetRouteTableAssociation",
"Properties": {
"SubnetId": {
"Ref": "PublicSubnet"
},
"RouteTableId": {
"Ref": "PublicRouteTable"
}
}
},
"PublicNetworkAcl": {
"Type": "AWS::EC2::NetworkAcl",
"Properties": {
"VpcId": {
"Ref": "VPC"
},
"Tags": [
{
"Key": "Application",
"Value": {
"Ref": "AWS::StackId"
}
},
{
"Key": "Network",
"Value": "Public"
}
]
}
},
"PublicSubnetNetworkAclAssociation": {
"Type": "AWS::EC2::SubnetNetworkAclAssociation",
"Properties": {
"SubnetId": {
"Ref": "PublicSubnet"
},
"NetworkAclId": {
"Ref": "PublicNetworkAcl"
}
}
},
"OutboundPublicNetworkAclEntry": {
"Type": "AWS::EC2::NetworkAclEntry",
"Properties": {
"NetworkAclId": {
"Ref": "PublicNetworkAcl"
},
"RuleNumber": "100",
"Protocol": "-1",
"RuleAction": "allow",
"Egress": "true",
"CidrBlock": "0.0.0.0/0"
}
},
"InboundPublicNetworkAclEntry": {
"Type": "AWS::EC2::NetworkAclEntry",
"Properties": {
"NetworkAclId": {
"Ref": "PublicNetworkAcl"
},
"RuleNumber": "100",
"Protocol": "-1",
"RuleAction": "allow",
"Egress": "false",
"CidrBlock": "0.0.0.0/0"
}
},
"SecurityGroup": {
"Type": "AWS::EC2::SecurityGroup",
"Properties": {
"GroupDescription": "Security group applied to all instances",
"VpcId": {
"Ref": "VPC"
},
"SecurityGroupIngress": [
{
"IpProtocol": "tcp",
"FromPort": "22",
"ToPort": "22",
"CidrIp": "0.0.0.0/0"
}
]
}
},
"SecurityGroupIngress": {
"Type": "AWS::EC2::SecurityGroupIngress",
"Properties": {
"IpProtocol": "-1",
"FromPort": "-1",
"ToPort": "-1",
"SourceSecurityGroupId": {
"Fn::GetAtt": [
"SecurityGroup",
"GroupId"
]
},
"GroupId": {
"Fn::GetAtt": [
"SecurityGroup",
"GroupId"
]
}
}
},
"AutoScalingGroup": {
"Type": "AWS::AutoScaling::AutoScalingGroup",
"Properties": {
"LaunchConfigurationName": {
"Ref": "LaunchConfiguration"
},
"MinSize": "1",
"MaxSize": "12",
"DesiredCapacity": {
"Ref": "ClusterSize"
},
"Tags": [
{
"Key": "Name",
"Value": {
"Ref": "AWS::StackName"
},
"PropagateAtLaunch": true
}
],
"VPCZoneIdentifier": [
{
"Ref": "PublicSubnet"
}
]
}
},
"LaunchConfiguration": {
"Type": "AWS::AutoScaling::LaunchConfiguration",
"Properties": {
"ImageId": {
"Fn::FindInMap": [
"RegionMap",
{
"Ref": "AWS::Region"
},
"AMI"
]
},
"AssociatePublicIpAddress": "true",
"InstanceMonitoring": false,
"InstanceType": {
"Ref": "InstanceType"
},
"KeyName": {
"Ref": "KeyName"
},
"SecurityGroups": [
{
"Ref": "SecurityGroup"
}
],
"UserData": {
"Fn::Base64": {
"Fn::Join": [
"",
[
"#cloud-config\n\n",
"coreos:\n",
" etcd2:\n",
" discovery: ",
{
"Ref": "DiscoveryURL"
},
"\n",
" advertise-client-urls: http://$",
{
"Ref": "AdvertisedIPAddress"
},
"_ipv4:2379\n",
" initial-advertise-peer-urls: http://$",
{
"Ref": "AdvertisedIPAddress"
},
"_ipv4:2380\n",
" listen-client-urls: http://0.0.0.0:2379,http://0.0.0.0:4001\n",
" listen-peer-urls: http://$",
{
"Ref": "AdvertisedIPAddress"
},
"_ipv4:2380\n",
" units:\n",
" - name: etcd2.service\n",
" command: start\n",
" - name: fleet.service\n",
" command: start\n"
]
]
}
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment