Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Use hyphen as a separator for input parameters #3

Merged
merged 5 commits into from
Dec 31, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
111 changes: 53 additions & 58 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,67 +1,62 @@
name: Build

on:
push:
branches-ignore:
- master
pull_request:

jobs:
build:
name: 'Build example docs'
name: Build example docs
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Should generate USAGE.md for tf11_basic
uses: ./
with:
tf_docs_working_dir: examples/tf11_basic
tf_docs_template: |
# Test tf11 basic

# Usage
<!--- BEGIN_TF_DOCS --->
<!--- END_TF_DOCS --->

- name: Should generate USAGE.md for tf11_extra_args
uses: ./
with:
tf_docs_working_dir: examples/tf11_extra_args
tf_docs_content_type: document
tf_docs_indention: '3'
tf_docs_args: '--no-sensitive --no-requirements --no-required'
tf_docs_output_method: replace

- name: Should inject into README.md
uses: ./
with:
tf_docs_working_dir: examples/tf12_basic
tf_docs_output_file: README.md
tf_docs_args: ''

- name: Should generate README.md for tf12_atlantis
uses: ./
with:
tf_docs_atlantis_file: atlantis.yaml
tf_docs_output_file: README.md
tf_docs_args: '--no-providers'

- name: Should generate README.md for tf12_find and its submodules
uses: ./
with:
tf_docs_find_dir: examples/tf12_find

- name: Should generate README.md for tf12_inject
uses: ./
with:
tf_docs_find_dir: examples/tf12_inject
tf_docs_output_file: README.md
tf_docs_args: '--sort-inputs-by-required'

- name: Push up changes
uses: ./
with:
tf_docs_working_dir: examples/tf12_basic
tf_docs_content_type: json
tf_docs_output_method: print
tf_docs_git_push: 'true'
tf_docs_git_commit_message: 'chore: terraform-docs build'
- name: Checkout
uses: actions/checkout@v2

- name: Should generate USAGE.md for tf11_basic
uses: ./
with:
working-dir: examples/tf11_basic
template: |
# Test tf11 basic

# Usage

<!--- BEGIN_TF_DOCS --->
<!--- END_TF_DOCS --->

- name: Should generate USAGE.md for tf11_extra_args
uses: ./
with:
working-dir: examples/tf11_extra_args
output-format: markdown document
output-method: replace
indention: 3
args: --sensitive=false --hide requirements --required=false

- name: Should inject into README.md
uses: ./
with:
working-dir: examples/tf12_basic
output-file: README.md
args: ""

- name: Should generate README.md for tf12_atlantis
uses: ./
with:
atlantis-file: atlantis.yaml
output-file: README.md
args: --hide providers

- name: Should generate README.md for tf12_find and its submodules
uses: ./
with:
find-dir: examples/tf12_find

- name: Should generate README.md for tf12_inject
uses: ./
with:
find-dir: examples/tf12_inject
output-file: README.md
args: --sort-by-required
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@ FROM quay.io/terraform-docs/terraform-docs:0.10.1
RUN echo "http://dl-4.alpinelinux.org/alpine/edge/community" >> /etc/apk/repositories

RUN set -x \
&& apk update \
&& apk add --no-cache \
bash \
git \
jq \
openssh \
sed \
yq

COPY ./src/common.sh /common.sh
COPY ./src/docker-entrypoint.sh /docker-entrypoint.sh

ENTRYPOINT ["/docker-entrypoint.sh"]
170 changes: 78 additions & 92 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
# terraform-docs

A Github action for generating Terraform module documentation using terraform-docs
A Github action for generating Terraform module documentation using [terraform-docs](terraform-docs)
and gomplate. In addition to statically defined directory modules, this module can
search specific sub folders or parse `atlantis.yaml` for module identification and
search specific subfolders or parse `atlantis.yaml` for module identification and
doc generation. This action has the ability to auto commit docs to an open PR or
after a push to a specific branch.

## Version

`v0.1.0`

Using [terraform-docs](https://github.com/terraform-docs/terraform-docs) v0.9.1, which
is supported and tested on terraform version 0.11+ & 0.12+ but may work for others.
`v0.1.0` (uses terraform-docs v0.10.1, which is supported and tested on terraform version 0.11+ and
0.12+ but may work for others.)

## Usage

Expand All @@ -33,119 +31,103 @@ jobs:
- name: Render terraform docs inside the USAGE.md and push changes back to PR branch
uses: terraform-docs/gh-actions@v0.1.0
with:
tf_docs_working_dir: .
tf_docs_output_file: USAGE.md
tf_docs_output_method: inject
tf_docs_git_push: 'true'
working-dir: .
output-file: USAGE.md
output-method: inject
git-push: "true"
```

| WARNING: If USAGE.md already exists it will need to be updated, with the block delimeters `<!--- BEGIN_TF_DOCS --->` and `<!--- END_TF_DOCS --->`, where the generated markdown will be injected. |
| --- |

### Renders

![Example](examples/example.png?raw=true "Example Output")

## Configuration

### Inputs

| Name | Description | Default | Required |
|------|-------------|---------|----------|
| tf\_docs\_args | Additional args to pass to the command see [https://github.com/terraform-docs/terraform-docs/tree/master/docs](https://github.com/terraform-docs/terraform-docs/tree/master/docs) | `""` | false |
| tf\_docs\_atlantis\_file | Generate directories by parsing an atlantis formatted yaml to enable provide the file name to parse (eg atlantis.yaml) | `disabled` | false |
| tf\_docs\_content\_type | Generate document or table | `table` | false |
| tf\_docs\_find\_dir | Generate directories by running `find ./tf_docs_find_dir -name \*.tf` | `disabled` | false |
| tf\_docs\_git\_commit\_message | Commit message | `terraform-docs: automated action` | false |
| tf\_docs\_git\_push | If true it will commit and push the changes | `false` | false |
| tf\_docs\_indention | Indention level of Markdown sections [1, 2, 3, 4, 5] | `2` | false |
| tf\_docs\_output\_file | File in module directory where the docs should be placed | `USAGE.md` | false |
| tf\_docs\_output\_method | Method should be one of (replace/inject/print) where:<br>- `replace` the `tf_docs_output_file`<br />- `inject` the content between start and close delims<br />- `print` the output | `inject` | false |
| tf\_docs\_template | When provided will be used as the template if/when the `output-file` does not exist | # Usage<br><!--- BEGIN\_TF\_DOCS ---><br><!--- END\_TF\_DOCS ---><br> | false |
| tf\_docs\_working\_dir | Directories of terraform modules to generate docs for seperated by commas (conflicts with atlantis/find dirs) | `.` | false |

### Outputs

| Name | Description |
|------|-------------|
| num\_changed | Number of files changed |

## Important Notes

In addition to the below notes, further documentation on terraform-docs can be found
[here](https://github.com/terraform-docs/terraform-docs).
| working-dir | Comma separated list of directories to generate docs for (ignored if `atlantis-file` or `find-dir` is set) | `.` | false |
| atlantis-file | Name of Atlantis file to extract list of directories by parsing it. To enable, provide the file name (e.g. `atlantis.yaml`) | `disabled` | false |
| find-dir | Name of root directory to extract list of directories by running `find ./find_dir -name *.tf` (ignored if atlantis-file is set) | `disabled` | false |
| output-format | terraform-docs format to generate content (see [all formats]) | `markdown table` | false |
| output-method | Method should be one of `replace`, `inject`, or `print` (see below for detail) | `inject` | false |
| output-file | File in module directory where the docs should be placed | `USAGE.md` | false |
| template | When provided will be used as the template if/when the `output-file` does not exist | <pre># Usage<br><br><!--- BEGIN\_TF\_DOCS ---><br><!--- END\_TF\_DOCS ---><br></pre> | false |
| args | Additional arguments to pass down to the command (see [full documentation]) | `""` | false |
| indention | Indention level of Markdown sections [1, 2, 3, 4, 5] | `2` | false |
| git-push | If true it will commit and push the changes | `false` | false |
| git-commit-message | Commit message | `terraform-docs: automated action` | false |

## Output Method (tf\_docs\_output\_method)
#### Output Method (output-method)

#### print
- `print`

This will just print the generated file
This will just print the generated output

#### replace
- `replace`

This will create/replace the tf\_docs\_output\_file at the determined module path(s)
This will create or replace the `output-file` at the determined module path(s)

#### inject
- `inject`

Instead of replacing the output file, this will inject the generated documentation into
the existing file between the predefined delimeters: `<!--- BEGIN_TF_DOCS --->` and
`<!--- END_TF_DOCS --->`. If the file exists but does not contain the delimeters, the
action will fail for the given module. If the file doesn't exist, it will create it
using the value template which MUST have the delimeters.
Instead of replacing the `output-file`, this will inject the generated documentation
into the existing file between the predefined delimeters: `<!--- BEGIN_TF_DOCS --->`
and `<!--- END_TF_DOCS --->`. If the file exists but does not contain the delimeters,
the action will fail for the given module. If the file doesn't exist, it will create
it using the value template which MUST have the delimeters.

### Auto commit changes
#### Auto commit changes

To enable you need to ensure a few things first:

- set `tf\_docs\_git\_push` to `true`
- set `git-push` to `true`
- use `actions/checkout@v2` with the head ref for PRs or branch name for pushes
- PR

```yaml
on:
- pull_request
jobs:
docs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
ref: ${{ github.event.pull_request.head.ref }}
```

- Push

```yaml
on:
push:
branches:
- master
jobs:
docs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
ref: master
```

#### PR

```yaml
on:
- pull_request
jobs:
docs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
ref: ${{ github.event.pull_request.head.ref }}
```

#### Push

```yaml
on:
push:
branches:
- master
jobs:
docs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
ref: master
```

### Content type (tf\_docs\_content\_type)
### Outputs

- document - long form document
- table - github formatted table
- json - pure json output
| Name | Description |
|------|-------------|
| num-changed | Number of files changed |

## Examples

### Simple / Single folder
### Single folder

```yaml
- name: Generate TF Docs
uses: terraform-docs/gh-actions@v0.1.0
with:
tf_docs_working_dir: .
tf_docs_output_file: README.md
working-dir: .
output-file: README.md
```

### Multi folder
Expand All @@ -154,17 +136,17 @@ jobs:
- name: Generate TF Docs
uses: terraform-docs/gh-actions@v0.1.0
with:
tf_docs_working_dir: .,example1,example3/modules/test
tf_docs_output_file: README.md
working-dir: .,example1,example3/modules/test
output-file: README.md
```

### Use `atlantis.yaml` v3 to find all dirs
### Use `atlantis.yaml` v3 to find all directories

```yaml
- name: Generate TF docs
uses: terraform-docs/gh-actions@v0.1.0
with:
tf_docs_atlantis_file: atlantis.yaml
atlantis-file: atlantis.yaml
```

### Find all `.tf` file under a given directory
Expand All @@ -173,7 +155,11 @@ jobs:
- name: Generate TF docs
uses: terraform-docs/gh-actions@v0.1.0
with:
tf_docs_find_dir: examples/
find-dir: examples/
```

Complete examples can be found [here](https://github.com/terraform-docs/gh-actions/tree/v0.1.0/examples).
Complete examples can be found [here](https://github.com/terraform-docs/gh-actions/tree/master/examples).

[terraform-docs]: https://github.com/terraform-docs/terraform-docs
[all formats]: https://github.com/terraform-docs/terraform-docs/blob/master/docs/FORMATS_GUIDE.md
[full documentation]: https://github.com/terraform-docs/terraform-docs/tree/master/docs
Loading