Selecting a single nomadService

I am trying to do something like this:

      template {
        data = <<EOH
          {{range nomadService 1 "service_name"}}
          	{{ .Address }}:{{ .Port }} 
          {{ end }}
        EOH
      destination = "local/selected-service.env"
      env = false
    }

However this generates an error because of that 1, I guess I should be filtering by some kind of key (or remove the 1 altogether):

Template failed: (dynamic): execute: template: :1:18: executing "" at <nomadService 1 "service_name">: error calling nomadService: expected arguments <service> or <count> <key> <service>

But I don’t have anything to filter on, I would like randomly get one of the available services, how could I do that? With the help of AI I was trying to apply some kind of randomness to the service list, but it seems that most of the Go template syntax is not available in Nomad (??).

Thank you in advance.

Hi. Use the syntax with three arguments, see consul-template/docs/templating-language.md at main · hashicorp/consul-template · GitHub

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.