diff --git a/core/traefik/traefik.nomad b/core/traefik/traefik.nomad index 47025ec..6ff0cb4 100644 --- a/core/traefik/traefik.nomad +++ b/core/traefik/traefik.nomad @@ -188,14 +188,25 @@ job "traefik" { service = "nomad" rule = "Host(`nomad.{{ with nomadVar "nomad/jobs" }}{{ .base_hostname }}{{ end }}`)" - {{ with nomadVar "nomad/jobs/traefik" }}{{ with .external }}{{ with .Value | parseYAML -}} - {{ range $service, $url := . }} - [http.routers.{{ $service }}] + {{ range nomadVarList "traefik_external" }}{{ with nomadVar .Path }} + [http.routers.{{ .name }}] entryPoints = ["websecure"] - service = "{{ $service }}" - rule = "Host(`{{ $service }}.{{ with nomadVar "nomad/jobs" }}{{ .base_hostname }}{{ end }}`)" - {{ end }} - {{- end }}{{ end }}{{ end }} + service = "{{ .name }}" + rule = "Host(`{{ .subdomain }}.{{ with nomadVar "nomad/jobs" }}{{ .base_hostname }}{{ end }}`){{ with .path_prefix.Value }}&&PathPrefix(`{{ . }}`){{ end }}" + {{ $name := .name -}} + {{ with .path_prefix.Value -}} + middlewares = ["{{ $name }}@file"] + {{ end }} + {{- end }}{{ end }} + + #[http.middlewares] + # {{ range nomadVarList "traefik_external" }}{{ with nomadVar .Path -}} + # {{ $name := .name -}} + # {{ with .path_prefix.Value -}} + # [http.middlewares.{{ $name }}.stripPrefix] + # prefixes = ["{{ . }}"] + # {{ end }} + # {{- end }}{{ end }} [http.services] [http.services.nomad] @@ -203,14 +214,12 @@ job "traefik" { [[http.services.nomad.loadBalancer.servers]] url = "http://127.0.0.1:4646" - {{ with nomadVar "nomad/jobs/traefik" }}{{ with .external }}{{ with .Value | parseYAML -}} - {{ range $service, $url := . }} - [http.services.{{ $service }}] - [http.services.{{ $service }}.loadBalancer] - [[http.services.{{ $service }}.loadBalancer.servers]] - url = "{{ $url }}" - {{ end }} - {{- end }}{{ end }}{{ end }} + {{ range nomadVarList "traefik_external" }}{{ with nomadVar .Path }} + [http.services.{{ .name }}] + [http.services.{{ .name }}.loadBalancer] + [[http.services.{{ .name }}.loadBalancer.servers]] + url = "{{ .url }}" + {{- end }}{{ end }} EOH destination = "${NOMAD_TASK_DIR}/config/conf/route-hashi.toml" change_mode = "noop" diff --git a/core/traefik/traefik.tf b/core/traefik/traefik.tf index 46094fa..08ce970 100644 --- a/core/traefik/traefik.tf +++ b/core/traefik/traefik.tf @@ -34,3 +34,48 @@ EOH job_id = resource.nomad_job.traefik.id } } + +resource "nomad_acl_policy" "treafik_external" { + name = "traefik-exernal" + description = "Read external services" + rules_hcl = <