Skip to content

Commit

Permalink
Merge pull request #1 from humanitec-architecture/docs
Browse files Browse the repository at this point in the history
chore: add docs target
  • Loading branch information
johanneswuerbach authored Dec 22, 2023
2 parents 4adbafe + d9ee901 commit 3388456
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 0 deletions.
21 changes: 21 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,31 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: hashicorp/setup-terraform@v2
with:
terraform_version: ~1.5

- name: Terraform Version
run: terraform -version

- name: Install terraform-docs
run: |
WORK_DIR=$(mktemp -d)
curl -Lo ${WORK_DIR}/terraform-docs.tar.gz https://github.com/terraform-docs/terraform-docs/releases/download/v0.16.0/terraform-docs-v0.16.0-$(uname)-amd64.tar.gz
cd ${WORK_DIR}
tar -xzf terraform-docs.tar.gz
chmod +x terraform-docs
mv terraform-docs /usr/local/bin/terraform-docs
- name: Generate docs
run: make docs

- name: Check git diff is clean (all files generated should be committed)
run: git diff --exit-code

- name: Terraform Format Check
run: make fmt-check

- name: Terraform Validate
run: make validate
12 changes: 12 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
TF_DIRS = $(patsubst %/main.tf, %, $(shell find . -type d -name .terraform -prune -o -name 'main.tf' -print))
VALIDATE_TF_DIRS = $(addprefix validate-,$(TF_DIRS))
DOCS_TF_DIRS = $(addprefix docs-,$(TF_DIRS))

# Generate docs for a terraform directories
$(DOCS_TF_DIRS): docs-%:
@echo "Docs $*"
terraform-docs --config docs/.terraform-docs.yaml $*
terraform-docs --config docs/.terraform-docs-example.yaml $*

# Generate docs
.PHONY: docs
docs: $(DOCS_TF_DIRS)
@echo "All docs generated"

# Format all terraform files
fmt:
Expand Down
9 changes: 9 additions & 0 deletions docs/.terraform-docs-example.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
formatter: "tfvars hcl"

output:
file: "./terraform.tfvars.example"
mode: replace
template: "{{ .Content }}"

settings:
description: true
14 changes: 14 additions & 0 deletions docs/.terraform-docs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
formatter: "markdown table"

output:
file: "./README.md"

sort:
enabled: true
by: required


settings:
anchor: false
hide-empty: true
lockfile: false

0 comments on commit 3388456

Please sign in to comment.