{
  "AWSTemplateFormatVersion" : "2010-09-09",

  "Description": "Nuxeo installation.",

  "Parameters": {
    "InstanceType": {
      "Description": "Type of EC2 instance to launch",
      "Type": "String",
      "Default": "c3.large"
    },
    "KeyName": {
      "Description": "Name of an existing EC2 KeyPair to enable SSH access to the instances",
      "Type": "String"
    }
  },

  "Mappings": {
    "AWSInstanceType2Arch": {
      "t1.micro"    : { "Arch": "64" },
      "m1.small"    : { "Arch" : "64" },
      "m1.large"    : { "Arch" : "64" },
      "m1.xlarge"   : { "Arch" : "64" },
      "m2.xlarge"   : { "Arch" : "64" },
      "m2.2xlarge"  : { "Arch" : "64" },
      "m2.4xlarge"  : { "Arch" : "64" },
      "c1.medium"   : { "Arch" : "64" },
      "c1.xlarge"   : { "Arch" : "64" },
      "cc1.4xlarge" : { "Arch" : "64" },
      "c3.large"    : { "Arch" : "64" }
    }, 
    "AWSRegionArch2AMI": {
      "us-west-1": { "64": "ami-73f7da13" },
      "us-west-2": { "64": "ami-835b4efa" },
      "us-east-1": { "64": "ami-d15a75c7" },
      "us-east-2": { "64": "ami-8b92b4ee" },
      "eu-west-1": { "64": "ami-6d48500b" },
      "eu-west-2": { "64": "ami-cc7066a8" },
      "eu-central-1": { "64": "ami-1c45e273" },
      "ap-northeast-1": { "64": "ami-785c491f" },
      "ap-northeast-2": { "64": "ami-94d20dfa" },
      "ap-southeast-1": { "64": "ami-2378f540" },
      "ap-southeast-2": { "64": "ami-e94e5e8a" },
      "ap-south-1": { "64": "ami-49e59a26" },
      "sa-east-1": { "64": "ami-34afc458" },
      "ca-central-1": { "64": "ami-7ed56a1a" }
    }
  },

  "Resources": {

    "nuxeoinstance": {
      "Type": "AWS::EC2::Instance",
      "Properties": {
        "InstanceType": { "Ref": "InstanceType" },
        "SecurityGroups": [ { "Ref": "nuxeo" }, "default"  ],
        "KeyName": { "Ref": "KeyName" },
        "ImageId": { "Fn::FindInMap" : [ "AWSRegionArch2AMI", { "Ref": "AWS::Region" },
                            { "Fn::FindInMap": [ "AWSInstanceType2Arch", { "Ref": "InstanceType" }, "Arch" ] } ] },
        "UserData": { "Fn::Base64": "#!/bin/bash\n\nadd-apt-repository -y ppa:alestic/ppa && apt-get update && apt-get install -y runurl\nrunurl https://nuxeo.s3.amazonaws.com/scripts/NuxeoFT_single-20170706-085927\n\n" }
    }
    },

    "nuxeoip": {
      "Type": "AWS::EC2::EIP",
      "Properties": {
        "InstanceId": { "Ref" : "nuxeoinstance" }
      }
    },

    "nuxeo": {
      "Type": "AWS::EC2::SecurityGroup",
      "Properties": {
        "GroupDescription": "Allow ports 22 (SSH) and 80 (HTTP)",
        "SecurityGroupIngress": [ {
          "IpProtocol": "tcp",
          "FromPort": "22",
          "ToPort": "22",
          "CidrIp": "0.0.0.0/0"
        },
        {
          "IpProtocol": "tcp",
          "FromPort": "80",
          "ToPort": "80",
          "CidrIp": "0.0.0.0/0"
        } ]
      }
    }

  },

 "Outputs": {
    "URL": {
      "Value" : { "Fn::Join" : [ "", [ "http://", { "Ref" : "nuxeoip" }, "/" ]]},
      "Description": "Nuxeo URL"
    }
  }

}

