{
  "AWSTemplateFormatVersion": "2010-09-09",
  "Parameters": {
    "KeyName": {
      "Type": "AWS::EC2::KeyPair::KeyName"
    },
    "Route53HostedZone": {
      "Type": "String"
    },
    "PublicHostedZone": {
      "Type": "String"
    },
    "AmiId": {
      "Type": "AWS::EC2::Image::Id"
    },
    "InstanceType": {
      "Type": "String",
      "Default": "m4.2xlarge"
    },
    "NodeRootVolSize": {
      "Type": "String",
      "Default": "30"
    },
    "NodeDockerVolSize": {
      "Type": "String",
      "Default": "25"
    },
    "NodeDockerVolType": {
      "Type": "String",
      "Default": "gp2"
    },
    "GlusterVolType": {
      "Type": "String",
      "Default": "gp2"
    },
    "GlusterVolSize": {
      "Type": "Number",
      "Default": "500"
    },
    "Iops": {
      "Type": "Number"
    },
    "NodeUserData": {
      "Type": "String"
    },
    "NodeEmptyVolSize": {
      "Type": "String",
      "Default": "25"
    },
    "NodeEmptyVolType": {
      "Type": "String",
      "Default": "gp2"
    },
    "NodeRootVolType": {
      "Type": "String",
      "Default": "gp2"
    },
    "PublicHostedZone": {
      "Type": "String"
    },
    "NodeInstanceProfile": {
      "Type": "String"
    },
    "NodeType": {
      "Type": "String",
      "Default": "gluster"
    },
    "GlusterNodeDns1": {
      "Type": "String"
    },
    "GlusterNodeDns2": {
      "Type": "String"
    },
    "GlusterNodeDns3": {
      "Type": "String"
    },
    "PrivateSubnet1": {
      "Type": "String"
    },
    "PrivateSubnet2": {
      "Type": "String"
    },
    "PrivateSubnet3": {
      "Type": "String"
    },
    "NodeSg": {
      "Type": "String"
    }
  },
  "Resources": {
    "Route53Records": {
      "Type": "AWS::Route53::RecordSetGroup",
      "DependsOn": [
        "GlusterNode1",
        "GlusterNode2",
        "GlusterNode3"
      ],
      "Properties": {
        "HostedZoneName": { "Ref": "Route53HostedZone" },
        "RecordSets": [
          {
            "Name":  {"Fn::Join": [".", [{"Ref": "GlusterNodeDns1"},{"Ref": "Route53HostedZone"}]]},
            "Type": "A",
	            "TTL": "300",
		    "ResourceRecords": [{ "Fn::GetAtt" : ["GlusterNode1", "PrivateIp"] }]
          },
          {
            "Name":  {"Fn::Join": [".", [{"Ref": "GlusterNodeDns2"},{"Ref": "Route53HostedZone"}]]},
            "Type": "A",
	            "TTL": "300",
		    "ResourceRecords": [{ "Fn::GetAtt" : ["GlusterNode2", "PrivateIp"] }]
          },
          {
            "Name":  {"Fn::Join": [".", [{"Ref": "GlusterNodeDns3"},{"Ref": "Route53HostedZone"}]]},
            "Type": "A",
	            "TTL": "300",
		    "ResourceRecords": [{ "Fn::GetAtt" : ["GlusterNode3", "PrivateIp"] }]
          }
        ]
      }
    },
    "GlusterNode1" : {
       "Type" : "AWS::EC2::Instance",
       "Properties" : {
          "ImageId" : {"Ref": "AmiId"},
          "UserData": {"Ref": "NodeUserData"},
          "KeyName" : {"Ref": "KeyName"},
	  "InstanceType": {"Ref": "InstanceType"},
	  "SecurityGroupIds": [{"Ref": "NodeSg"}],
          "SubnetId" : {"Ref": "PrivateSubnet1"},
          "IamInstanceProfile": { "Ref": "NodeInstanceProfile" },
          "Tags": [
            { "Key": "Name",
              "Value": {"Fn::Join": [".", [{"Ref": "GlusterNodeDns1"},{"Ref": "PublicHostedZone"}]]}
            },
            { "Key": "provision",
              "Value": "node"
            },
            { "Key": "openshift-role",
              "Value": "storage" 
            }
          ],
          "BlockDeviceMappings" : [
          {
            "DeviceName": "/dev/sda1",
            "Ebs": {
              "DeleteOnTermination": "true",
              "VolumeSize": {"Ref": "NodeRootVolSize"},
              "VolumeType": {"Ref": "NodeRootVolType"}
            }
          },
          {
            "DeviceName": "/dev/xvdb",
            "Ebs": {
              "DeleteOnTermination": "true",
              "VolumeSize": {"Ref": "NodeDockerVolSize"},
              "VolumeType": {"Ref": "NodeDockerVolType"}
            }
          },
          {
            "DeviceName": "/dev/xvdc",
            "Ebs": {
              "DeleteOnTermination": "true",
              "VolumeSize": {"Ref": "NodeEmptyVolSize"},
              "VolumeType": {"Ref": "NodeEmptyVolType"}
            }
          },
          {
            "DeviceName": "/dev/xvdd",
            "Ebs": {
              "DeleteOnTermination": "true",
              "VolumeSize": {"Ref": "GlusterVolSize"},
              "VolumeType": {"Ref": "GlusterVolType"},
              "Iops": {"Ref": "Iops"}
            }
          }
         ]
     }
   },
    "GlusterNode2" : {
       "Type" : "AWS::EC2::Instance",
       "Properties" : {
          "ImageId" : {"Ref": "AmiId"},
          "UserData": {"Ref": "NodeUserData"},
          "KeyName" : {"Ref": "KeyName"},
	  "InstanceType": {"Ref": "InstanceType"},
	  "SecurityGroupIds": [{"Ref": "NodeSg"}],
	  "SecurityGroupIds": [{"Ref": "NodeSg"}],
          "SubnetId" : {"Ref": "PrivateSubnet2"},
          "IamInstanceProfile": { "Ref": "NodeInstanceProfile" },
          "Tags": [
            { "Key": "Name",
              "Value": {"Fn::Join": [".", [{"Ref": "GlusterNodeDns2"},{"Ref": "PublicHostedZone"}]]}
            },
            { "Key": "provision",
              "Value": "node"
            },
            { "Key": "openshift-role",
              "Value": "storage" 
            }
          ],
          "BlockDeviceMappings" : [
          {
            "DeviceName": "/dev/sda1",
            "Ebs": {
              "DeleteOnTermination": "true",
              "VolumeSize": {"Ref": "NodeRootVolSize"},
              "VolumeType": {"Ref": "NodeRootVolType"}
            }
          },
          {
            "DeviceName": "/dev/xvdb",
            "Ebs": {
              "DeleteOnTermination": "true",
              "VolumeSize": {"Ref": "NodeDockerVolSize"},
              "VolumeType": {"Ref": "NodeDockerVolType"}
            }
          },
          {
            "DeviceName": "/dev/xvdc",
            "Ebs": {
              "DeleteOnTermination": "true",
              "VolumeSize": {"Ref": "NodeEmptyVolSize"},
              "VolumeType": {"Ref": "NodeEmptyVolType"}
            }
          },
          {
            "DeviceName": "/dev/xvdd",
            "Ebs": {
              "DeleteOnTermination": "true",
              "VolumeSize": {"Ref": "GlusterVolSize"},
              "VolumeType": {"Ref": "GlusterVolType"},
              "Iops": {"Ref": "Iops"}
            }
          }
         ]
     }
   },
    "GlusterNode3" : {
       "Type" : "AWS::EC2::Instance",
       "Properties" : {
          "ImageId" : {"Ref": "AmiId"},
          "UserData": {"Ref": "NodeUserData"},
          "KeyName" : {"Ref": "KeyName"},
	  "InstanceType": {"Ref": "InstanceType"},
	  "SecurityGroupIds": [{"Ref": "NodeSg"}],
          "SubnetId" : {"Ref": "PrivateSubnet3"},
          "IamInstanceProfile": { "Ref": "NodeInstanceProfile" },
          "Tags": [
            { "Key": "Name",
              "Value": {"Fn::Join": [".", [{"Ref": "GlusterNodeDns3"},{"Ref": "PublicHostedZone"}]]}
            },
            { "Key": "provision",
              "Value": "node"
            },
            { "Key": "openshift-role",
              "Value": "storage"
            }
          ],
          "BlockDeviceMappings" : [
          {
            "DeviceName": "/dev/sda1",
            "Ebs": {
              "DeleteOnTermination": "true",
              "VolumeSize": {"Ref": "NodeRootVolSize"},
              "VolumeType": {"Ref": "NodeRootVolType"}
            }
          },
          {
            "DeviceName": "/dev/xvdb",
            "Ebs": {
              "DeleteOnTermination": "true",
              "VolumeSize": {"Ref": "NodeDockerVolSize"},
              "VolumeType": {"Ref": "NodeDockerVolType"}
            }
          },
          {
            "DeviceName": "/dev/xvdc",
            "Ebs": {
              "DeleteOnTermination": "true",
              "VolumeSize": {"Ref": "NodeEmptyVolSize"},
              "VolumeType": {"Ref": "NodeEmptyVolType"}
            }
          },
          {
            "DeviceName": "/dev/xvdd",
            "Ebs": {
              "DeleteOnTermination": "true",
              "VolumeSize": {"Ref": "GlusterVolSize"},
              "VolumeType": {"Ref": "GlusterVolType"},
              "Iops": {"Ref": "Iops"}
            }
          }
         ]
     }
   }
 }
}
