Skip to content

Instantly share code, notes, and snippets.

@mr-karan
Created May 24, 2022 04:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mr-karan/c9bc000e158826062575ce755e83251c to your computer and use it in GitHub Desktop.
Save mr-karan/c9bc000e158826062575ce755e83251c to your computer and use it in GitHub Desktop.
Format Nomad Job Files

VSCode

  • Install this extension.
  • Add the following lines to your settings.json:
    "files.associations": {
        "*.nomad": "hcl",
        "*.nomad.tpl": "hcl",
        "*.tf": "terraform",
    }
  • Reload VSCode.

Manual

  • Install hclfmt using go (they don't provide pre-compiled binaries, so building from source is only option):
go install github.com/hashicorp/hcl/v2/cmd/hclfmt@latest
  • Format with hclfmt. Since it only works on a single file by default, we need to use a wrapper script to cover all files and nested directories.
#!/usr/bin/env bash
set -e
for file in *; do
  hclfmt -w $file
done
  • Save the above as run-hclfmt in /usr/local/bin and chmod +x /usr/local/bin/run-hclfmt

  • Now, you'll be able to run this script from anywhere in your directory of Nomad job specs using run-hclfmt. It includes sub directories as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment