In all the examples, I see references to the {{ .Address }} and {{ .Port }} fields in a “Service” struct (which according to the error message is a “dependency.HealthService”), but what other fields can I access from this object - and how?
Here is what I tried:
{{- range service "server" }}
SERVER_{{ .Meta.ordinal }}={{ .Address }}:{{ .Port }}
{{ end -}}
And here is what I got:
Template failed: (dynamic): execute: template: :3:36: executing “” at <.Meta.ordinal>: can’t evaluate field Meta in type *dependency.HealthService.
The corresponding service definition is:
service {
name = "server"
port = "admin"
tags = [ "svr-${NOMAD_ALLOC_INDEX}" ]
meta {
ordinal = "${NOMAD_ALLOC_INDEX}"
}
}
As you can see, I need to create a set of ENV vars, one for each task registered to the service.
I have made that particular use-case work - using different means - by creating a separate service for each task; but that seemed heavyweight, when a single service with some metadata provides a much neater solution.
In a different use-case, I need to use the tag on the service.
I guess I should reference that something like: {{ .Tags }} or {{ index .Tags 0 }} (?)
So what I need is documentation on the actual structure of the HealthService type - and in fact all types accessible in the template section.
I had a quick scan of the source in GitHub, but didn’t find anything immediately.
(Should I be scanning nomad or consul or somewhere else?)
Any and all help gratefully received.
Kind Regards,
Nik