Skip to content

Commit

Permalink
refactor: function make terraform docs (hadenlabs#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
luismayta committed Apr 6, 2021
1 parent 48c8293 commit 46b2fa8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 14 deletions.
12 changes: 1 addition & 11 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ OS := $(shell uname)

HAS_PIP := $(shell command -v pip;)
HAS_PIPENV := $(shell command -v pipenv;)
TF_DOCS := $(shell which terraform-docs 2> /dev/null)

ifdef HAS_PIPENV
PIPENV_RUN:=pipenv run
Expand All @@ -19,15 +18,6 @@ else
PIPENV_INSTALL:=
endif

define terraform-docs
$(if $(TF_DOCS),,$(error "terraform-docs revision >= a8b59f8 is required (https://github.com/segmentio/terraform-docs)"))
@echo '<!-- DO NOT EDIT. THIS FILE IS GENERATED BY THE MAKEFILE. -->' > $1
@echo '# Terraform variables' >> $1
@echo $2 >> $1
@terraform-docs markdown table . >> $1
endef


TEAM := hadenlabs
REPOSITORY_DOMAIN:=github.com
REPOSITORY_OWNER:=${TEAM}
Expand All @@ -52,7 +42,7 @@ SOURCE_DIR=$(ROOT_DIR)
PROVISION_DIR:=$(ROOT_DIR)/provision
DOCS_DIR:=$(ROOT_DIR)/docs
README_TEMPLATE:=$(PROVISION_DIR)/templates/README.tpl.md
TERRAFORM_README_FILE := $(DOCS_DIR)/include/terraform.md
TERRAFORM_README_FILE := docs/include/terraform.md

export README_FILE ?= README.md
export README_YAML ?= provision/generators/README.yaml
Expand Down
11 changes: 8 additions & 3 deletions provision/make/terraform.mk
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
## Terraform
.PHONY: terraform.help

TF_DOCS := $(shell which terraform-docs 2> /dev/null)

define terraform-docs
$(if $(TF_DOCS),,$(error "terraform-docs revision >= a8b59f8 is required (https://github.com/segmentio/terraform-docs)"))
@terraform-docs markdown table . --output-file ${1} --output-mode replace --sort-by-type
endef

terraform.help:
@echo ' terraform:'
@echo ''
Expand All @@ -13,7 +20,5 @@ terraform:


terraform.docs:
$(call terraform-docs, ${TERRAFORM_README_FILE}, \
'This document gives an overview of variables used in the platform of the ${PROJECT}.', \
variables.tf)
$(call terraform-docs, ${TERRAFORM_README_FILE})
.PHONY: terraform.docs

0 comments on commit 46b2fa8

Please sign in to comment.