Skip to content

Instantly share code, notes, and snippets.

@blooper
Last active August 29, 2015 13:57
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 blooper/9907765 to your computer and use it in GitHub Desktop.
Save blooper/9907765 to your computer and use it in GitHub Desktop.
{
"AWSTemplateFormatVersion" : "2010-09-09",
"Description" : "Try CoreOS in VPC",
"Outputs" : {
"DiscoveryIP" : {
"Value" : { "Fn::GetAtt" : [ "DeliveryInstance1", "PublicIp" ] },
"Description" : "SSH to this IP address."
}
},
"Mappings": {
"RegionMap": {
"ap-northeast-1": { "CoreAMI": "ami-133a4512", "ALAMI": "ami-ebbfc2ea" },
"ap-southeast-1": { "CoreAMI": "ami-0abfef58", "ALAMI": "ami-727c2c20" },
"ap-southeast-2": { "CoreAMI": "ami-65e77f5f", "ALAMI": "ami-25c8501f" },
"eu-west-1": { "CoreAMI": "ami-6501f812", "ALAMI": "ami-bb21dfcc" },
"sa-east-1": { "CoreAMI": "ami-198c2e04", "ALAMI": "ami-3bde7c26" },
"us-east-1": { "CoreAMI": "ami-83a8b9ea", "ALAMI": "ami-51736438" },
"us-west-1": { "CoreAMI": "ami-1a82bc5f", "ALAMI": "ami-e6f1cfa3" },
"us-west-2": { "CoreAMI": "ami-4299f172", "ALAMI": "ami-60f69f50" }
}
},
"Parameters": {
"AZ1" : {
"Description": "Availability Zone 1",
"Type": "String"
},
"AZ2" : {
"Description": "Availability Zone 2",
"Type": "String"
},
"AllowSSHFrom": {
"Default": "0.0.0.0/0",
"Description": "The net block (CIDR) that SSH is available to.",
"Type": "String"
},
"InstanceType": {
"AllowedValues": [
"t1.micro",
"m1.small", "m1.medium", "m1.large", "m1.xlarge",
"m3.medium", "m3.large", "m3.xlarge", "m3.2xlarge",
"m2.xlarge", "m2.2xlarge", "m2.4xlarge",
"c1.medium", "c1.xlarge",
"c3.large", "c3.xlarge", "c3.2xlarge", "c3.4xlarge", "c3.8xlarge",
"cc1.4xlarge", "cc2.8xlarge", "cg1.4xlarge",
"hi1.4xlarge", "hs1.8xlarge"
],
"ConstraintDescription": "must be a valid EC2 instance type.",
"Default": "t1.micro",
"Description": "EC2 instance type (m1.small, etc).",
"Type": "String"
},
"ClusterSize": {
"Default": "3",
"Description": "Number of nodes in cluster (2-12).",
"MaxValue": "12",
"MinValue": "2",
"Type": "Number"
},
"KeyPair": {
"Description": "The name of an EC2 Key Pair to allow SSH access to the instance.",
"Type": "String"
}
},
"Resources" : {
"CoreVPC" : {
"Type" : "AWS::EC2::VPC",
"Properties" : {
"CidrBlock" : "10.0.0.0/22",
"EnableDnsSupport" : true,
"EnableDnsHostnames" : true,
"Tags" : [ {"Key" : "name", "Value" : { "Ref": "AWS::StackName" } } ]
}
},
"PublicRTB" : {
"Type" : "AWS::EC2::RouteTable",
"Properties" : {
"VpcId" : { "Ref" : "CoreVPC" }
}
},
"CoreIGW" : {
"Type" : "AWS::EC2::InternetGateway",
"Properties" : {
"Tags" : [ {"Key" : "name", "Value" : { "Ref": "AWS::StackName" } } ]
}
},
"CoreGWAttach" : {
"Type" : "AWS::EC2::VPCGatewayAttachment",
"Properties" : {
"InternetGatewayId" : { "Ref" : "CoreIGW" },
"VpcId" : { "Ref" : "CoreVPC" }
}
} ,
"PublicRule" : {
"Type" : "AWS::EC2::Route",
"Properties" : {
"DestinationCidrBlock" : "0.0.0.0/0",
"GatewayId" : { "Ref" : "CoreIGW" },
"RouteTableId" : { "Ref" : "PublicRTB" }
}
},
"PublicSubnet1" : {
"Type" : "AWS::EC2::Subnet",
"Properties" : {
"AvailabilityZone" : { "Ref": "AZ1" },
"CidrBlock" : "10.0.0.0/24",
"VpcId" : { "Ref" : "CoreVPC" }
}
},
"PublicSubnet2" : {
"Type" : "AWS::EC2::Subnet",
"Properties" : {
"AvailabilityZone" : { "Ref": "AZ2" },
"CidrBlock" : "10.0.1.0/24",
"VpcId" : { "Ref" : "CoreVPC" }
}
},
"PrivateSubnet1" : {
"Type" : "AWS::EC2::Subnet",
"Properties" : {
"AvailabilityZone" : { "Ref": "AZ1" },
"CidrBlock" : "10.0.2.0/24",
"VpcId" : { "Ref" : "CoreVPC" }
}
},
"PrivateSubnet2" : {
"Type" : "AWS::EC2::Subnet",
"Properties" : {
"AvailabilityZone" : { "Ref": "AZ2" },
"CidrBlock" : "10.0.3.0/24",
"VpcId" : { "Ref" : "CoreVPC" }
}
},
"STAssociation1" : {
"Type" : "AWS::EC2::SubnetRouteTableAssociation",
"Properties" : {
"RouteTableId" : { "Ref" : "PublicRTB" },
"SubnetId" : { "Ref" : "PublicSubnet1" }
}
},
"STAssociation2" : {
"Type" : "AWS::EC2::SubnetRouteTableAssociation",
"Properties" : {
"RouteTableId" : { "Ref" : "PublicRTB" },
"SubnetId" : { "Ref" : "PublicSubnet2" }
}
},
"CoreSG" : {
"Type" : "AWS::EC2::SecurityGroup",
"Properties" :
{
"GroupDescription" : "for CoreOS",
"SecurityGroupIngress" : [ {
"CidrIp" : { "Ref": "AllowSSHFrom" },
"FromPort" : "22",
"IpProtocol" : "6",
"ToPort" : "22"
} ],
"VpcId" : { "Ref" : "CoreVPC" }
}
},
"CoreSGIngress22" : {
"Type" : "AWS::EC2::SecurityGroupIngress",
"Properties" : {
"GroupId" : { "Fn::GetAtt" : [ "CoreSG", "GroupId" ] },
"SourceSecurityGroupId" : { "Fn::GetAtt" : [ "CoreSG", "GroupId" ] },
"FromPort" : "22",
"IpProtocol" : "6",
"ToPort" : "22"
}
},
"CoreSGIngress4001" : {
"Type" : "AWS::EC2::SecurityGroupIngress",
"Properties" : {
"GroupId" : { "Fn::GetAtt" : [ "CoreSG", "GroupId" ] },
"SourceSecurityGroupId" : { "Fn::GetAtt" : [ "CoreSG", "GroupId" ] },
"FromPort" : "4001",
"IpProtocol" : "6",
"ToPort" : "4001"
}
},
"CoreSGIngress7001" : {
"Type" : "AWS::EC2::SecurityGroupIngress",
"Properties" : {
"GroupId" : { "Fn::GetAtt" : [ "CoreSG", "GroupId" ] },
"SourceSecurityGroupId" : { "Fn::GetAtt" : [ "CoreSG", "GroupId" ] },
"FromPort" : "7001",
"IpProtocol" : "6",
"ToPort" : "7001"
}
},
"DeliveryInstance1" : {
"Type" : "AWS::EC2::Instance",
"Properties" : {
"InstanceType": { "Ref": "InstanceType" },
"ImageId" : { "Fn::FindInMap": [ "RegionMap", { "Ref": "AWS::Region" }, "ALAMI" ] },
"KeyName" : { "Ref": "KeyPair" },
"NetworkInterfaces" : [ {
"DeviceIndex" : "0",
"Description" : "CoreENI1",
"AssociatePublicIpAddress" : true,
"DeleteOnTermination" : true,
"GroupSet" : [ { "Fn::GetAtt" : [ "CoreSG", "GroupId" ] } ],
"SubnetId" : { "Ref" : "PublicSubnet1" }
} ],
"UserData" : { "Fn::Base64" : { "Fn::Join" : ["", [
"#!/bin/bash\n",
"cd /root\n",
"yum -y install golang git\n",
"git clone https://github.com/coreos/etcd.git\n",
"cd etcd\n",
"./build\n",
"cd ..\n",
"git clone https://github.com/coreos/fleet.git\n",
"cd fleet\n",
"./build\n",
"cd ..\n",
"cp */bin/* /usr/local/bin\n",
"/usr/local/bin/etcd -addr `curl -s http://169.254.169.254/latest/meta-data/local-ipv4`:4001 -v > /var/log/etcd.log &\n"
]]}},
"Tags" : [ {"Key" : "name", "Value" : { "Ref": "AWS::StackName" } } ]
}
},
"CoreASG": {
"Type": "AWS::AutoScaling::AutoScalingGroup",
"Properties": {
"VPCZoneIdentifier" : [ { "Ref" : "PrivateSubnet1" }, { "Ref" : "PrivateSubnet2" } ],
"AvailabilityZones" : [
{ "Fn::GetAtt" : [ "PrivateSubnet1", "AvailabilityZone" ] },
{ "Fn::GetAtt" : [ "PrivateSubnet2", "AvailabilityZone" ] }
],
"DesiredCapacity": { "Ref": "ClusterSize" },
"LaunchConfigurationName": { "Ref": "CoreConfig" },
"MaxSize": "12",
"MinSize": "2",
"Tags": [ {
"Key": "Name",
"PropagateAtLaunch": true,
"Value": { "Ref": "AWS::StackName" }
} ]
}
},
"CoreConfig": {
"Type": "AWS::AutoScaling::LaunchConfiguration",
"Properties": {
"ImageId": { "Fn::FindInMap": [ "RegionMap", { "Ref": "AWS::Region" }, "CoreAMI" ] },
"InstanceType": { "Ref": "InstanceType" },
"KeyName": { "Ref": "KeyPair" },
"SecurityGroups": [ { "Fn::GetAtt" : [ "CoreSG", "GroupId" ] } ],
"UserData": { "Fn::Base64": { "Fn::Join": [ "", [
"#cloud-config\n\n",
"coreos:\n",
" etcd:\n",
{ "Fn::Join": [ "", [ " discovery: http://", { "Fn::GetAtt" : [ "DeliveryInstance1", "PrivateIp" ] }, ":4001/v2/keys/machines\n" ] ] },
" addr: $private_ipv4:4001\n",
" peer-addr: $private_ipv4:7001\n",
" units:\n",
" - name: etcd.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