I have deployed 2 services with connect native=true, and both are running fine, and appear in consul service catalog with connect enabled. If one service is the backend DB and the second service is the frontend UI for example, how do I reference in the Nomad Job file ENV stanza the Consul Service Natively without a sidecar proxy? The only way I have been able to do it dynamically is with the following template:
template {
data = <<EOF
{{ range service “<db_service_name” }}
DB_HOST = “{{ .Address }}:{{ .Port }}”
{{ end }}
EOF
destination = “local/env”
env = true
}
Using templates is the definitely the easiest way to go, and how service discovery is usually done in Nomad. The only change I would add is to use the connect function instead of service to limit the query to only Connect-enabled services.