consul-template: ByMeta does not accept `services` as input
TL;DR - services output cannot be passed to ByMeta, even though the documentation says this is valid.
Consul Template version
consul-template v0.24.1 (58aa6c60)
Configuration
{{- range $subdomain, $services := (services | byMeta "ProxySubdomain") }}
Expected behavior
Per the documentation:
Takes a list of services returned by the
serviceorservicesand returns a map that groups services by ServiceMeta values.
Actual behavior
2020/02/25 22:04:55.961357 [ERR] (cli) /pomerium/pomerium.yaml.tpl: execute: template: :3:53: executing "" at <"ProxySubdomain">: wrong type for value; expected []*dependency.HealthService; got []*dependency.CatalogSnippet
Steps to reproduce
- Try and pass the output of
servicestoByMeta.
References
It appears (to my amateur eye) that ByMeta explicitly expects to be passed a []*dep.HealthService: https://github.com/hashicorp/consul-template/blob/7103eb34608d642d0c7dd3f6d8c2053e166927e6/template/funcs.go#L384
By comparison, ByTag accepts an interface{}: https://github.com/hashicorp/consul-template/blob/7103eb34608d642d0c7dd3f6d8c2053e166927e6/template/funcs.go#L658
This matches the functions in question - service returns a []*dep.HealthService and services returns a []*dep.CatalogSnippet:
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 1
- Comments: 15 (7 by maintainers)
Buckle up, here we go:
rangeover the list of service names returned fromservices.serviceon the service name to get a list of service instances.rangeover the list of service instances, orServiceMetafield of the service instance.Example:
(Note that you can’t just do
{{ with index (service .Name) 0 }}because of this caveat.)Internally,
servicesreturns a list ofCatalogSnippetobjects, which only contain aNameand aTagsfield -servicereturns aHealthServiceobject, with all the fields you’d expect.