Service is not getting IPs across datacenters?

I’m trying to configure a job that points to IPs across datacenters.

Datacenters a configured:

job "seaweedfs" {
    datacenters = ["dc1", "dc2"]
}

Here is the code i’m trying to setup within my template:

{{ range service "seaweedfs-server" }}{{ .Address }}:{{ .Port }},{{ end }}

The problem is this range only gets the IP address for one datacenter only (example, dc1 and dc2 jobs will give the “service” IPs local to it’s datacenter) and not across datacenters. How do i remove this limitation?

Hi @zaihan since this is consul-template under the hood, take a look at the docs for the service function and how to get results from more than one datacenter.

Hi @seth.hoenig :wave:

Yeah, your answer is right, i need to use consul-template.

As for reference, i’ve fixed the problem as mentioned about consul-template in the last github comment here:

So the code would be:

{{ range $dc := datacenters }}{{ $service := print "seaweedfs-server@" $dc }}{{ range service $service }}{{ .Address }}:{{ .Port }},{{ end }}{{ end }}