heat_template_version: 2015-10-15

description: |
  Simplest web-app using netcat reporting only hostname.
  Specifically tailored for minimal Cirros image.

parameters:

  app_port:
    type: number

  wc_curl_cli:
    type: string

resources:

  webapp_nc:
    type: OS::Heat::SoftwareConfig
    properties:
      group: ungrouped
      config:
        str_replace:
          template: |
            #! /bin/sh -v
            Body=$(hostname)
            Response="HTTP/1.1 200 OK\r\nContent-Length: ${#Body}\r\n\r\n$Body"
            wc_notify --data-binary '{"status": "SUCCESS"}'
            while true ; do echo -e $Response | nc -llp PORT; done
          params:
            PORT: { get_param: app_port }
            wc_notify: { get_param: wc_curl_cli }

outputs:
  OS::stack_id:
    value: { get_resource: webapp_nc }
