Dynamic server address in services based on query param

Hello,

Is it possible to grab an IP address from query param and use it down the line as a server url in a service?

Something similar to:

http:
  routers:
    rpi:
      entryPoints:
      - "https"
      rule: "Host(`rpi.local`) && Query(`rpiaddr=10.10.10.1`)"
      service: rpi-svc
      tls:
        options: tlsopt

    rpi-svc:
      loadBalancer:
        servers:
        - url: "http://{QUERY_PARAM_ADDR}:2133"

Is it possible to use variables of any sort in the file config?

Thanks,

Hello,

you cannot do that (and it's really insecure) but you can do that:

http:
  routers:
    {{ range $i, $e := until 100 }}
    rpi-{{ $e }}:
      entryPoints:
      - websecure
      rule: Host(`rpi.local`) && Query(`rpiaddr=10.10.10.{{ $e }}`)
      service: rpi-svc-{{ $e }}
      # tls:
      #   options: tlsopt
    {{ end }}

  services:
    {{ range $i, $e := until 100 }}
    rpi-svc-{{ $e }}:
      loadBalancer:
        servers:
        - url: http://10.10.10.{{ $e }}:2133
    {{ end }}

Thanks for the heads up!

Can you elaborate why this is insecure?

The documentation is here https://docs.traefik.io/v2.1/providers/file/#go-templating

But there are some errors in the doc, so I opened a PR to fix that https://github.com/containous/traefik/pull/6402