---

pdns_labels: [
  '"traefik.enable=true"',
  '"traefik.http.routers.{{ pdns_id }}.service={{ pdns_id }}"',
  '"traefik.http.routers.{{ pdns_id }}.rule=Host(`{{ stage_server_domain }}`)"',
  '"traefik.http.routers.{{ pdns_id }}.entrypoints=websecure"',
  '"traefik.http.routers.{{ pdns_id }}.tls=true"',
  '"traefik.http.routers.{{ pdns_id }}.tls.certresolver=letsencrypt"',
  '"traefik.http.services.{{ pdns_id }}.loadbalancer.server.port=80"',
]

pdns_environment: [
  "PDNS_gpgsql_host: \"{{ pdns_postgres_host }}\"",
  "PDNS_gpgsql_dbname: \"{{ pdns_postgres_database }}\"",
  "PDNS_gpgsql_user: \"{{ pdns_postgres_username }}\"",
  "PDNS_gpgsql_password: \"{{ pdns_postgres_password }}\"",
  "PDNS_master: \"yes\"",
  "PDNS_api: \"yes\"",
  "PDNS_api_key: \"{{ pdns_api_key }}\"",
  "PDNS_webserver: \"yes\"",
  "PDNS_webserver_address: \"0.0.0.0\"",
  "PDNS_webserver_allow_from: \"172.6.0.0/16,0.0.0.0\"",
  "PDNS_version_string: \"anonymous\"",
  "PDNS_default_ttl: \"1500\"",
]

pdns_admin_environment: [
  "SQLALCHEMY_DATABASE_URI: \"postgresql://{{ pdns_admin_postgres_username }}:{{ pdns_admin_postgres_password }}@{{ pdns_postgres_host }}/{{ pdns_admin_postgres_database }}\"",
]

pdns_recursor_environment: [
  "PDNS_forward-zones: \"smardigo.digital=172.6.0.20\"",
]

pdns_docker: {
  networks: [
    {
      name: front-tier,
      external: true
    },
    {
      name: pdns,
      ipams: [
        {
          subnet: 172.6.0.0/16,
          gateway: 172.6.0.1
        }
      ]
    },
  ],
  services: [
    {
      name: "{{ pdns_id }}",
      image_name: "{{ pdns_image_name }}",
      image_version: "{{ pdns_image_version }}",
      restart: "{{ pdns_service_restart | default('always') }}",
      environment: "{{ pdns_environment + ( pdns_environment_additional | default([])) }}",
      volumes: [
        '"/etc/timezone:/etc/timezone:ro"',
        '"/etc/localtime:/etc/localtime:ro"',
      ],
      networks: [
        {
          name: "pdns",
          aliases: "pdns",
          ipv4_address: "172.6.0.20",
        },
      ],
      ports: [
        {
          external: "8081",
          internal: "8081",
        },
      ],
      extra_hosts: [
        {
          hostname: "{{ pdns_postgres_host }}",
          ip: "{{ shared_service_pg_master_ip }}"
        
        },
        {
          hostname: "ns1.smardigo.digital",
          ip: "172.6.0.20"
        }
      ],
    },
    {
      name: "{{ pdns_admin_id }}",
      image_name: "{{ pdns_admin_image_name }}",
      image_version: "{{ pdns_admin_image_version }}",
      labels: "{{ pdns_labels + ( pdns_labels_additional | default([])) }}",
      environment: "{{ pdns_admin_environment + ( pdns_admin_environment_additional | default([])) }}",
      volumes: [
        '"/etc/timezone:/etc/timezone:ro"',
        '"/etc/localtime:/etc/localtime:ro"',
      ],
      networks: [
        '"pdns"',
        '"front-tier"',
      ],
      extra_hosts: [
        {
          hostname: "{{ pdns_postgres_host }}",
          ip: "{{ shared_service_pg_master_ip }}"
        }
      ],
    },
    {
      name: "{{ pdns_recursor_id }}",
      image_name: "{{ pdns_recursor_image_name }}",
      image_version: "{{ pdns_recursor_image_version }}",
      environment: "{{ pdns_recursor_environment + ( pdns_recursor_environment_additional | default([])) }}",
      volumes: [
        '"/etc/timezone:/etc/timezone:ro"',
        '"/etc/localtime:/etc/localtime:ro"',
      ],
      ports: [
        {
          external: "53",
          internal: "53/tcp",
        },
        {
          external: "53",
          internal: "53/udp",
        },
      ],
      networks: [
        '"pdns"',
      ]
    }
  ],
}
