consul-template icon indicating copy to clipboard operation
consul-template copied to clipboard

Document how to access meta

Open rgarrigue opened this issue 6 years ago • 0 comments

Consul Template version

consul-template v0.22.0 (6cae10fe)

Configuration

A simple service like this

{
  "haproxy-stats-i-0000000": {
    "ID": "haproxy-stats-i-0000000",
    "Service": "haproxy-stats",
    "Tags": [
      "published"
    ],
    "Meta": {
      "Environment": "development",
      "Owner": "company",
      "Service": "haproxy",
      "URL": "haproxy.development.company.cloud"
    },
    "Port": 1936,
    "Address": "",
    "Weights": {
      "Passing": 1,
      "Warning": 1
    },
    "EnableTagOverride": false
  }
}

Expected behavior

I just wanted to print the URL, I'ld have done that in less than 1 minute with my usual python, ansible, jinja.

Actual behavior

I banged my head 2 hours on the keyboard trying to print {{ .Meta.URL }}, fighting with "if", "with", "range", "services", ".", ... being unable to just print the whole data to understand where I was wrong.

Until I ended up reading the code and realized it's not Meta but ServiceMeta.

Now I think I hate the whole golang text.template & consul-template until tomorrow at least.

I know that's me being incompetent with strongly structured & whatever you call it language & derivated templating stuff. But please document how to access meta. If you don't fix the incoherence between consul api (runnning 1.6.1 btw) and consul-template. And maybe that's my fault for missing out the proper compatibility between consul & consul-template. But still.

rgarrigue avatar Oct 10 '19 16:10 rgarrigue