Repackages the hashicorp/packer container into one that
knows how to reformat all *.hcl and *.nomad files in a directory,
recursively.
Mount your directory at /workdir in the container, with write
permissions and as your current machine user, and the container will
format all the HCL files it finds. (If you don't override the user,
you will end up with incorrect file ownership, which is no fun for
anyone.)
You can run it directly with docker:
docker run \
--rm \
--mount=type=bind,source="$(pwd)",destination=/workdir \
--user=$(id -u):$(id -g) \
docker.cloudsmith.io/grapl/releases/hcl-formatter:latest formatAlternatively, you can set up a docker-compose.yml file like this:
version: "3.8"
services:
hcl-formatter:
image: docker.cloudsmith.io/grapl/releases/hcl-formatter:latest
command: format
volumes:
- type: bind
source: .
target: /workdir
read_only: falseand invoke the service like so:
docker-compose run --rm --user=$(id -u):$(id -g) hcl-formatterChanging the command to lint will instead invoke packer fmt -check -diff on the files. This invocation does not need write permissions
to the mounted directory, nor does it require a different user to be
set.
- Docker
- Docker
buildxplugin - Docker Compose
When new versions of hashicorp/packer are available,
update the default value of PACKER_VERSION in
docker-bake.hcl to match and rebuild the image
with make image.