Nomad Plan Diff
Understanding nomad diffs is a big pain
~/.local/bin/nomad-tmpl-diff (or wherever you keep scripts):
#!/usr/bin/env bash# Usage: nomad job plan foo.hcl 2>&1 | nomad-tmpl-diffgrep "EmbeddedTmpl:" | sed 's/.*EmbeddedTmpl:[[:space:]]*//' | while IFS= read -r val; do diff \ <(echo "$val" | awk -v SIDE=L -f ~/.local/bin/nomad_diff.awk) \ <(echo "$val" | awk -v SIDE=R -f ~/.local/bin/nomad_diff.awk)done~/.local/bin/nomad_diff.awk:
{ p = "\\n\" => \"" idx = index($0, p) left = substr($0, 2, idx - 2) right = substr($0, idx + 8) sub(/"$/, "", right) s = (SIDE == "L") ? left : right gsub(/\\n/, "\n", s) gsub(/\\"/, "\"", s) printf "%s\n", s}Then just run and see the magic!
nomad job plan monitoring.hcl | nomad-tmpl-diffNote:
- The inline quoting for awk’s
gsubwith escaped quotes is a nightmare in bash — the separate.awkfile avoids that entirely and actually works reliably.