heat_template_version: '2016-10-14'

description: >
  Single Linux instance with a network, router, and subnet 
  Version: 28FEB18

parameters:
  name:
    type: string
    default: lin_inst
  flavor:
    type: string
    default: cy.large
  image:
    type: string
    default: "Debian Stretch"
  username:
    type: string
    default: user
  password:
    type: string
    hidden: true
    default: pass

resources:

  network:
    type: OS::Neutron::Net
    properties:
      name: network
      port_security_enabled: false

  router:
    type: OS::Neutron::Router    
    properties:
      name: router
      external_gateway_info:
        network: public

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

  subnet:
    type: OS::Neutron::Subnet
    properties:
      cidr: 192.168.100.0/24
      network: { get_resource: network }
      name: subnet
      dns_nameservers: [ "10.50.255.254" ]
      gateway_ip: 192.168.100.1

  host:
    type: OS::Nova::Server
    properties:
      name: { get_param: name }
      image: { get_param: image }
      flavor: { get_param: flavor }
      networks: 
        - network: { get_resource: network }
      user_data_format: RAW
      user_data: { get_resource: host_config }

  host_config:
    type: OS::Heat::SoftwareConfig
    properties:
      config:
        str_replace:
          template: |
            #!/bin/bash
            export DEBIAN_FRONTEND=noninteractive
            echo 127.0.0.1 $(hostname) >> /etc/hosts
            useradd $username -m -U -s /bin/bash
            echo "$username:$password" | chpasswd
            usermod -aG sudo $username
            shutdown -r now
          params:
            $username: { get_param: username }
            $password: { get_param: password }