job "traefik-simple" {
  datacenters = ["dc1"]
  type = "service"

  group "traefik" {
    count = 1

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

    network {
      mode = "host"
      port "http" {
        static = 80
        host_network = "tailscale0"
      }
      port "traefik" {
        static = 8080
        host_network = "tailscale0"
      }
    }

    task "traefik" {
      driver = "exec"
      
      config {
        command = "/usr/local/bin/traefik"
        args = [
          "--configfile=/local/traefik.yml"
        ]
      }

      template {
        data = <<EOF
api:
  dashboard: true
  insecure: true

entryPoints:
  web:
    address: "0.0.0.0:80"
  traefik:
    address: "0.0.0.0:8080"

providers:
  consulCatalog:
    endpoint:
      address: "warden.tailnet-68f9.ts.net:8500"
      scheme: "http"
    watch: true
    exposedByDefault: false
    prefix: "traefik"

log:
  level: INFO
EOF
        destination = "local/traefik.yml"
      }

      resources {
        cpu = 500
        memory = 512
      }
    }
  }
}