Skip to content

Alpine-based multistage-build version of terraform-docs and terraform-docs-replace in multiple versions to be used for CI and other reproducible automations

License

Notifications You must be signed in to change notification settings

cytopia/docker-terraform-docs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Docker image for terraform-docs

Tag License

lint build nightly

All #awesome-ci Docker images

ansible-lint โ€ข ansible โ€ข awesome-ci โ€ข bandit โ€ข black โ€ข checkmake โ€ข eslint โ€ข file-lint โ€ข gofmt โ€ข goimports โ€ข golint โ€ข jsonlint โ€ข kubeval โ€ข linkcheck โ€ข mypy โ€ข php-cs-fixer โ€ข phpcbf โ€ข phpcs โ€ข phplint โ€ข pycodestyle โ€ข pydocstyle โ€ข pylint โ€ข terraform-docs โ€ข terragrunt-fmt โ€ข terragrunt โ€ข yamlfmt โ€ข yamllint

View Dockerfiles on GitHub.

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

Tiny Alpine-based multistage-build dockerized version of terraform-docs[1], which additionally implements terraform-docs-replace allowing you to automatically and safely replace the terraform-docs generated output infile. Furthermore this implementation is also Terraform >= 0.12 ready[2]. See Generic Usage for more details. The image is built nightly against multiple stable versions and pushed to Dockerhub.

๐Ÿณ Available Docker image versions

Docker

Rolling releaess

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

nightly

Docker Tag Git Ref Terraform Docs Available Architectures
latest master latest amd64, i386, arm64, arm/v7, arm/v6
0.16.0 master 0.16.0 amd64, i386, arm64, arm/v7, arm/v6
0.15.0 master 0.15.0 amd64, i386, arm64, arm/v7, arm/v6
0.14.1 master 0.14.1 amd64, i386, arm64, arm/v7, arm/v6
0.14.0 master 0.14.0 amd64, i386, arm64, arm/v7, arm/v6
0.13.0 master 0.13.0 amd64, i386, arm64, arm/v7, arm/v6
0.12.1 master 0.12.1 amd64, i386, arm64, arm/v7, arm/v6
0.12.0 master 0.12.0 amd64, i386, arm64, arm/v7, arm/v6
0.11.2 master 0.11.2 amd64
0.11.1 master 0.11.1 amd64
0.11.0 master 0.11.0 amd64
0.10.1 master 0.10.1 amd64
0.10.0 master 0.10.0 amd64
0.9.1 master 0.9.1 amd64
0.9.0 master 0.9.0 amd64
0.8.2 master 0.8.2 amd64
0.8.1 master 0.8.1 amd64
0.8.0 master 0.8.0 amd64
0.7.0 master 0.7.0 amd64
0.6.0 master 0.6.0 amd64
0.5.0 master 0.5.0 amd64
0.4.5 master 0.4.5 amd64
0.4.0 master 0.4.0 amd64
0.3.0 master 0.3.0 amd64
0.2.0 master 0.2.0 amd64
0.1.1 master 0.1.1 amd64
0.1.0 master 0.1.0 amd64

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 Tag Git Ref Terraform Docs Available Architectures
latest-0.32 tag: 0.32 latest amd64, i386, arm64, arm/v7, arm/v6
0.16.0-0.32 tag: 0.32 0.16.0 amd64, i386, arm64, arm/v7, arm/v6
0.15.0-0.32 tag: 0.32 0.15.0 amd64, i386, arm64, arm/v7, arm/v6
0.14.1-0.32 tag: 0.32 0.14.1 amd64, i386, arm64, arm/v7, arm/v6
0.14.0-0.32 tag: 0.32 0.14.0 amd64, i386, arm64, arm/v7, arm/v6
0.13.0-0.32 tag: 0.32 0.13.0 amd64, i386, arm64, arm/v7, arm/v6
0.12.1-0.32 tag: 0.32 0.12.1 amd64, i386, arm64, arm/v7, arm/v6
0.12.0-0.32 tag: 0.32 0.12.0 amd64, i386, arm64, arm/v7, arm/v6
0.11.2-0.32 tag: 0.32 0.11.2 amd64
0.11.1-0.32 tag: 0.32 0.11.1 amd64
0.11.0-0.32 tag: 0.32 0.11.0 amd64
0.10.1-0.32 tag: 0.32 0.10.1 amd64
0.10.0-0.32 tag: 0.32 0.10.0 amd64
0.9.1-0.32 tag: 0.32 0.9.1 amd64
0.9.0-0.32 tag: 0.32 0.9.0 amd64
0.8.2-0.32 tag: 0.32 0.8.2 amd64
0.8.1-0.32 tag: 0.32 0.8.1 amd64
0.8.0-0.32 tag: 0.32 0.8.0 amd64
0.7.0-0.32 tag: 0.32 0.7.0 amd64
0.6.0-0.32 tag: 0.32 0.6.0 amd64
0.5.0-0.32 tag: 0.32 0.5.0 amd64
0.4.5-0.32 tag: 0.32 0.4.5 amd64
0.4.0-0.32 tag: 0.32 0.4.0 amd64
0.3.0-0.32 tag: 0.32 0.3.0 amd64
0.2.0-0.32 tag: 0.32 0.2.0 amd64
0.1.1-0.32 tag: 0.32 0.1.1 amd64
0.1.0-0.32 tag: 0.32 0.1.0 amd64

๐Ÿ”  Environment variables

The following Docker environment variables are available. These will only need to be used when using terraform-docs-replace or terraform-docs-replace-012.

Variable Default Required Comment
DELIM_START <!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK --> No The starting delimiter in the file in where you want to replace the terraform-docs output.
DELIM_CLOSE <!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK --> No The ending delimiter in the file in where you want to replace the terraform-docs output.

๐Ÿ“‚ Docker mounts

The working directory inside the Docker container is /data/ and should be mounted locally to where your Terraform module is located.

๐Ÿ’ป Usage

Generic

Usage: cytopia/terraform-docs terraform-docs <ARGS> .
       cytopia/terraform-docs terraform-docs-012 <ARGS> .

       cytopia/terraform-docs terraform-docs-replace <ARGS> <PATH-TO-FILE>
       cytopia/terraform-docs terraform-docs-replace-012 <ARGS> <PATH-TO-FILE>


terraform-docs              Output as expected from terraform-docs
terraform-docs-012          Same as above, but used for Terraform >= 0.12 modules

terraform-docs-replace      Replaces directly inside README.md, if DELIM_START and DELIM_CLOSE are found.
terraform-docs-replace-012  Same as above, but used for Terraform >= 0.12 modules

<ARGS>                      All arguments terraform-docs command can use.
<PATH-TO-FILE>              File in where to auto-replace terraform-docs block.

Output to stdout

Create markdown output and sent to stdout:

# [Terraform < 0.12]
docker run --rm \
  -v $(pwd):/data \
  cytopia/terraform-docs \
  terraform-docs --sort-by-required md .

# [Terraform >= 0.12]
docker run --rm \
  -v $(pwd):/data \
  cytopia/terraform-docs \
  terraform-docs-012 --sort-by-required md .

Store in file

Create README.md with terraform-docs output:

# [Terraform < 0.12]
docker run --rm \
  -v $(pwd):/data \
  cytopia/terraform-docs \
  terraform-docs --sort-by-required md . > README.md

# [Terraform >= 0.12]
docker run --rm \
  -v $(pwd):/data \
  cytopia/terraform-docs \
  terraform-docs-012 --sort-by-required md . > README.md

Replace in README.md

Replace current terraform-docs blocks in README.md with current one in order to automatically keep it up to date. For this to work, the terraform-docs information must be wrapped with the following delimiter by default:

README.md:

<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
## Inputs
...
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
# [Terraform < 0.12]
# Path to README.md must be specified as last command.
# Note that the command changes from terraform-docs to terraform-docs-replace
docker run --rm \
  -v $(pwd):/data \
  cytopia/terraform-docs \
  terraform-docs-replace --sort-by-required md README.md

# [Terraform >= 0.12]
# Path to README.md must be specified as last command.
# Note that the command changes from terraform-docs to terraform-docs-replace
docker run --rm \
  -v $(pwd):/data \
  cytopia/terraform-docs \
  terraform-docs-replace-012 --sort-by-required md README.md

Replace in INFO.md with different delimiter

You are able to use different delimiter. Let's imagine the following delimiter:

INFO.md:

<!-- TFDOC_START -->
## Inputs
...
<!-- TFDOC_END -->
# [Terraform < 0.12]
# Path to INFO.md must be specified as last command.
# Note that the command changes from terraform-docs to terraform-docs-replace
docker run --rm \
  -v $(pwd):/data \
  -e DELIM_START='<!-- TFDOC_START -->' \
  -e DELIM_CLOSE='<!-- TFDOC_END -->' \
  cytopia/terraform-docs \
  terraform-docs-replace --sort-by-required md INFO.md

# [Terraform >= 0.12]
# Path to INFO.md must be specified as last command.
# Note that the command changes from terraform-docs to terraform-docs-replace
docker run --rm \
  -v $(pwd):/data \
  -e DELIM_START='<!-- TFDOC_START -->' \
  -e DELIM_CLOSE='<!-- TFDOC_END -->' \
  cytopia/terraform-docs \
  terraform-docs-replace-012 --sort-by-required md INFO.md

Example Makefile

You can add the following Makefile to your project for easy generation of terraform-docs output in a Terraform module. It takes into consideration the Main module, sub-modules and examples.

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

.PHONY: gen _gen-main _gen-examples _gen-modules _update-tf-docs

CURRENT_DIR     = $(dir $(abspath $(lastword $(MAKEFILE_LIST))))
TF_EXAMPLES     = $(sort $(dir $(wildcard $(CURRENT_DIR)examples/*/)))
TF_MODULES      = $(sort $(dir $(wildcard $(CURRENT_DIR)modules/*/)))
TF_DOCS_VERSION = 0.6.0

# Adjust your delimiter here or overwrite via make arguments
DELIM_START = <!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
DELIM_CLOSE = <!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->

gen: _update-tf-docs
	@echo "################################################################################"
	@echo "# Terraform-docs generate"
	@echo "################################################################################"
	@$(MAKE) --no-print-directory _gen-main
	@$(MAKE) --no-print-directory _gen-examples
	@$(MAKE) --no-print-directory _gen-modules

_gen-main:
	@echo "------------------------------------------------------------"
	@echo "# Main module"
	@echo "------------------------------------------------------------"
	@if docker run --rm \
		-v $(CURRENT_DIR):/data \
		-e DELIM_START='$(DELIM_START)' \
		-e DELIM_CLOSE='$(DELIM_CLOSE)' \
		cytopia/terraform-docs:$(TF_DOCS_VERSION) \
		terraform-docs-replace --sort-by-required md README.md; then \
		echo "OK"; \
	else \
		echo "Failed"; \
		exit 1; \
	fi

_gen-examples:
	@$(foreach example,\
		$(TF_EXAMPLES),\
		DOCKER_PATH="examples/$(notdir $(patsubst %/,%,$(example)))"; \
		echo "------------------------------------------------------------"; \
		echo "# $${DOCKER_PATH}"; \
		echo "------------------------------------------------------------"; \
		if docker run --rm \
			-v $(CURRENT_DIR):/data \
			-e DELIM_START='$(DELIM_START)' \
			-e DELIM_CLOSE='$(DELIM_CLOSE)' \
			cytopia/terraform-docs:$(TF_DOCS_VERSION) \
			terraform-docs-replace --sort-by-required md $${DOCKER_PATH}/README.md; then \
			echo "OK"; \
		else \
			echo "Failed"; \
			exit 1; \
		fi; \
	)

_gen-modules:
	@$(foreach module,\
		$(TF_MODULES),\
		DOCKER_PATH="modules/$(notdir $(patsubst %/,%,$(module)))"; \
		echo "------------------------------------------------------------"; \
		echo "# $${DOCKER_PATH}"; \
		echo "------------------------------------------------------------"; \
		if docker run --rm \
			-v $(CURRENT_DIR):/data \
			-e DELIM_START='$(DELIM_START)' \
			-e DELIM_CLOSE='$(DELIM_CLOSE)' \
			cytopia/terraform-docs:$(TF_DOCS_VERSION) \
			terraform-docs-replace --sort-by-required md $${DOCKER_PATH}/README.md; then \
			echo "OK"; \
		else \
			echo "Failed"; \
			exit 1; \
		fi; \
	)

_update-tf-docs:
	docker pull cytopia/terraform-docs:$(TF_DOCS_VERSION)

Travis CI integration

With the above Makefile in place, you can easily add a Travis CI rule to ensure the terraform-docs output is always up-to-date and will fail otherwise (due to git changes):

---
sudo: required
language: minimal
services:
  - docker
script:
  - make gen
  - git diff --quiet || { echo "Build Changes"; git diff; git status; false; }

โ„น๏ธ Example projects

Find below some example projects how this Docker image is used in CI to verify if the README.md has been updated with the latest changes generated from terraform-docs:

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:

GitHub DockerHub Type Description
awesome-ci aci-hub-img Basic Tools for git, file and static source code analysis
file-lint flint-hub-img Basic Baisc source code analysis
linkcheck linkcheck-hub-img Basic Search for URLs in files and validate their HTTP status code
ansible ansible-hub-img Ansible Multiple versions and flavours of Ansible
ansible-lint alint-hub-img Ansible Lint Ansible
gofmt gfmt-hub-img Go Format Go source code [1]
goimports gimp-hub-img Go Format Go source code [1]
golint glint-hub-img Go Lint Go code
eslint elint-hub-img Javascript Lint Javascript code
jsonlint jlint-hub-img JSON Lint JSON files [1]
kubeval kubeval-hub-img K8s Lint Kubernetes files
checkmake cm-hub-img Make Lint Makefiles
phpcbf pcbf-hub-img PHP PHP Code Beautifier and Fixer
phpcs pcs-hub-img PHP PHP Code Sniffer
phplint plint-hub-img PHP PHP Code Linter [1]
php-cs-fixer pcsf-hub-img PHP PHP Coding Standards Fixer
bandit bandit-hub-img Python A security linter from PyCQA
black black-hub-img Python The uncompromising Python code formatter
mypy mypy-hub-img Python Static source code analysis
pycodestyle pycs-hub-img Python Python style guide checker
pydocstyle pyds-hub-img Python Python docstyle checker
pylint pylint-hub-img Python Python source code, bug and quality checker
terraform-docs tfdocs-hub-img Terraform Terraform doc generator (TF 0.12 ready) [1]
terragrunt tg-hub-img Terraform Terragrunt and Terraform
terragrunt-fmt tgfmt-hub-img Terraform terraform fmt for Terragrunt files [1]
yamlfmt yfmt-hub-img Yaml Format Yaml files [1]
yamllint ylint-hub-img Yaml Lint 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.

๐Ÿ“„ License

MIT License

Copyright (c) 2019 cytopia