Skip to content

Commit

Permalink
Migrate action to official repository
Browse files Browse the repository at this point in the history
Signed-off-by: Khosrow Moossavi <[email protected]>
  • Loading branch information
khos2ow committed Dec 30, 2020
1 parent 26b7043 commit fe18fad
Show file tree
Hide file tree
Showing 6 changed files with 127 additions and 111 deletions.
16 changes: 8 additions & 8 deletions .github/templates/README.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
## Version
{{ $version }}

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

{{ if eq $version "master" }}
| WARNING: You should not rely on master being stable or to have accurate documentation. Please use a git tagged semver or major version tag like `v1`. |
Expand All @@ -28,7 +28,7 @@ jobs:
ref: {{"${{"}} github.event.pull_request.head.ref {{"}}"}}

- name: Render terraform docs inside the USAGE.md and push changes back to PR branch
uses: Dirrk/terraform-docs@{{ $version }}
uses: terraform-docs/gh-actions@{{ $version }}
with:
tf_docs_working_dir: .
tf_docs_output_file: USAGE.md
Expand Down Expand Up @@ -61,7 +61,7 @@ jobs:

# Important Notes

In addition to the below notes, further documentation on terraform-docs can be found [here](https://github.com/segmentio/terraform-docs)
In addition to the below notes, further documentation on terraform-docs can be found [here](https://github.com/terraform-docs/terraform-docs).

## Output Method (tf\_docs\_output\_method)

Expand Down Expand Up @@ -118,7 +118,7 @@ jobs:
## Simple / Single folder
```
- name: Generate TF Docs
uses: Dirrk/terraform-docs@{{ $version }}
uses: terraform-docs/gh-actions@{{ $version }}
with:
tf_docs_working_dir: .
tf_docs_output_file: README.md
Expand All @@ -127,7 +127,7 @@ jobs:
## Multi folder
```
- name: Generate TF Docs
uses: Dirrk/terraform-docs@{{ $version }}
uses: terraform-docs/gh-actions@{{ $version }}
with:
tf_docs_working_dir: .,example1,example3/modules/test
tf_docs_output_file: README.md
Expand All @@ -136,17 +136,17 @@ jobs:
## Use atlantis.yaml v3 to find all dirs
```
- name: Generate TF docs
uses: Dirrk/terraform-docs@{{ $version }}
uses: terraform-docs/gh-actions@{{ $version }}
with:
tf_docs_atlantis_file: atlantis.yaml
```

## Find all .tf file folders under a given directory
```yaml
- name: Generate TF docs
uses: Dirrk/terraform-docs@{{ $version }}
uses: terraform-docs/gh-actions@{{ $version }}
with:
tf_docs_find_dir: examples/
```

Complete examples can be found [here](https://github.com/Dirrk/terraform-docs/tree/{{ $version }}/examples)
Complete examples can be found [here](https://github.com/terraform-docs/gh-actions/tree/{{ $version }}/examples)
16 changes: 15 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@
FROM derekrada/terraform-docs:v1.0.8
FROM quay.io/terraform-docs/terraform-docs:0.10.1

# this can be removed when base image
# was upgraded to alpine:3.13 which has
# 'yq' in its repository out of the box.
RUN echo "http://dl-4.alpinelinux.org/alpine/edge/community" >> /etc/apk/repositories

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

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

Expand Down
143 changes: 85 additions & 58 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
# terraform-docs
A Github action for generating terraform module documentation using 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 doc generation. This action has the ability to auto commit docs to an open PR or after a push to a specific branch.

A Github action for generating Terraform module documentation using 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
doc generation. This action has the ability to auto commit docs to an open PR or
after a push to a specific branch.

## Version
v1.0.8

Using [terraform-docs](https://github.com/segmentio/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`

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.

## Usage

To use terraform-docs github action, configure a YAML workflow file, e.g.
`.github/workflows/documentation.yml`, with the following:

# Usage
To use terraform-docs github action, configure a YAML workflow file, e.g. `.github/workflows/documentation.yml`, with the following:
```yaml
name: Generate terraform docs
on:
Expand All @@ -22,64 +31,77 @@ jobs:
ref: ${{ github.event.pull_request.head.ref }}

- name: Render terraform docs inside the USAGE.md and push changes back to PR branch
uses: Dirrk/terraform-docs@v1.0.8
uses: terraform-docs/[email protected]
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
## Configuration

## Inputs
### Inputs

| Name | Description | Default | Required |
|------|-------------|---------|----------|
| tf\_docs\_args | Additional args to pass to the command see https://github.com/segmentio/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 replace will replace the tf\_docs\_output\_file, inject will inject the content between start and close delims and print will just 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
| 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 |
| atlantis-file | Generate directories by parsing an atlantis formatted yaml to enable provide the file name to parse (eg atlantis.yaml) | `disabled` | false |
| content-type | Generate document or table | `table` | false |
| find-dir | Generate directories by running `find ./find-dir -name \*.tf` | `disabled` | false |
| git-commit-message | Commit message | `terraform-docs: automated action` | false |
| git-push | If true it will commit and push the changes | `false` | false |
| indention | Indention level of Markdown sections [1, 2, 3, 4, 5] | `2` | false |
| output-file | File in module directory where the docs should be placed | `USAGE.md` | false |
| output-method | Method should be one of (replace/inject/print) where:<br>- `replace` the `output-file`<br />- `inject` the content between start and close delims<br />- `print` the output | `inject` | false |
| 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 |
| 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
## Important Notes

In addition to the below notes, further documentation on terraform-docs can be found
[here](https://github.com/terraform-docs/terraform-docs).

In addition to the below notes, further documentation on terraform-docs can be found [here](https://github.com/segmentio/terraform-docs)
### Output Method (output\_method)

## Output Method (tf\_docs\_output\_method)
#### print

### print
This will just print the generated file

### replace
This will create/replace the tf\_docs\_output\_file at the determined module path(s)
#### replace

### 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 tf\_docs\_template which MUST have the delimeters.
This will create/replace the output\_file at the determined module path(s)

#### 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.

### Auto commit changes

## Auto commit changes
To enable you need to ensure a few things first:
- set tf\_docs\_git\_push to 'true'
- use actions/checkout@v2 with the head ref for PRs or branch name for pushes

### PR
- 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
Expand All @@ -92,7 +114,8 @@ jobs:
ref: ${{ github.event.pull_request.head.ref }}
```

### Push
#### Push

```yaml
on:
push:
Expand All @@ -107,46 +130,50 @@ jobs:
ref: master
```

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

- document - long form document
- table - github formatted table
- json - pure json output

## Examples

# Examples
### Simple / Single folder

## Simple / Single folder
```
```yaml
- name: Generate TF Docs
uses: Dirrk/terraform-docs@v1.0.8
uses: terraform-docs/[email protected]
with:
tf_docs_working_dir: .
tf_docs_output_file: README.md
working_dir: .
output_file: README.md
```

## Multi folder
```
### Multi folder

```yaml
- name: Generate TF Docs
uses: Dirrk/terraform-docs@v1.0.8
uses: terraform-docs/[email protected]
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 dirs

```yaml
- name: Generate TF docs
uses: Dirrk/terraform-docs@v1.0.8
uses: terraform-docs/[email protected]
with:
tf_docs_atlantis_file: atlantis.yaml
atlantis_file: atlantis.yaml
```

## Find all .tf file folders under a given directory
### Find all `.tf` file under a given directory

```yaml
- name: Generate TF docs
uses: Dirrk/terraform-docs@v1.0.8
uses: terraform-docs/[email protected]
with:
tf_docs_find_dir: examples/
find_dir: examples/
```

Complete examples can be found [here](https://github.com/Dirrk/terraform-docs/tree/v1.0.8/examples)
Complete examples can be found [here](https://github.com/terraform-docs/gh-actions/tree/v0.1.0/examples).
34 changes: 18 additions & 16 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,48 +1,49 @@
name: terraform-docs
author: Derek Rada
description: A Github action for generating terraform module documentation using terraform-docs and gomplate.
author: terraform-docs Authors
description: A Github action for generating Terraform module documentation using terraform-docs and gomplate.

inputs:
tf_docs_working_dir:
working_dir:
description: Directories of terraform modules to generate docs for seperated by commas (conflicts with atlantis/find dirs)
required: false
default: '.'
tf_docs_atlantis_file:
atlantis_file:
description: Generate directories by parsing an atlantis formatted yaml to enable provide the file name to parse (eg atlantis.yaml)
required: false
default: 'disabled'
tf_docs_find_dir:
description: Generate directories by running find ./tf_docs_find_dir -name *.tf
find_dir:
description: Generate directories by running find ./find_dir -name *.tf
required: false
default: 'disabled'
tf_docs_output_file:
output_file:
description: File in module directory where the docs should be placed
required: false
default: 'USAGE.md'
tf_docs_content_type:
content_type:
description: Generate document or table
required: false
default: 'table'
tf_docs_indention:
indention:
description: Indention level of Markdown sections [1, 2, 3, 4, 5]
required: false
default: '2'
tf_docs_args:
description: Additional args to pass to the command see https://github.com/segmentio/terraform-docs/tree/master/docs
args:
description: Additional args to pass to the command see https://github.com/terraform-docs/terraform-docs/tree/master/docs
required: false
default: ''
tf_docs_output_method:
description: Method should be one of (replace/inject/print) where replace will replace the tf_docs_output_file, inject will inject the content between start and close delims and print will just print the output
output_method:
description: Method should be one of (replace/inject/print) where replace will replace the output_file, inject will inject the content between start and close delims and print will just print the output
required: false
default: 'inject'
tf_docs_git_push:
git_push:
description: If true it will commit and push the changes
required: false
default: 'false'
tf_docs_git_commit_message:
git_commit_message:
description: Commit message
required: false
default: 'terraform-docs: automated action'
tf_docs_template:
template:
description: When provided will be used as the template if/when the OUTPUT_FILE does not exist
default: |
# Usage
Expand All @@ -57,6 +58,7 @@ outputs:
runs:
using: docker
image: Dockerfile


branding:
icon: file-text
Expand Down
Loading

0 comments on commit fe18fad

Please sign in to comment.