{
  "AWSTemplateFormatVersion" : "2010-09-09",
  "Description" : "ArcGIS CloudFormation Template: Provisions an Elastic Load Balancer for ArcGIS Server. **WARNING** You will be billed by AWS for the AWS resources if you create a stack from this template.",
  "Parameters" : {
    "SSLCertificateARN": {
      "Description": "ARN of the SSL certificate issued to the site domain",
      "Type": "String",
      "AllowedPattern": "[^\"]{1,1024}",
      "ConstraintDescription": "arn:aws:acm:<region>:<account-id>:certificate/<resource>"
    },
    "VPCId" : {
      "Description" : "VPC ID",
      "Type" : "AWS::EC2::VPC::Id" 
    },
    "Subnet1" : {
      "Description" : "Subnet 1",
      "Type": "AWS::EC2::Subnet::Id"
    },
    "Subnet2" : {
      "Description" : "Subnet 2",
      "Type": "AWS::EC2::Subnet::Id"
    }
  },
  "Resources" : {
    "ELB" : {
      "Type" : "AWS::ElasticLoadBalancing::LoadBalancer",
      "Properties" : {
        "Subnets" : [ {"Ref" : "Subnet1"}, {"Ref" : "Subnet2"} ],
        "SecurityGroups" : [ {"Ref" : "ELBSecurityGroup"} ],
        "Scheme" : "internet-facing",
        "Listeners" : [ {
          "LoadBalancerPort" : "80",
          "InstancePort" : "6080",
          "Protocol" : "HTTP"
        }, {
          "LoadBalancerPort" : "443",
          "InstancePort" : "6443",
          "Protocol" : "HTTPS",
          "InstanceProtocol" : "HTTPS",
          "SSLCertificateId" : {"Ref" : "SSLCertificateARN"}
        } ],
        "HealthCheck" : {
          "Target" : "HTTPS:6443/arcgis/rest/info/healthcheck",
          "HealthyThreshold" : "3",
          "UnhealthyThreshold" : "5",
          "Interval" : "30",
          "Timeout" : "5"
        }
      }
    },
    "ELBSecurityGroup" : {
      "Type" : "AWS::EC2::SecurityGroup",
      "Properties" : {
        "GroupDescription" : {"Ref" : "AWS::StackName"},
        "VpcId" : {"Ref" : "VPCId"},
        "SecurityGroupIngress" : [ {
          "IpProtocol" : "tcp",
          "FromPort" : "80",
          "ToPort" : "80",
          "CidrIp" : "0.0.0.0/0"
        }, {
          "IpProtocol" : "tcp",
          "FromPort" : "443",
          "ToPort" : "443",
          "CidrIp" : "0.0.0.0/0"
        } ]
      }
    }
  },
  "Outputs" : {
    "ELBName" : {
      "Description" : "Elastic Load Balancer name",
      "Value" :  {"Ref" : "ELB"}
    },
    "DNSName" : {
      "Description" : "Elastic Load Balancer DNS name",
      "Value" :  {"Fn::GetAtt" : ["ELB", "DNSName"]}
    }
  }
}
