I'm using the following template in consul-template:
{{ range services }}
{{ $server_name := .Name | replaceAll "_" "." }}
{{ range .Tags }}
{{ if . | regexMatch "server_name=" }}
# found matching server_name in {{ . }}
{{ $server_name := . | regexReplaceAll ".*=" "" }}
{{ end }}
{{ end }}
# server_name = {{ $server_name }}
acl host_{{ .Name }} hdr(host) -i {{ $server_name }}
use_backend {{ .Name }}_backend if host_{{ .Name }}
{{ end }}
which produces
# found matching server_name in server_name=geoserver.hello.org
# server_name = geoserver.dev.hello.org
acl host_geoserver_dev_hello_org hdr(host) -i geoserver.dev.hello.org
use_backend geoserver_dev_hello_org_backend if host_geoserver_dev_hello_org
where .Name
is geoserver_dev_hello_org
and there is a server_name=geoserver.hello.org
tag. I expect that by the end of the .Tags
range loop, $server_name
should have value geoserver.hello.org
, but it still has its original value of geoserver.dev.hello.org
.
How can I make it so that the loop overrides $server_name
(and exit the loop when the value is found)?