title: Overriding a variable in a loop in consul-template
body: <p>I'm using the following template in consul-template:</p>
  
  <pre><code>{{ 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 }}
  </code></pre>
  
  <p>which produces</p>
  
  <pre><code>  # 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
  </code></pre>
  
  <p>where <code>.Name</code> is <code>geoserver_dev_hello_org</code> and there is a <code>server_name=geoserver.hello.org</code> tag. I expect that by the end of the <code>.Tags</code> range loop, <code>$server_name</code> should have value <code>geoserver.hello.org</code>, but it still has its original value of <code>geoserver.dev.hello.org</code>.</p>
  
  <p>How can I make it so that the loop overrides <code>$server_name</code> (and exit the loop when the value is found)?</p>