I learned a handy trick with consul-template today and I think it’s useful enough to share here for others, and my future self. I’m also curious about how others are solving the same problem on relatively small projects using Nomad.
A pain point - generating templates with Nomad
While I use and like Nomad, to help manage infrastructure, I don’t really code golang, and I have found it pretty fiddly to see what generated templates looked like before I used them in jobs to sent to a Nomad server.
Today though, I learned you can use consul-template, the library Nomad uses for rendering templates independently.
NOMAD_ADDR="https://nomad.mysite.org" \
NOMAD_TOKEN="long-token" \
consul-template -template="source.rendered.caddyfile" -once
This is helpful to manually eyeballing the output so you have no surprises, but crucially, you can also do things like run Caddy’s own validation checks safely on your own machine first against your rendered file, like so:
caddy validate --config Caddyfile.rendered.caddyfile
I’ve used Caddy as an example here because it’s a fairly common tool with nice validation support of files, but you this approach should work with basically any tool that has support for validating files before you use them on servers.
There’s more detail in this blog post below:
Anyway - back to my original question - this is how I’m sanity checking template output on small projects using Nomad - how are the rest of you doing it?
I didn’t see any obvious testing frameworks I might use, and I’d welcome pointers.