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

w-leads/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 • ansible-lint • awesome-ci • black • checkmake • eslint • file-lint • gofmt • goimports • golint • jsonlint • linkcheck • mypy • phpcbf • phpcs • phplint • php-cs-fixer • pycodestyle • pydocstyle • pylint • terraform-docs • terragrunt • terragrunt-fmt • yamlfmt • 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-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

Rolling releases

The following Docker image tags are rolling releases and built and updated nightly. This means any scripts from this repository which enhance the original terraform-docs are always available at their latest state (from this repository's master branch) and might cause backwards incompatibilities with how you use it (although it's very unlikely that backwards incompatible changes will be introduced).

Docker tag Build from docker-terraform-docs Build from terraform-docs
latest Branch: master Branch: master
0.10.1 Branch: master Tag: v0.10.1
0.10.0 Branch: master Tag: v0.10.0
0.9.1 Branch: master Tag: v0.9.1
0.9.0 Branch: master Tag: v0.9.0
0.8.2 Branch: master Tag: v0.8.2
0.8.1 Branch: master Tag: v0.8.1
0.8.0 Branch: master Tag: v0.8.0
0.8.0-rc.3 Branch: master Tag: v0.8.0-rc.3
0.8.0-rc.2 Branch: master Tag: v0.8.0-rc.2
0.8.0-rc.1 Branch: master Tag: v0.8.0-rc.1
0.7.0 Branch: master Tag: v0.7.0
0.6.0 Branch: master Tag: v0.6.0
0.5.0 Branch: master Tag: v0.5.0
0.4.5 Branch: master Tag: v0.4.5
0.4.0 Branch: master Tag: v0.4.0
0.3.0 Branch: master Tag: v0.3.0
0.2.0 Branch: master Tag: v0.2.0
0.1.1 Branch: master Tag: v0.1.1
0.1.0 Branch: master Tag: v0.1.0

Point in time releases

If you want to ensure to have reproducible Terraform doc generation you should use a git tag from this repository. Tags are incremented for each new version, but never updated itself. This means you will have to take care yourself and update your CI tools every time a new tag is being released.

Docker tag Build from docker-terraform-docs Build from terraform-docs
latest-<tag> Tag: <tag> Branch: master
0.10.1-<tag> Tag: <tag> Tag: v0.10.1
0.10.0-<tag> Tag: <tag> Tag: v0.10.0
0.9.1-<tag> Tag: <tag> Tag: v0.9.1
0.9.0-<tag> Tag: <tag> Tag: v0.9.0
0.8.2-<tag> Tag: <tag> Tag: v0.8.2
0.8.1-<tag> Tag: <tag> Tag: v0.8.1
0.8.0-<tag> Tag: <tag> Tag: v0.8.0
0.8.0-rc.3-<tag> Tag: <tag> Tag: v0.8.0-rc.3
0.8.0-rc.2-<tag> Tag: <tag> Tag: v0.8.0-rc.2
0.8.0-rc.1-<tag> Tag: <tag> Tag: v0.8.0-rc.1
0.7.0-<tag> Tag: <tag> Tag: v0.7.0
0.6.0-<tag> Tag: <tag> Tag: v0.6.0
0.5.0-<tag> Tag: <tag> Tag: v0.5.0
0.4.5-<tag> Tag: <tag> Tag: v0.4.5
0.4.0-<tag> Tag: <tag> Tag: v0.4.0
0.3.0-<tag> Tag: <tag> Tag: v0.3.0
0.2.0-<tag> Tag: <tag> Tag: v0.2.0
0.1.1-<tag> Tag: <tag> Tag: v0.1.1
0.1.0-<tag> Tag: <tag> Tag: v0.1.0

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

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-inputs-by-required --with-aggregate-type-defaults md .

# [Terraform >= 0.12]
docker run --rm \
  -v $(pwd):/data \
  cytopia/terraform-docs \
  terraform-docs-012 --sort-inputs-by-required --with-aggregate-type-defaults 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-inputs-by-required --with-aggregate-type-defaults md . > README.md

# [Terraform >= 0.12]
docker run --rm \
  -v $(pwd):/data \
  cytopia/terraform-docs \
  terraform-docs-012 --sort-inputs-by-required --with-aggregate-type-defaults 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-inputs-by-required --with-aggregate-type-defaults 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-inputs-by-required --with-aggregate-type-defaults 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-inputs-by-required --with-aggregate-type-defaults 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-inputs-by-required --with-aggregate-type-defaults 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-inputs-by-required --with-aggregate-type-defaults 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-inputs-by-required --with-aggregate-type-defaults 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-inputs-by-required --with-aggregate-type-defaults 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]
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
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

About

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

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • HCL 60.0%
  • Makefile 18.4%
  • Shell 12.7%
  • Awk 8.9%