Skip to content

Commit

Permalink
chore: add docs target
Browse files Browse the repository at this point in the history
  • Loading branch information
johanneswuerbach committed Dec 21, 2023
1 parent 1f295ef commit 433e0ed
Show file tree
Hide file tree
Showing 13 changed files with 137 additions and 4 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
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ A collection of in-cluster resources ready to be used with [Humanitec](https://h

The following resources are included:

* `mysql/basic`: A basic MySQL.
* `postgres/basic`: A basic Postgres.
* [mysql/basic](./humanitec-resource-defs/mysql/basic): A basic MySQL.
* [postgres/basic](./humanitec-resource-defs/postgres/basic): A basic Postgres.

The `humanitec-resource-defs` directory includes the respective resource definitions.

Checkout `examples/main.tf` for an example using Postgres.
Checkout `examples/postgres/main.tf` for an example using Postgres.
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
21 changes: 21 additions & 0 deletions examples/postgres/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<!-- BEGIN_TF_DOCS -->


## Providers

| Name | Version |
|------|---------|
| humanitec | n/a |

## Modules

| Name | Source | Version |
|------|--------|---------|
| postgres\_basic | ../humanitec-resource-defs/postgres/basic | n/a |

## Resources

| Name | Type |
|------|------|
| [humanitec_resource_definition_criteria.postgres_basic](https://registry.terraform.io/providers/humanitec/humanitec/latest/docs/resources/resource_definition_criteria) | resource |
<!-- END_TF_DOCS -->
2 changes: 1 addition & 1 deletion examples/main.tf → examples/postgres/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ locals {
}

module "postgres_basic" {
source = "../humanitec-resource-defs/postgres/basic"
source = "../../humanitec-resource-defs/postgres/basic"

prefix = local.res_def_prefix
}
Expand Down
File renamed without changes.
Empty file.
27 changes: 27 additions & 0 deletions humanitec-resource-defs/mysql/basic/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<!-- BEGIN_TF_DOCS -->


## Providers

| Name | Version |
|------|---------|
| humanitec | n/a |

## Resources

| Name | Type |
|------|------|
| [humanitec_resource_definition.main](https://registry.terraform.io/providers/humanitec/humanitec/latest/docs/resources/resource_definition) | resource |

## Inputs

| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| prefix | n/a | `string` | `""` | no |

## Outputs

| Name | Description |
|------|-------------|
| id | n/a |
<!-- END_TF_DOCS -->
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
prefix = ""
27 changes: 27 additions & 0 deletions humanitec-resource-defs/postgres/basic/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<!-- BEGIN_TF_DOCS -->


## Providers

| Name | Version |
|------|---------|
| humanitec | n/a |

## Resources

| Name | Type |
|------|------|
| [humanitec_resource_definition.main](https://registry.terraform.io/providers/humanitec/humanitec/latest/docs/resources/resource_definition) | resource |

## Inputs

| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| prefix | n/a | `string` | `""` | no |

## Outputs

| Name | Description |
|------|-------------|
| id | n/a |
<!-- END_TF_DOCS -->
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
prefix = ""

0 comments on commit 433e0ed

Please sign in to comment.