5

I have a test service registered with Consul with the following service definition:

{
  "name": "web",
  "tags": ["web1"],
  "address": "example.com",
  "meta": {
    "meta": "cluster",
    "acl": "host_test",
    "cluster": "test_cluster"
  },
  "port": 8000
}

And I want to load that information into HAProxy config using consul-template. I can get the address and port as instructed in the documentation:

{{ range service "web" }}{{if in .Tags "web1"}}
    server {{.Node}} {{ .Address }}:{{.Port}} cookie A check
    {{ end }}{{end}}

But I can't seem to get the meta information. I thought I can access that using something like this within the service range:

 {{range .Meta}}
  {{.}}{{end}}

Any idea how I can get acl or cluster out of meta?

seemvision
  • 242
  • 1
  • 2
  • 12
  • when I look at https://github.com/hashicorp/consul-template/blob/master/dependency/health_service.go I see there is a ServiceMeta in there, but I also get nothing – Arne Burmeister Feb 28 '19 at 16:55

1 Answers1

3

In order to use key:value pairs from the Meta map you need to use index. Additionally, the Meta map on a service is referred to as .ServiceMeta.

So for example to get the value of the key acl in Meta you would use:

{{index .ServiceMeta "acl"}}