heat_template_version: 2015-10-15

description: A Group of Load Balanced Servers

parameters:

  tls:
    type: string
    default: http://10.102.184.190:9311/v1/secrets/b3828052-efb8-462f-b61f-934e1c52d65e
  key_name:
    type: string
    default: opstkcsi
  app_port:
    type: number
    default: 80
    description: Port used by the servers
  flavor:
    type: string
    description: Flavor used for servers
    default: "m1.small"
  image:
    type: string
    description: Image used for servers
    default: "centos7_lvm"
  lb_port:
    type: number
    default: 443
    description: Port used by the load balancer
  private_network:
    type: string
    description: Network used by the servers
    default: "566"
  public_network:
    type: string
    description: Network used by the load balancer
    default: "566"
  subnet:
    type: string
    description: Subnet on which the load balancer will be located
    default: "566-subnet"

resources:

  sec_group:
    type: OS::Neutron::SecurityGroup
    properties:
      name: "loadblstks"
      rules:
      - remote_ip_prefix: 0.0.0.0/0
        protocol: tcp
        port_range_min: 22
        port_range_max: 80

# A ResourceGroup with a nested server template
# is a cleaner way of doing multiple servers.
# These are placed inline for the sake of the
# keeping the example in the App Catalog in a
# single template.
#
# A Resource Group would be as follows:
#
#  group:
#    type: OS::Heat::ResourceGroup
#    properties:
#      count: 2
#      resource_def:
#        type: lb_server.yaml
#
# The lb_server template would create the
# server and member resources.

  server1:
    type: OS::Nova::Server
    properties:
      image: { get_param: image }
      flavor: { get_param: flavor }
      networks: [{ network: { get_param: private_network }}]
      key_name:
        get_param: key_name
      security_groups: [{ get_resource: sec_group }]
      user_data: |
            #! /bin/sh -v
            echo ciao > /tmp/p
            export http_proxy=http://proxy-srv.csi.it:3128
            export https_proxy=http://proxy-srv.csi.it:3128
            yum -y install httpd
            systemctl enable httpd
            systemctl start httpd

  pool_member111:
    type: OS::Octavia::PoolMember
    properties:
      pool: { get_resource: pool }
      address: { get_attr: [ server1, first_address ]}
      protocol_port: { get_param: app_port }
      subnet: { get_param: subnet }

  server2:
    type: OS::Nova::Server
    properties:
      image: { get_param: image }
      flavor: { get_param: flavor }
      networks: [{ network: { get_param: private_network }}]
      key_name:
        get_param: key_name
      security_groups: [{ get_resource: sec_group }]
      user_data: |
            #! /bin/sh -v
            echo ciao > /tmp/p
            export http_proxy=http://proxy-srv.csi.it:3128
            export https_proxy=http://proxy-srv.csi.it:3128
            yum -y  install httpd
            systemctl enable httpd
            systemctl start httpd

  pool_member222:
    type: OS::Octavia::PoolMember
    properties:
      pool: { get_resource: pool }
      address: { get_attr: [ server2, first_address ]}
      protocol_port: { get_param: app_port }
      subnet: { get_param: subnet }

  monitor:
    type: OS::Octavia::HealthMonitor
    properties:
      delay: 3
      type: TCP
      timeout: 3
      max_retries: 3
      pool: { get_resource: pool }

  pool:
    type: OS::Octavia::Pool
    properties:
      lb_algorithm: ROUND_ROBIN
      protocol: TCP
      listener: { get_resource: listener }


  listener:
    type: OS::Octavia::Listener
    properties:
      loadbalancer: { get_resource: loadbalancer }
      protocol: TCP
      protocol_port: { get_param: lb_port }
      default_tls_container_ref: { get_param: tls }

  loadbalancer:
    type: OS::Octavia::LoadBalancer
    properties:
      vip_subnet: { get_param: subnet }

outputs:

