{ "Description": "A simple Docker Swarm cluster outline. No overlay networking. Single manager. Single VPC, subnet, availability zone. Best used for flat-file engine discovery.", "AWSTemplateFormatVersion": "2010-09-09", "Parameters": { "NamePrefix": { "Description": "Prefix for resource Name tags.", "Type": "String", "Default": "Swarm-" }, "AvailabilityZone": { "Description": "The target availability zone.", "Type": "String", "MaxLength": "1", "MinLength": "0", "AllowedPattern": "^[a-z]+$", "Default": "a" }, "ClusterName": { "Description": "Name of the Swarm cluster.", "Type": "String", "Default": "default" }, "KeyName": { "Description": "Name of the SSH KeyPair.", "Type": "String", "Default": "" }, "ManagerInstanceType": { "Description": "The instance type to use for the manager node.", "Type": "String", "Default": "m3.medium" }, "NodeInstanceType": { "Description": "The instance type to use for nodes.", "Type": "String", "Default": "t2.micro" }, "NodeAMI": { "Description": "The AMI to use for all nodes.", "Type": "String", "Default": "" }, "NodeCount": { "Description": "The number of nodes to create.", "Type": "String", "Default": "2" } }, "Outputs": { "Manager16" : { "Description" : "The public IP address of the manager.", "Value" : { "Fn::GetAtt" : [ "ManagerInstance", "PublicIp" ]} } }, "Resources": { "Vpc": { "Type": "AWS::EC2::VPC", "Properties": { "EnableDnsHostnames": "true", "EnableDnsSupport": "true", "CidrBlock": "10.0.128.0/17", "Tags": [ { "Key": "Name", "Value": { "Fn::Join": [ "-", [{ "Ref":"NamePrefix" }, "VPC"] ] } }, { "Value": { "Ref": "AWS::StackName" }, "Key": "Application" }, { "Value": "Public", "Key": "Network" } ] } }, "InternetGateway": { "DependsOn": "Vpc", "Type": "AWS::EC2::InternetGateway", "Properties": { "Tags": [ { "Key": "Name", "Value": { "Fn::Join": [ "", [{ "Ref":"NamePrefix" }, "IG"] ] } }, { "Value": { "Ref": "AWS::StackName" }, "Key": "Application" }, { "Value": "Public", "Key": "Network" } ] } }, "GatewayToInternet": { "DependsOn": "InternetGateway", "Type": "AWS::EC2::VPCGatewayAttachment", "Properties": { "VpcId": { "Ref": "Vpc" }, "InternetGatewayId": { "Ref": "InternetGateway" } } }, "PublicSubnet": { "Type": "AWS::EC2::Subnet", "Properties": { "VpcId": { "Ref": "Vpc" }, "AvailabilityZone": { "Fn::Join": [ "", [ { "Ref": "AWS::Region" }, { "Ref": "AvailabilityZone" } ] ] }, "MapPublicIpOnLaunch": "true", "CidrBlock": "10.0.128.0/17", "Tags": [ { "Key": "Name", "Value": { "Fn::Join": [ "", [{ "Ref":"NamePrefix" }, "PublicSubnet"] ] } }, { "Value": { "Ref": "AWS::StackName" }, "Key": "Application" }, { "Value": "Public", "Key": "Network" } ] } }, "PublicRouteTable": { "Type": "AWS::EC2::RouteTable", "Properties": { "Tags": [ { "Key": "Name", "Value": { "Fn::Join": [ "", [{ "Ref":"NamePrefix" }, "PublicRoutes"] ] } }, { "Value": { "Ref": "AWS::StackName" }, "Key": "Application" }, { "Value": "Public", "Key": "Network" } ], "VpcId": { "Ref": "Vpc" } } }, "PublicRoute": { "DependsOn": "GatewayToInternet", "Type": "AWS::EC2::Route", "Properties": { "DestinationCidrBlock": "0.0.0.0\/0", "GatewayId": { "Ref": "InternetGateway" }, "RouteTableId": { "Ref": "PublicRouteTable" } } }, "PublicSubnetRouteTableAssociation": { "Type": "AWS::EC2::SubnetRouteTableAssociation", "Properties": { "SubnetId": { "Ref": "PublicSubnet" }, "RouteTableId": { "Ref": "PublicRouteTable" } } }, "InfraSecurityGroup": { "Type": "AWS::EC2::SecurityGroup", "Properties": { "GroupDescription": { "Ref": "AWS::StackName" }, "SecurityGroupEgress": [ { "CidrIp": "0.0.0.0/0", "FromPort": 0, "IpProtocol": "tcp", "ToPort": 65535 }, { "CidrIp": "0.0.0.0/0", "FromPort": 0, "IpProtocol": "udp", "ToPort": 65535 } ], "SecurityGroupIngress": [ { "CidrIp": "0.0.0.0/0", "FromPort": 3, "IpProtocol": "icmp", "ToPort": -1 }, { "CidrIp": "0.0.0.0/0", "FromPort": 22, "IpProtocol": "tcp", "ToPort": 22 }, { "CidrIp": "10.0.0.0/16", "FromPort": 0, "IpProtocol": "tcp", "ToPort": 65535 } ], "Tags": [ { "Key": "SwarmCluster", "Value": { "Ref": "ClusterName" } } ], "VpcId": { "Ref": "Vpc" } } }, "ManagerInterface": { "Type" : "AWS::EC2::NetworkInterface", "DependsOn": "GatewayToInternet", "Properties" : { "Description" : "Private IP for the Swarm cluster manager discovering on /16.", "GroupSet" : [ { "Ref": "InfraSecurityGroup" } ], "PrivateIpAddress" : "10.0.128.10", "SubnetId" : { "Ref": "PublicSubnet" }, "Tags": [ { "Key": "SwarmCluster", "Value": { "Ref": "ClusterName" } }, { "Key": "Name", "Value": { "Fn::Join": [ "-", [{ "Ref":"NamePrefix" }, "manager-interface-16"]]} } ] } }, "ManagerInstance": { "Type": "AWS::EC2::Instance", "DependsOn" : ["GatewayToInternet", "ManagerInterface"], "Properties": { "ImageId": { "Ref": "NodeAMI" }, "InstanceType": { "Ref": "ManagerInstanceType" }, "KeyName": { "Ref": "KeyName" }, "AvailabilityZone": { "Fn::Join": [ "", [ { "Ref": "AWS::Region" }, { "Ref": "AvailabilityZone" } ] ] }, "BlockDeviceMappings": [ { "DeviceName": "/dev/xvda", "Ebs": { "VolumeSize": "30", "VolumeType": "gp2" } } ], "NetworkInterfaces": [ {"NetworkInterfaceId": { "Ref":"ManagerInterface" }, "DeviceIndex": "0" } ], "Tags": [ { "Key": "SwarmCluster", "Value": { "Ref": "ClusterName" } }, { "Key": "Name", "Value": { "Fn::Join": [ "-", [{ "Ref":"NamePrefix" }, "manager-16"]]} } ], "UserData": { "Fn::Base64": { "Fn::Join": [ "", [ "#!/bin/sh\n", "sudo rm /etc/docker/key.json\n", "sudo systemctl restart docker\n" ] ] } } } }, "NodeLC": { "Type": "AWS::AutoScaling::LaunchConfiguration", "Properties": { "ImageId": { "Ref": "NodeAMI" }, "InstanceType": { "Ref": "NodeInstanceType" }, "SecurityGroups": [{ "Ref": "InfraSecurityGroup" }], "KeyName": { "Ref": "KeyName" }, "BlockDeviceMappings": [ { "DeviceName": "/dev/sda1", "Ebs": { "VolumeSize": "30", "VolumeType": "gp2" } } ], "UserData": { "Fn::Base64": { "Fn::Join": [ "", [ "#!/bin/sh\n", "sudo rm /etc/docker/key.json\n", "sudo systemctl restart docker\n" ] ] } } } }, "NodeASG": { "Type": "AWS::AutoScaling::AutoScalingGroup", "DependsOn" : ["GatewayToInternet"], "Properties": { "AvailabilityZones": [ { "Fn::Join": [ "", [ { "Ref": "AWS::Region" }, { "Ref": "AvailabilityZone" } ] ] } ], "DesiredCapacity": { "Ref": "NodeCount" }, "MaxSize": { "Ref": "NodeCount" }, "MinSize": { "Ref": "NodeCount" }, "HealthCheckGracePeriod": 600, "HealthCheckType": "EC2", "LaunchConfigurationName": { "Ref": "NodeLC" }, "VPCZoneIdentifier": [ { "Ref": "PublicSubnet" } ], "Tags": [ { "Key": "SwarmCluster", "PropagateAtLaunch": "true", "Value": { "Ref": "ClusterName" } }, { "Key": "Name", "PropagateAtLaunch": "true", "Value": "swarm-node" } ] } } } }