{{ range service "my-service" }}
server {{ .Address }}:{{ .Port }};
{{ else }}server 127.0.0.1:65535; # force a 502
{{ end }}
Port seems to return whatever port is registered for the service with Consul - but what if I want to connect to the port associated with the Consul Connect sidecar? In some cases, that is the only port associated with the service, and Port in those contexts returns 0.
With Consul Connect you don’t need to query the service information, since all the connectivity that you need is managed by the sidecar proxy. So you can use the NOMAD_UPSTREAM_*_<service> environment variables, since the sidecar and your main task live in the same allocation.