I have several services on different machines that are available though HTTP and I wanted to merge them under a consistent URL: https://syncthing.XXX/<name of service>
. To do so, I created a config file with the following content:
http:
routers:
syncthing-srv:
rule: Host(`syncthing.XXX`) && Path(`/srv`)
service: syncthing-srv
services:
syncthing-srv:
loadBalancer:
servers:
- url: http://100.79.184.103:8384
This is a repetitive pattern for all my services where only the service name and the target URL will be different.
Is there a way to template such a config file by iterating a list of tuples (name and URL) and building the configuration accordingly?
I imagine something like (in pseudocode)
for service in [('srv', 'http://klsjdlskj'), ('hello', 'http://uiyeiuryieu')):
'''
http:
routers:
syncthing-{{service[0]}}:
rule: Host(`syncthing.XXX`) && Path(`/{{service[0]}}`)
service: syncthing-{{service[0]}}
services:
syncthing-{{service[0]}}:
loadBalancer:
servers:
- url: {{service[1]}}
'''