seemvision
seemvision

Reputation: 242

Can't read Service Meta with consul-template

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?

Upvotes: 5

Views: 2112

Answers (1)

Mitchell Stankowski
Mitchell Stankowski

Reputation: 31

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"}}

Upvotes: 3

Related Questions