variable "consul_address" { type = string description = "Full address of Consul instance to get catalog from" default = "http://127.0.0.1:5400" } variable "base_hostname" { type = string description = "Base hostname to serve content from" default = "dev.homelab" } job "traefik" { region = "global" datacenters = ["dc1"] type = "system" constraint { attribute = "${node.class}" value = "ingress" } group "traefik" { network { port "web" { static = 80 } port "websecure" { static = 443 } } service { name = "traefik" port = "web" check { type = "http" path = "/ping" port = "web" interval = "10s" timeout = "2s" } connect { native = true } tags = [ "traefik.enable=true", "traefik.http.routers.traefik_dashboard.entryPoints=websecure", "traefik.http.routers.traefik_dashboard.rule=Host(`traefik.${var.base_hostname}`)", "traefik.http.routers.traefik_dashboard.service=api@internal", "traefik.http.routers.traefik_dashboard.tls=true", ] } task "traefik" { driver = "docker" config { image = "traefik:2.6" ports = ["web", "websecure"] network_mode = "host" mount { type = "bind" target = "/etc/traefik" source = "config" } } template { # Avoid conflict with TOML lists [[ ]] and Go templates {{ }} left_delimiter = "<<" right_delimiter = ">>" data = <>" EOH destination = "/config/traefik.toml" } template { # Avoid conflict with TOML lists [[ ]] and Go templates {{ }} left_delimiter = "<<" right_delimiter = ">>" data = <> [http.services.nomad] [http.services.nomad.loadBalancer] << range . ->> [[http.services.nomad.loadBalancer.servers]] url = "http://<< .Address >>:<< .Port >>" << end >> <<- end >> << with service "consul" ->> [http.services.consul] [http.services.consul.loadBalancer] << range . ->> [[http.services.consul.loadBalancer.servers]] # Not using .Port because that's an RPC port url = "http://<< .Address >>:8500" << end >> <<- end >> << with service "vault" ->> [http.services.vault] [http.services.vault.loadBalancer] << range . ->> [[http.services.vault.loadBalancer.servers]] url = "http://<< .Address >>:<< .Port >>" << end >> <<- end >> EOH destination = "/config/conf/route-hashi.toml" change_mode = "noop" } resources { cpu = 50 memory = 50 } } } }