job "consul-ui-service" {
  datacenters = ["dc1"]
  type = "service"

  group "consul-ui" {
    count = 1

    constraint {
      attribute = "${node.unique.name}"
      value     = "warden"
    }

    network {
      mode = "host"
      port "http" {
        static = 8500
        host_network = "tailscale0"
      }
    }

    service {
      name = "consul-ui"
      port = "http"
      
      tags = [
        "traefik.enable=true",
        "traefik.http.routers.consul-ui.rule=PathPrefix(`/consul`)",
        "traefik.http.routers.consul-ui.priority=100"
      ]

      check {
        type     = "http"
        path     = "/v1/status/leader"
        interval = "10s"
        timeout  = "2s"
      }
    }

    task "consul-ui" {
      driver = "exec"
      
      config {
        command = "/usr/bin/consul"
        args = [
          "agent",
          "-server",
          "-bootstrap-expect=3",
          "-data-dir=/opt/nomad/data/consul",
          "-client=0.0.0.0",
          "-bind=100.122.197.112",
          "-advertise=100.122.197.112",
          "-retry-join=100.117.106.136",
          "-retry-join=100.116.80.94",
          "-ui",
          "-http-port=8500"
        ]
      }

      resources {
        cpu = 300
        memory = 512
      }
    }
  }
}

