Service tags formatting question

Hey all,

when using traefik + nomad auto service discovery, one has to rely on the nomad service tags defined in a job file.

More complex traefik routing rules can get pretty long. So was wondering if there is a way to do this more neatly with multiline (instead of 1 line).

As an example:

tags = [
  "traefik.http.routers.myroute.rule=(Host(``) || Host(``) || HostRegexp(``)) && !PathPrefix(`/.well-known/acme-challenge/`)",                                                                     

In my case I need to support multiple custom domains. Having this in one line isn’t ideal.

Any solutions for this?

It should be possible to use Terraform native concat(). Not perfect, but maybe slightly better?

Thanks a lot! Your answer pointed me into the right direction.

I keep forgetting I have the HCL builtin functions available in nomad jobs =)

I opted to go for following solution:

Define the rules ahead of time in a local var.

locals {
  custom_domain_list = [

  joined_custom_domains       = join("`) || Host(`", local.custom_domain_list)
  traefik_custom_domain_rules = "Host(`${local.joined_custom_domains}`)"

  traefik_router_rules = join("", [
    "HostRegexp(`genericdomain`) || ",
    " && !PathPrefix(`/.well-known/acme-challenge/`)"

Which allows me to re-use the rules later on for the web and websecure entrypoints:

tags = [
1 Like