---
heat_template_version: 2013-05-23
description: "A simple template to boot a cluster of desktops (LoginNode, ManagementNodes and Desktop Nodes)"
# avz parameters disabled. they are working but I want just more options than monash-02. I would like to have a parameter that says "I don't care"

parameters:
  ubuntu_1804_image_id:
    type: string
    label: Image ID
    description: Ubuntu Image
    default: 99d9449a-084f-4901-8bd8-c04aebd589ca
  centos_7_image_id:
    type: string
    label: Image ID
    description: Centos Image
    default: c47c3acb-9657-4243-9e14-e6c676157e3b #with NetworkManager
  rhel_77_image_id:
    type: string
    label: Image ID
    description: Rhel Image
    default: 19993115-ad60-4979-bdfb-67ae7a77e40c
  ssh_key:
    type: string
    default: gc_key
  avz:
    type: string
    default: monash-02
  project_name:
    type: string
  NetID:
    type: string
    default: Classic Provider
  Flavour:
    type: string
    default: m3.xsmall


resources:

  SlurmSecGroup:
   type: "OS::Neutron::SecurityGroup"
   properties:
     name: "heatslurmsecgroup"
     rules: [ { protocol: tcp,
               port_range_min: 12000,
               port_range_max: 12999},
              { protocol: tcp,
               port_range_min: 6817,
               port_range_max: 6819},
              { protocol: tcp,
               port_range_min: 1019,
               port_range_max: 1019}]
  NFSSecGroup:
   type: "OS::Neutron::SecurityGroup"
   properties:
     name: "heatnfssecgroup"
     rules: [ { protocol: tcp,
               port_range_min: 2049,
               port_range_max: 2049,
               remote_mode: "remote_group_id"},
              { protocol: tcp,
               port_range_min: 111,
               port_range_max: 111,
               remote_mode: "remote_group_id"},
              { protocol: udp,
               port_range_min: 2049,
               port_range_max: 2049,
               remote_mode: "remote_group_id"},
              { protocol: udp,
               port_range_min: 111,
               port_range_max: 111,
               remote_mode: "remote_group_id"} ]
  MySQLSecGroup:
   type: "OS::Neutron::SecurityGroup"
   properties:
     name: "heatmysqlsecgroup"
     rules: [ { protocol: tcp,
               port_range_min: 3306,
               port_range_max: 3306,
               remote_mode: "remote_group_id"} ]
  SSHMonashSecGroup:
   type: "OS::Neutron::SecurityGroup"
   properties:
     name: "SSHMonashSecGroup"
     rules: [ { protocol: tcp,
               port_range_min: 22,
               port_range_max: 22,
               direction: ingress,
               remote_ip_prefix: 59.191.208.0/20
     },
     { protocol: tcp,
               port_range_min: 22,
               port_range_max: 22,
               direction: ingress,
               remote_ip_prefix: 114.30.64.0/21
     },
     { protocol: tcp,
               port_range_min: 22,
               port_range_max: 22,
               direction: ingress,
               remote_ip_prefix: 118.138.0.0/16
     },
     { protocol: tcp,
               port_range_min: 22,
               port_range_max: 22,
               direction: ingress,
               remote_ip_prefix: 118.139.0.0/17
     },
     { protocol: tcp,
               port_range_min: 22,
               port_range_max: 22,
               direction: ingress,
               remote_ip_prefix: 130.194.0.0/16
     },
     { protocol: tcp,
               port_range_min: 22,
               port_range_max: 22,
               direction: ingress,
               remote_ip_prefix: 203.0.141.0/24
     },
     { protocol: tcp,
               port_range_min: 22,
               port_range_max: 22,
               direction: ingress,
               remote_ip_prefix: 203.6.141.0/24
     },
     { protocol: tcp,
               port_range_min: 22,
               port_range_max: 22,
               direction: ingress,
               remote_ip_prefix: 203.23.136.0/24
     },
     { protocol: tcp,
               port_range_min: 22,
               port_range_max: 22,
               direction: ingress,
               remote_ip_prefix: 59.191.192.0/20
     },
     { protocol: tcp,
               port_range_min: 22,
               port_range_max: 22,
               direction: ingress,
               remote_ip_prefix: 202.158.212.32/27
     },
     { protocol: tcp,
               port_range_min: 22,
               port_range_max: 22,
               direction: ingress,
               remote_ip_prefix: 130.194.13.96/27
     },
     { protocol: tcp,
               port_range_min: 22,
               port_range_max: 22,
               direction: ingress,
               remote_ip_prefix: 49.127.0.0/16
     },
     { protocol: tcp,
               port_range_min: 22,
               port_range_max: 22,
               direction: ingress,
               remote_ip_prefix: 202.58.246.0/24
     },
     { protocol: tcp,
               port_range_min: 22,
               port_range_max: 22,
               direction: ingress,
               remote_ip_prefix: 202.94.69.0/24
     },
     { protocol: tcp,
               port_range_min: 22,
               port_range_max: 22,
               direction: ingress,
               remote_ip_prefix: 103.35.228.0/22
     },
     { protocol: tcp,
               port_range_min: 22,
               port_range_max: 22,
               direction: ingress,
               remote_ip_prefix: 43.246.232.0/22
     },
     { protocol: tcp,
               port_range_min: 22,
               port_range_max: 22,
               direction: ingress,
               remote_ip_prefix: 103.35.228.0/22
     },
     { protocol: tcp,
               port_range_min: 22,
               port_range_max: 22,
               direction: ingress,
               remote_ip_prefix: 59.191.208.0/20
     },
     { protocol: tcp,
               port_range_min: 22,
               port_range_max: 22,
               direction: ingress,
               remote_ip_prefix: 49.127.0.0/16
     },
     { protocol: tcp,
               port_range_min: 22,
               port_range_max: 22,
               direction: ingress,
               remote_ip_prefix: 59.191.220.0/22
     },
     { protocol: tcp,
               port_range_min: 22,
               port_range_max: 22,
               direction: ingress,
               remote_ip_prefix: 43.246.232.0/22
     } ]

  webaccess:
   type: "OS::Neutron::SecurityGroup"
   properties:
     name: "webaccess"
     rules: [ { protocol: tcp,
               port_range_min: 80,
               port_range_max: 80},
              { protocol: tcp,
               port_range_min: 443,
               port_range_max: 443} ]

  SQLNode0:
   type: "OS::Nova::Server"
   properties:
    name:
     list_join: [ '-', [ { get_param: "OS::stack_name" }, 'sql0' ]]
    availability_zone: { get_param: avz }
    flavor: m3.xsmall
    image: { get_param: centos_7_image_id }
    key_name: { get_param: ssh_key }
    security_groups: [ default, { get_resource: SSHMonashSecGroup }, { get_resource: SlurmSecGroup }, { get_resource: MySQLSecGroup }, { get_resource: NFSSecGroup } ]
    metadata:
     ansible_host_groups: [ SQLNodes, NFSNodes ]
     ansible_ssh_user: ubuntu
     project_name: { get_param: project_name }
    networks:
      - network: { get_param: NetID }

  NFSVolume:
   type: OS::Cinder::Volume
   properties:
    availability_zone: { get_param: avz }
    size: 1
    name: nfsvol
  NFSVolumeAttachment:
   type: "OS::Cinder::VolumeAttachment"
   properties:
    volume_id: { get_resource: NFSVolume }
    instance_uuid: { get_resource: SQLNode0 }

  SLURMSTATEVolume:
   type: OS::Cinder::Volume
   properties:
    availability_zone: { get_param: avz }
    size: 1
    name: slurmstate
  SLURMSTATEVolumeAttachment:
   type: "OS::Cinder::VolumeAttachment"
   properties:
    volume_id: { get_resource: SLURMSTATEVolume }
    instance_uuid: { get_resource: SQLNode0 }

  DBVolume:
   type: OS::Cinder::Volume
   properties:
    availability_zone: { get_param: avz }
    size: 10
    name: dbvol
  DBVolumeAttachment:
   type: "OS::Cinder::VolumeAttachment"
   properties:
    volume_id: { get_resource: DBVolume }
    instance_uuid: { get_resource: SQLNode0 }

  MgmtNodesC:
   type: "OS::Heat::ResourceGroup"
   properties:
    count: 1
    resource_def:
      type: My::Server::MgmtNode
      properties:
        #avz: { get_param: avz }
        image: { get_param: centos_7_image_id }
        ansible_ssh_user: ec2-user
        mynodename:
         list_join: [ '-', [ { get_param: "OS::stack_name" }, 'mgmt%index%' ]]
        ssh_key: { get_param: ssh_key }
        security_groups: [ default, { get_resource: SSHMonashSecGroup }, { get_resource: SlurmSecGroup }, { get_resource: NFSSecGroup }, { get_resource: MySQLSecGroup } ]
        project_name: { get_param: project_name }

  MgmtNodesU:
   type: "OS::Heat::ResourceGroup"
   properties:
    count: 1
    resource_def:
      type: My::Server::MgmtNode
      properties:
        #avz: { get_param: avz }
        image: { get_param: ubuntu_1804_image_id }
        ansible_ssh_user: ubuntu
        mynodename:
         list_join: [ '-', [ { get_param: "OS::stack_name" }, 'mgmtU%index%' ]]
        ssh_key: { get_param: ssh_key }
        security_groups: [ default, { get_resource: SSHMonashSecGroup }, { get_resource: SlurmSecGroup }, { get_resource: NFSSecGroup }, { get_resource: MySQLSecGroup } ]
        project_name: { get_param: project_name }

  LoginNodesC:
   type: "OS::Heat::ResourceGroup"
   properties:
    count: 0
    resource_def:
     type: "OS::Nova::Server"
     properties:
      #availability_zone: { get_param: avz }
      flavor: m3.xsmall
      image: { get_param: centos_7_image_id }
      key_name: { get_param: ssh_key }
      name:
       list_join: [ '-', [ { get_param: "OS::stack_name" }, 'login%index%' ]]
      security_groups: [ default, { get_resource: SSHMonashSecGroup }, { get_resource: SlurmSecGroup }, { get_resource: NFSSecGroup } ]
      metadata:
       ansible_host_groups: [ LoginNodes ]
       ansible_ssh_user: ec2-user
       project_name: { get_param: project_name }
      networks:
       - network: { get_param: NetID }

  LoginNodesU:
   type: "OS::Heat::ResourceGroup"
   properties:
    count: 0
    resource_def:
     type: "OS::Nova::Server"
     properties:
      #availability_zone: { get_param: avz }
      flavor: m3.xsmall
      image: { get_param: ubuntu_1804_image_id }
      key_name: { get_param: ssh_key }
      name:
       list_join: [ '-', [ { get_param: "OS::stack_name" }, 'loginU%index%' ]]
      security_groups: [ default, { get_resource: SSHMonashSecGroup }, { get_resource: SlurmSecGroup }, { get_resource: NFSSecGroup } ]
      metadata:
       ansible_host_groups: [ LoginNodes ]
       ansible_ssh_user: ubuntu
       project_name: { get_param: project_name }
      networks:
       - network: { get_param: NetID }

  DesktopNodes:
   type: "OS::Heat::ResourceGroup"
   properties:
    count: 0
    resource_def:
     type: "OS::Nova::Server"
     properties:
      #availability_zone: { get_param: avz }
      flavor: m3.xsmall
      image: { get_param: centos_7_image_id }
      key_name: { get_param: ssh_key }
      name:
       list_join: [ '-', [ { get_param: "OS::stack_name" }, 'desktopc%index%' ]]
      security_groups: [ default, { get_resource: SSHMonashSecGroup }, { get_resource: SlurmSecGroup }, { get_resource: NFSSecGroup } ]
      metadata:
       ansible_host_groups: [ DesktopNodes, VisNodes, ComputeNodes ]
       ansible_ssh_user: ec2-user
       project_name: { get_param: project_name }
      networks:
       - network: { get_param: NetID }

  ComputeNodesU:
   type: "OS::Heat::ResourceGroup"
   properties:
    count: 0
    resource_def:
     type: "OS::Nova::Server"
     properties:
      #availability_zone: { get_param: avz }
      flavor: m3.xsmall
      image: { get_param: ubuntu_1804_image_id }
      key_name: { get_param: ssh_key }
      name:
       list_join: [ '-', [ { get_param: "OS::stack_name" }, 'computec7%index%' ]]
      security_groups: [ default, { get_resource: SSHMonashSecGroup }, { get_resource: SlurmSecGroup }, { get_resource: NFSSecGroup } ]
      metadata:
       ansible_host_groups: [ ComputeNodes ]
       ansible_ssh_user: ubuntu
       project_name: { get_param: project_name }
      networks:
       - network: { get_param: NetID }

  ComputeNodesC:
   type: "OS::Heat::ResourceGroup"
   properties:
    count: 1
    resource_def:
     type: "OS::Nova::Server"
     properties:
      #availability_zone: { get_param: avz }
      flavor: m3.xsmall
      image: { get_param: centos_7_image_id }
      key_name: { get_param: ssh_key }
      name:
       list_join: [ '-', [ { get_param: "OS::stack_name" }, 'computec7%index%' ]]
      security_groups: [ default, { get_resource: SSHMonashSecGroup }, { get_resource: SlurmSecGroup }, { get_resource: NFSSecGroup } ]
      metadata:
       ansible_host_groups: [ ComputeNodes ]
       ansible_ssh_user: ec2-user
       project_name: { get_param: project_name }
      networks:
       - network: { get_param: NetID }

  UbuntuDesktopNodes:
   type: "OS::Heat::ResourceGroup"
   properties:
    count: 0
    resource_def:
     type: "OS::Nova::Server"
     properties:
      #availability_zone: { get_param: avz }
      flavor: mon.c10r35.gpu-k2
      image: { get_param: ubuntu_1804_image_id }
      key_name: { get_param: ssh_key }
      name:
       list_join: [ '-', [ { get_param: "OS::stack_name" }, 'gpudesktopu%index%' ]]
      security_groups: [ default, { get_resource: SSHMonashSecGroup }, { get_resource: SlurmSecGroup }, { get_resource: NFSSecGroup } ]
      metadata:
       ansible_host_groups: [ DesktopNodes, GPU, ComputeNodes, K1, VisNodes ]
       ansible_ssh_user: ubuntu
       project_name: { get_param: project_name }
      networks:
       - network: { get_param: NetID }

  CentosDesktopNodes:
   type: "OS::Heat::ResourceGroup"
   properties:
    count: 1
    resource_def:
     type: "OS::Nova::Server"
     properties:
      #availability_zone: { get_param: avz }
      flavor: mon.c10r35.gpu-k2
      image: { get_param: centos_7_image_id }
      key_name: { get_param: ssh_key }
      name:
       list_join: [ '-', [ { get_param: "OS::stack_name" }, 'gpudesktopu%index%' ]]
      security_groups: [ default, { get_resource: SSHMonashSecGroup }, { get_resource: SlurmSecGroup }, { get_resource: NFSSecGroup } ]
      metadata:
       ansible_host_groups: [ DesktopNodes, GPU, ComputeNodes, K1, VisNodes ]
       ansible_ssh_user: ec2-user
       project_name: { get_param: project_name }
      networks:
       - network: { get_param: NetID }

  ComputeNodeRHEL:
   type: "OS::Heat::ResourceGroup"
   properties:
    count: 0
    resource_def:
     type: "OS::Nova::Server"
     properties:
      #availability_zone: { get_param: avz }
      flavor: m3.xsmall
      image: { get_param: rhel_77_image_id }
      key_name: { get_param: ssh_key }
      name:
       list_join: [ '-', [ { get_param: "OS::stack_name" }, 'computerhel%index%' ]]
      security_groups: [ default, { get_resource: SSHMonashSecGroup }, { get_resource: SlurmSecGroup }, { get_resource: NFSSecGroup } ]
      metadata:
       ansible_host_groups: [ DGXRHELNodes ]
       ansible_ssh_user: cloud-user
       project_name: { get_param: project_name }
      networks:
       - network: { get_param: NetID }
