cytopia/terragrunt-fmt

By cytopia

Updated about 3 years ago

Alpine-based multistage-build version of terragrunt-fmt to be used for CI and local linting

Image
4

50K+

cytopia/terragrunt-fmt repository overview

Docker image for terragrunt-fmt

Tag License

lint build nightly

View Dockerfiles on GitHub.

Available Architectures: amd64, i386, arm64, arm/v7, arm/v6, ppc64le, s390x

Tiny Alpine-based multistage-build dockerized version of Terraform[1] with the ability to do terraform fmt on Terragrunt files (.hcl). This is achieved by creating a temporary file within the container with an .tf extension and then running terraform fmt on it. Additionally the wrapper has been extended with a -ignore argument to be able to ignore files and directory or wildcards. The image is built nightly against multiple stable versions and pushed to Dockerhub.

[1] Official project: https://github.com/hashicorp/terraform

:whale: Available Docker image versions

Docker

Rolling releaess

The following Docker image tags are rolling releases and are built and updated every night.

nightly

Docker TagGit RefterraformAvailable Architectures
latestmasterlatestamd64, i386, arm64, arm/v7, arm/v6, ppc64le, s390x
1.3master1.3.xamd64, i386, arm64, arm/v7, arm/v6, ppc64le, s390x
1.2master1.2.xamd64, i386, arm64, arm/v7, arm/v6, ppc64le, s390x
1.1master1.1.xamd64, i386, arm64, arm/v7, arm/v6, ppc64le, s390x
1.0master1.0.xamd64, i386, arm64, arm/v7, arm/v6, ppc64le, s390x
0.15master0.15.xamd64, i386, arm64, arm/v7, arm/v6, ppc64le, s390x
0.14master0.14.xamd64, i386, arm64, arm/v7, arm/v6, ppc64le, s390x
0.13master0.13.xamd64, i386, arm64, arm/v7, arm/v6, ppc64le, s390x
0.12master0.12.xamd64, i386, arm64, arm/v7, arm/v6, ppc64le, s390x
Point in time releases

The following Docker image tags are built once and can be used for reproducible builds. Its version never changes so you will have to update tags in your pipelines from time to time in order to stay up-to-date.

build

Docker TagGit RefterraformAvailable Architectures
latest-<tag>tag: <tag>latestamd64, i386, arm64, arm/v7, arm/v6, ppc64le, s390x
1.3-<tag>tag: <tag>1.3.xamd64, i386, arm64, arm/v7, arm/v6, ppc64le, s390x
1.2-<tag>tag: <tag>1.2.xamd64, i386, arm64, arm/v7, arm/v6, ppc64le, s390x
1.1-<tag>tag: <tag>1.1.xamd64, i386, arm64, arm/v7, arm/v6, ppc64le, s390x
1.0-<tag>tag: <tag>1.0.xamd64, i386, arm64, arm/v7, arm/v6, ppc64le, s390x
0.15-<tag>tag: <tag>0.15.xamd64, i386, arm64, arm/v7, arm/v6, ppc64le, s390x
0.14-<tag>tag: <tag>0.14.xamd64, i386, arm64, arm/v7, arm/v6, ppc64le, s390x
0.13-<tag>tag: <tag>0.13.xamd64, i386, arm64, arm/v7, arm/v6, ppc64le, s390x
0.12-<tag>tag: <tag>0.12.xamd64, i386, arm64, arm/v7, arm/v6, ppc64le, s390x

Where <tag> refers to the chosen git tag from this repository.

:open_file_folder: Docker mounts

The working directory inside the Docker container is /data/ and should be mounted locally to the root of your project.

:computer: Usage

Ignore all directories named dev/ and testing/ and everything inside.

$ docker run --rm -v $(pwd):/data cytopia/terragrunt-fmt -recursive -ignore=*/dev/,*/testing/

[INFO] Finding files: find . -not \( -path "./*/dev/*" -o -path "./*/testing/*" \) -name '*.hcl' -type f
terraform fmt -list=true -write=false ./prod/eu-central-1/microservice/terragrunt.hcl
../tmp/terragrunt.hcl.tf
terraform fmt -list=true -write=false ./prod/eu-central-1/infra/terragrunt.hcl
../tmp/terragrunt.hcl.tf

Project and CI integration

Makefile

You can add the following Makefile to your project for easy linting anf fixing of Terragrunt .hcl files.

ifneq (,)
.error This Makefile requires GNU Make.
endif

.PHONY: help lint fix _pull

CURRENT_DIR = $(dir $(abspath $(lastword $(MAKEFILE_LIST))))

# Adjust according to your needs
IGNORE      = */.terragrunt-cache/,*/.terraform/
FMT_VERSION = latest

help:
	@echo "help    Show this help"
	@echo "lint    Exit > 0 if any files have wrong formatting"
	@echo "fix     Fix all .hcl files"

lint: _pull
	docker run --rm -v $(CURRENT_DIR):/data cytopia/terragrunt-fmt:$(FMT_VERSION) \
		-check -diff -recursive -ignore='$(IGNORE)'

fix: _pull
	docker run --rm -v $(CURRENT_DIR):/data cytopia/terragrunt-fmt:$(FMT_VERSION) \
		-write -diff -recursive -ignore='$(IGNORE)'

_pull:
	docker pull cytopia/terragrunt-fmt:$(FMT_VERSION)
Travis CI integration

With the above Makefile in place, you can easily add a Travis CI rule to ensure the Terragrunt code uses correct coding style.

---
sudo: required
language: minimal
services:
  - docker
script:
  - make lint
Docker images

Save yourself from installing lot's of dependencies and pick a dockerized version of your favourite linter below for reproducible local or remote CI tests:

GitHubDockerHubTypeDescription
awesome-ciaci-hub-imgBasicTools for git, file and static source code analysis
file-lintflint-hub-imgBasicBaisc source code analysis
linkchecklinkcheck-hub-imgBasicSearch for URLs in files and validate their HTTP status code
ansibleansible-hub-imgAnsibleMultiple versions and flavours of Ansible
ansible-lintalint-hub-imgAnsibleLint Ansible
gofmtgfmt-hub-imgGoFormat Go source code [1]
goimportsgimp-hub-imgGoFormat Go source code [1]
golintglint-hub-imgGoLint Go code
eslintelint-hub-imgJavascriptLint Javascript code
jsonlintjlint-hub-imgJSONLint JSON files [1]
kubevalkubeval-hub-imgK8sLint Kubernetes files
checkmakecm-hub-imgMakeLint Makefiles
phpcbfpcbf-hub-imgPHPPHP Code Beautifier and Fixer
phpcspcs-hub-imgPHPPHP Code Sniffer
phplintplint-hub-imgPHPPHP Code Linter [1]
php-cs-fixerpcsf-hub-imgPHPPHP Coding Standards Fixer
banditbandit-hub-imgPythonA security linter from PyCQA
blackblack-hub-imgPythonThe uncompromising Python code formatter
mypymypy-hub-imgPythonStatic source code analysis
pycodestylepycs-hub-imgPythonPython style guide checker
pydocstylepyds-hub-imgPythonPython docstyle checker
pylintpylint-hub-imgPythonPython source code, bug and quality checker
terraform-docstfdocs-hub-imgTerraformTerraform doc generator (TF 0.12 ready) [1]
terragrunttg-hub-imgTerraformTerragrunt and Terraform
terragrunt-fmttgfmt-hub-imgTerraformterraform fmt for Terragrunt files [1]
yamlfmtyfmt-hub-imgYamlFormat Yaml files [1]
yamllintylint-hub-imgYamlLint Yaml files

[1] Uses a shell wrapper to add enhanced functionality not available by original project.

Makefiles

Visit cytopia/makefiles for dependency-less, seamless project integration and minimum required best-practice code linting for CI. The provided Makefiles will only require GNU Make and Docker itself removing the need to install anything else.

:page_facing_up: License

MIT License

Copyright (c) 2019 cytopia

Tag summary

Content type

Image

Digest

sha256:69bb9880c

Size

22.3 MB

Last updated

about 3 years ago

docker pull cytopia/terragrunt-fmt