Skip to content

Alpine-based multistage-build version of terragrunt-fmt to be used for CI and other reproducible automations

License

Notifications You must be signed in to change notification settings

cytopia/docker-terragrunt-fmt

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Docker image for terragrunt-fmt

Build Status Tag License

All #awesome-ci Docker images

ansible • ansible-lint • awesome-ci • black • checkmake • eslint • file-lint • gofmt • goimports • golint • jsonlint • phpcbf • phpcs • php-cs-fixer • pycodestyle • pylint • terraform-docs • terragrunt • terragrunt-fmt • yamllint

All #awesome-ci Makefiles

Visit cytopia/makefiles for seamless project integration, minimum required best-practice code linting and CI.

View Dockerfile on GitHub.

Docker hub

Tiny Alpine-based multistage-build dockerized version of Terraform[1] with the ability to do terraform fmt on Terragrunt files (.hcl).

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

Available Docker image versions

The following Docker image tags are rolling releases and built and updated nightly. This means they always contain the latest stable version as shown below.

Docker tag Terraform version
latest latest stable
0.12 latest stable 0.12.x

Docker mounts

The working directory inside the Docker container is /data/ and should be mounted to your local filesystem where your Terragrant project resides. (See Examples for mount location usage.)

Usage

$ docker run --rm -v $(pwd):/data cytopia/terragrunt-fmt --help
Usage: cytopia/terragrunt-fmt [options] [DIR]
       cytopia/terragrunt-fmt --help
       cytopia/terragrunt-fmt --version

       Rewrites all Terragrunt configuration files to a canonical format. All
       hcl configuration files (.hcl) are updated.

       If DIR is not specified then the current working directory will be used.

Options:

  -list=true     List files whose formatting differs

  -write=false   Don't write to source files
                 (always disabled if using -check)

  -diff          Display diffs of formatting changes

  -check         Check if the input is formatted. Exit status will be 0 if all
                 input is properly formatted and non-zero otherwise.

  -recursive     Also process files in subdirectories. By default, only the
                 given directory (or current directory) is processed.

  -ignore=a,b    Comma separated list of paths to ignore.
                 The wildcard character '*' is supported.

Examples

List filenames that need to be fixed

docker run --rm -v $(pwd):/data cytopia/terragrunt-fmt -list

Show diff of files that need to be fixed

docker run --rm -v $(pwd):/data cytopia/terragrunt-fmt -diff

Fix files

docker run --rm -v $(pwd):/data cytopia/terragrunt-fmt -write

Fix files and show diff

docker run --rm -v $(pwd):/data cytopia/terragrunt-fmt -write -diff

List filenames that need to be fixed recursively

docker run --rm -v $(pwd):/data cytopia/terragrunt-fmt -list -recursive

Show diff of files that need to be fixed recursively

docker run --rm -v $(pwd):/data cytopia/terragrunt-fmt -diff -recursive

Fix recursively

docker run --rm -v $(pwd):/data cytopia/terragrunt-fmt -write -recursive

Ignore files and directories

Ignore all files named terragrunt.hcl.

docker run --rm -v $(pwd):/data cytopia/terragrunt-fmt -recursive -ignore=*terragrunt.hcl

Ignore all directories named dev/ and everything inside.

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

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

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

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/terraform-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
install: true
script:
  - make lint

Related #awesome-ci projects

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:

Docker image Type Description
awesome-ci Basic Tools for git, file and static source code analysis
file-lint Basic Baisc source code analysis
jsonlint Basic Lint JSON files [1]
yamllint Basic Lint Yaml files
ansible Ansible Multiple versoins of Ansible
ansible-lint Ansible Lint Ansible
gofmt Go Format Go source code [1]
goimports Go Format Go source code [1]
golint Go Lint Go code
eslint Javascript Lint Javascript code
checkmake Make Lint Makefiles
phpcbf PHP PHP Code Beautifier and Fixer
phpcs PHP PHP Code Sniffer
php-cs-fixer PHP PHP Coding Standards Fixer
black Python The uncompromising Python code formatter
pycodestyle Python Python style guide checker
pylint Python Python source code, bug and quality checker
terraform-docs Terraform Terraform doc generator (TF 0.12 ready) [1]
terragrunt Terraform Terragrunt and Terraform
terragrunt-fmt Terraform terraform fmt for Terragrunt files [1]

[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.

License

MIT License

Copyright (c) 2019 cytopia