---
heat_template_version: 2016-10-14

description:
  An instance for a DNS slave server
  The instances are created with Heat and then configured with Ansible

parameters:

  # Connectivity
  external_network:
    type: string
    description: >
      The external network that provides floating IP addresses for the nodes
    constraints:
    - custom_constraint: neutron.network

  service_network:
    description: >
      The name or ID of the internal network
    type: string
    constraints:
    - custom_constraint: neutron.network

  service_subnet:
    description: >
      The name or ID of the internal IPv4 space
    type: string
    constraints:
    - custom_constraint: neutron.subnet

  security_group:
    description: >
      Allow DNS service access to instances
    type: string
    constraints:
    - custom_constraint: neutron.security_group

  # Host Characteristics
  hostname:
    description: The prefix for slave nameserver hostnames
    type: string

  domain_name:
    description: The prefix for slave nameserver hostnames
    type: string

  server_group:
    description: >
      ID of a server group containing all of the master hosts
    type: string

  image:
    description: >
      The Glance image to use as a base for DNS servers
    type: string
    constraints:
    - custom_constraint: glance.image

  flavor:
    description: >
      The name of the OpenStack instance flavor to use for DNS servers
    type: string
    constraints:
    - custom_constraint: nova.flavor

  # Access to the VMs
  ssh_user:
    type: string
    description: >
      The SSH user available on all nodes.

  ssh_key_name:
    type: string
    description: Name of the SSH keypair registered with Nova
    constraints:
    - custom_constraint: nova.keypair

resources:
  host:
    type: OS::Nova::Server
    properties:
      name:
        str_replace:
          template: "HOSTNAME.DOMAIN"
          params:
            HOSTNAME: {get_param: hostname}
            DOMAIN: {get_param: domain_name}
      user_data_format: SOFTWARE_CONFIG
      user_data: {get_resource: init}
      image: {get_param: image}
      flavor: {get_param: flavor}
      admin_user: {get_param: ssh_user}
      key_name: {get_param: ssh_key_name}
      networks:
      - port: {get_resource: port}
      scheduler_hints:
        group: {get_param: server_group}

  port:
    type: OS::Neutron::Port
    properties:
      security_groups:
      - {get_param: security_group}
      network: {get_param: service_network}
      fixed_ips:
      - subnet: {get_param: service_subnet}
      replacement_policy: AUTO

  floating_ip:
    type: OS::Neutron::FloatingIP
    properties:
      floating_network: {get_param: external_network}
      port_id: {get_resource: port}

  init:
    type: OS::Heat::MultipartMime
    properties:
      parts:
      - config: {get_resource: set_hostname}

  set_hostname:
    type: OS::Heat::CloudConfig
    properties:
      cloud_config:
        hostname: {get_param: hostname}
        fqdn:
          str_replace:
            template: "HOSTNAME.DOMAIN"
            params:
              HOSTNAME: {get_param: hostname}
              DOMAIN: {get_param: domain_name}

outputs:
  entry:
    value:
      name: {get_param: hostname}
      address: {get_attr: [floating_ip, floating_ip_address]}
