2

We have multiple environments for our apps, and I am trying to use generic consul template and an environment variable to create haproxy configurations for different environments. This is what I am trying to do:

{{$environment := "yellow" }} .... balance leastconn {{range service "myservice-{{$env}}"}} ....

I cannot seem to find a way to use this variable within this range. Is there a way to get this working?

Thanks!

1 Answers1

5

You just need to define the variable and then use it in the range statement.

{{ $service_name := env "CONSUL_SERVICE_NAME" }}

{{range service $service_name }}
Caleb Brinkman
  • 2,489
  • 3
  • 26
  • 40
ZikPhil
  • 66
  • 1
  • 2