A practical example setting up watches

Hi there

If been reading the watches doc here https://www.consul.io/docs/dynamic-app-config/watches#service. I’m trying to set it up for a practical case, but I lack a full example, and an explanation about what I can use in the triggered script.

Here’s my use case

  • I’m running instances over AWS
  • I’ve an autoscaling group with haproxies with public IPs
  • A DNS A record “haproxy.company.tld” in Route53 with all those public IPs
  • A consul cluster
  • An “admin” instance which can update Route53 records

So I want to keep “haproxy.company.tld” up to date through a script executing on “admin” triggered by a watch.

I added this

root@i-0d651224c5f6bfc67:/etc/consul/consul.d# jq '.' haproxy.watches.json 
{
  "watches": [
    {
      "type": "service",
      "service": "haproxy",
      "passingonly": true,
      "args": [
        "/usr/local/bin/update_haproxy_records.sh"
      ]
    }
  ]
}

A question here, can I have a watch { } instead of watches [ ] ? I prefer adding multiple watch files through Ansible like I do with service, than consolidating somehow a dict of watches in Ansible to write down only one file. I guess no, didn’t found any mention of this in the doc, but asking just in case…

Then my update_haproxy_records.sg script at the moment is just

echo $@ > /tmp/haproxy_watch.log

to understand what’s happening. But nothing is happening, I don’t even have an empty file. I guess my watches config is wrong, but I saw no subcommand, no API endpoint to ask consul which watches it knows about.

Thank in advance !