heat_template_version: 2013-05-23
description: |
  Template which uses a wait condition to confirm that a minimal
  signalling works in a created network
parameters:
  key_name:
    type: string
  flavor:
    type: string
  image:
    type: string
  subnet_cidr:
    type: string
    default: 10.100.0.0/16
  timeout:
    type: number
  public_net:
    type: string
    default: public
  private_net:
    type: string
    default: heat-net
  dns_servers:
    type: comma_delimited_list
    default: ["8.8.8.8", "8.8.4.4"]
  user_data_format:
    type: string
    default: RAW
resources:
  sg:
    type: OS::Neutron::SecurityGroup
    properties:
      name: the_sg
      description: Ping and SSH
      rules:
      - protocol: icmp
      - protocol: tcp
        port_range_min: 22
        port_range_max: 22

  floating_ip:
    type: OS::Neutron::FloatingIP
    properties:
      floating_network: {get_param: public_net}

  network:
    type: OS::Neutron::Net

  subnet:
    type: OS::Neutron::Subnet
    properties:
      network: {get_resource: network}
      ip_version: 4
      cidr: {get_param: subnet_cidr}
      dns_nameservers: {get_param: dns_servers}

  router:
    type: OS::Neutron::Router
    properties:
      external_gateway_info:
        network: {get_param: public_net}

  router_interface:
    type: OS::Neutron::RouterInterface
    properties:
      router: {get_resource: router}
      subnet: {get_resource: subnet}

  wait_handle:
    type: OS::Heat::WaitConditionHandle

  server:
    type: OS::Nova::Server
    properties:
      image: {get_param: image}
      flavor: {get_param: flavor}
      key_name: {get_param: key_name}
      networks:
      - subnet: {get_resource: subnet}
      security_groups:
      - {get_resource: sg}
      user_data_format: {get_param: user_data_format}
      user_data:
        str_replace:
          template: |
            #!/bin/sh
            wc_notify --data-binary '{"status": "SUCCESS", "data": "test complete"}'
          params:
            wc_notify: { get_attr: ['wait_handle', 'curl_cli'] }

  server_floating_ip_assoc:
    type: OS::Neutron::FloatingIPAssociation
    properties:
      floatingip_id: {get_resource: floating_ip}
      port_id: {get_attr: [server, addresses, {get_resource: network}, 0, port]}

  wait_condition:
    type: OS::Heat::WaitCondition
    properties:
      handle: {get_resource: wait_handle}
      timeout: {get_param: timeout}

outputs:
  server_ip:
    value: {get_attr: [floating_ip, floating_ip_address]}
  wc_data:
    value: {get_attr: [wait_condition, data]}
