Skip to content

Commit

Permalink
ci: add terraform-docs workflow (#27)
Browse files Browse the repository at this point in the history
* ci: add `terraform-docs` workflow

* terraform-docs: automated action

* ci: tweak `terraform-docs` commit message

* ci: add paths filter

* ci: fixup job names

* chore: update `git-commit-message`

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
JoshuaLicense and github-actions[bot] authored Mar 11, 2024
1 parent 8013a0b commit ae24a6f
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 3 deletions.
21 changes: 21 additions & 0 deletions .github/workflows/terraform-docs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Terraform docs

on:
pull_request:
paths:
- "infra/terraform/modules/**"

jobs:
generate-terraform-docs:
name: Generate
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.ref }}

- uses: terraform-docs/gh-actions@main
with:
find-dir: "infra/terraform/modules"
git-commit-message: "docs: update Terraform docs"
git-push: true
3 changes: 0 additions & 3 deletions .lintstagedrc

This file was deleted.

27 changes: 27 additions & 0 deletions .lintstagedrc.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import chalk from "chalk";
import path from "path";
import { execSync } from "child_process";

const generateTerraformDocs = (filenames) => {
try {
execSync("terraform-docs --version", { stdio: "ignore" });
} catch (error) {
const message = `Warning: \`terraform-docs\` is not installed so cannot update Terraform module docs. Please install \`terraform-docs\`, see https://github.com/terraform-docs/terraform-docs/#installation.`;

console.warn(chalk.yellow(message));
return [];
}

const modules = [...new Set(filenames.map((filename) => path.dirname(filename)))];

return [
...modules.map((module) => `terraform-docs markdown --output-file ${module}/README.md ${module}`),
"git add terraform/modules/**/README.md",
];
};

export default {
"*": ["prettier --ignore-unknown --write"],
"*.{tf,tfvars}": ["terraform fmt"],
"terraform/modules/**/*": generateTerraformDocs,
};
25 changes: 25 additions & 0 deletions infra/terraform/modules/account/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<!-- BEGIN_TF_DOCS -->
## Requirements

No requirements.

## Providers

No providers.

## Modules

No modules.

## Resources

No resources.

## Inputs

No inputs.

## Outputs

No outputs.
<!-- END_TF_DOCS -->
25 changes: 25 additions & 0 deletions infra/terraform/modules/service/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<!-- BEGIN_TF_DOCS -->
## Requirements

No requirements.

## Providers

No providers.

## Modules

No modules.

## Resources

No resources.

## Inputs

No inputs.

## Outputs

No outputs.
<!-- END_TF_DOCS -->

0 comments on commit ae24a6f

Please sign in to comment.