---
heat_template_version: 2016-10-14

description:
  An instance for a DNS service made up of a single master and a set of
  slave services.
  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

  dns_forwarders:
    type: comma_delimited_list
    description: Addresses of a dns nameserver reachable in your environment

  master_hostname:
    description: >
      The default prefix for slave server hostnames
    type: string
    default: "ns-master"

  slave_hostname_prefix:
    description: >
      The default prefix for slave server hostnames
    type: string
    default: "ns"

  domain_name:
    description: >
      All VMs will be placed in this domain
    type: string

  slave_count:
    type: number
    description: >
      Number of slave servers to create.
    default: 3

  slave_server_group_policies:
    type: comma_delimited_list
    description: >
      List of policies applied on master nodes ServerGroup. By default
      'anti-affinity' policy is used to make sure that each master node
      is deployed on a different host. If you use a small/all-in-one openstack
      environment, you may need to disable this e.g. by passing
      '-P master_server_group_policies=affinity'.
    default: ['anti-affinity']

  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
    default: m1.small
    constraints:
    - custom_constraint: nova.flavor

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

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

resources:

  network:
    type: network.yaml
    properties:
      external_network: {get_param: external_network}
      dns_nameservers: {get_param: dns_forwarders}

  hosts:
    depends_on: [network]
    type: hosts.yaml
    properties:
      external_network: {get_param: external_network}
      service_network: {get_attr: [network, dns_network]}
      service_subnet: {get_attr: [network, dns_subnet]}
      image: {get_param: image}
      flavor: {get_param: flavor}
      master_hostname: {get_param: master_hostname}
      slave_hostname_prefix: {get_param: slave_hostname_prefix}
      domain_name: {get_param: domain_name}
      slave_count: {get_param: slave_count}
      ssh_user: {get_param: ssh_user}
      ssh_key_name: {get_param: ssh_key_name}

outputs:
  ip_address:
    description: The floating IP address of the DNS servers
    value:
      master:
        name: {get_param: master_hostname}
        address: {get_attr: [hosts, master_ip_address]}
      slaves: {get_attr: [hosts, slave_entries]}
