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

  group "consul-servers" {
    count = 3

    constraint {
      attribute = "${node.unique.name}"
      operator  = "regexp"
      value     = "(master|ash3c|hcp)"
    }

    task "consul" {
      driver = "podman"

      config {
        image = "hashicorp/consul:latest"
        ports = ["server", "serf_lan", "serf_wan", "ui"]
        args = [
          "agent",
          "-server",
          "-bootstrap-expect=3",
          "-data-dir=/consul/data",
          "-ui",
          "-client=0.0.0.0",
          "-bind={{ env `NOMAD_IP_server` }}",
          "-retry-join=100.117.106.136",
          "-retry-join=100.116.80.94",
          "-retry-join=100.76.13.187"
        ]
      }

      volume_mount {
        volume      = "consul-data"
        destination = "/consul/data"
        read_only   = false
      }

      resources {
        network {
          mbits = 10
          port "server" { static = 8300 }
          port "serf_lan" { static = 8301 }
          port "serf_wan" { static = 8302 }
          port "ui" { static = 8500 }
        }
      }
    }

    volume "consul-data" {
      type      = "host"
      read_only = false
      source    = "consul-data"
    }
  }
}