heat_template_version: 2013-05-23

parameters:
  flavor:
    type: string
    default: m1.tiny
    constraints:
      - custom_constraint: nova.flavor
  image:
    type: string
    default: cirros-0.5.2-x86_64-disk
    constraints:
      - custom_constraint: glance.image
  scaling_adjustment:
    type: number
    default: 1
  max_size:
    type: number
    default: 5
    constraints:
      - range: {min: 1}
  cidr:
    type: string
    default: 11.11.11.0/24


resources:
  asg:
    type: OS::Heat::AutoScalingGroup
    properties:
      resource:
        type: OS::Nova::Server
        properties:
            image: { get_param: image }
            flavor: { get_param: flavor }
            networks:
              - port: { get_resource: server_port }
        server_port:
          type: OS::Neutron::Port
          properties:
            network_id: {get_resource: private_net}
        private_net:
          type: OS::Neutron::Net
        private_subnet:
          type: OS::Neutron::Subnet
          properties:
            network_id: { get_resource: private_net }
            cidr: {get_param: cidr}
      min_size: 1
      desired_capacity: 3
      max_size: { get_param: max_size }

  scaling_policy:
    type: OS::Heat::ScalingPolicy
    properties:
      adjustment_type: change_in_capacity
      auto_scaling_group_id: {get_resource: asg}
      scaling_adjustment: { get_param: scaling_adjustment }

outputs:
  scaling_url:
    value: {get_attr: [scaling_policy, alarm_url]}
