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

  group "consul-ch4" {
    constraint {
      attribute = "${node.unique.name}"
      value     = "ch4"
    }

    network {
      port "http" {
        static = 8500
      }
      port "server" {
        static = 8300
      }
      port "serf-lan" {
        static = 8301
      }
      port "serf-wan" {
        static = 8302
      }
    }

    task "consul" {
      driver = "exec"
      
      config {
        command = "consul"
        args = [
          "agent",
          "-server",
          "-bootstrap-expect=3",
          "-data-dir=/opt/nomad/data/consul",
          "-client=0.0.0.0",
          "-bind={{ env "NOMAD_IP_http" }}",
          "-advertise={{ env "NOMAD_IP_http" }}",
          "-retry-join=ash3c.tailnet-68f9.ts.net:8301",
          "-retry-join=warden.tailnet-68f9.ts.net:8301",
          "-ui",
          "-http-port=8500",
          "-server-port=8300",
          "-serf-lan-port=8301",
          "-serf-wan-port=8302"
        ]
      }

      resources {
        cpu = 300
        memory = 512
      }

    }
  }

  group "consul-ash3c" {
    constraint {
      attribute = "${node.unique.name}"
      value     = "ash3c"
    }

    network {
      port "http" {
        static = 8500
      }
      port "server" {
        static = 8300
      }
      port "serf-lan" {
        static = 8301
      }
      port "serf-wan" {
        static = 8302
      }
    }

    task "consul" {
      driver = "exec"
      
      config {
        command = "consul"
        args = [
          "agent",
          "-server",
          "-data-dir=/opt/nomad/data/consul",
          "-client=0.0.0.0",
          "-bind={{ env "NOMAD_IP_http" }}",
          "-advertise={{ env "NOMAD_IP_http" }}",
          "-retry-join=ch4.tailnet-68f9.ts.net:8301",
          "-retry-join=warden.tailnet-68f9.ts.net:8301",
          "-ui",
          "-http-port=8500",
          "-server-port=8300",
          "-serf-lan-port=8301",
          "-serf-wan-port=8302"
        ]
      }

      resources {
        cpu = 300
        memory = 512
      }

    }
  }

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

    network {
      port "http" {
        static = 8500
      }
      port "server" {
        static = 8300
      }
      port "serf-lan" {
        static = 8301
      }
      port "serf-wan" {
        static = 8302
      }
    }

    task "consul" {
      driver = "exec"
      
      config {
        command = "consul"
        args = [
          "agent",
          "-server",
          "-data-dir=/opt/nomad/data/consul",
          "-client=0.0.0.0",
          "-bind={{ env "NOMAD_IP_http" }}",
          "-advertise={{ env "NOMAD_IP_http" }}",
          "-retry-join=ch4.tailnet-68f9.ts.net:8301",
          "-retry-join=ash3c.tailnet-68f9.ts.net:8301",
          "-ui",
          "-http-port=8500",
          "-server-port=8300",
          "-serf-lan-port=8301",
          "-serf-wan-port=8302"
        ]
      }

      resources {
        cpu = 300
        memory = 512
      }

    }
  }
}
