Skip to content

Commit

Permalink
release v1.0.0 (#1)
Browse files Browse the repository at this point in the history
* Update README.md

* Update find test to use USAGE.md

* Ensure correct git reference

* Use head ref

* switch to external action

* test adm

* change github checkout

* terraform-docs Automated render

* terraform-docs Automated render

* terraform-docs Automated render

* terraform-docs Automated render

* terraform-docs Automated render

* Switched back to my branch

* Testing commit + push

* terraform-docs: automated action

* v1 release
  • Loading branch information
Dirrk authored Jan 3, 2020
1 parent 0c90601 commit 04e24ca
Show file tree
Hide file tree
Showing 12 changed files with 242 additions and 28 deletions.
13 changes: 6 additions & 7 deletions .github/workflows/example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ jobs:
docs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- uses: actions/checkout@v2
with:
ref: ${{ github.event.pull_request.head.ref }}

- name: Should generate USAGE.md for tf11_basic
uses: ./
with:
Expand Down Expand Up @@ -41,15 +44,11 @@ jobs:
uses: ./
with:
tf_docs_find_dir: examples/tf12_find
tf_docs_output_file: README.md

- name: Should generate README.md for tf12_inject and push up all changes
uses: ./
with:
tf_docs_find_dir: examples/tf12_inject
tf_docs_output_file: README.md
tf_docs_git_commit_message: terraform-docs automated change
tf_docs_git_commit: true
tf_docs_git_push: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
tf_docs_git_push: 'true'
tf_docs_git_commit_message: 'terraform-docs: automated action'
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Changelog

## v1
- Backwards compatible tag for v1.X.X

### v1.0.0
- initial release
75 changes: 68 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,76 @@ A Github action for generating terraform documentation (using terraform-docs)
| tf\_docs\_indention | Indention level of Markdown sections [1, 2, 3, 4, 5] (default 2) | 2 | false |
| tf\_docs\_args | Additional args to pass | --sort-inputs-by-required | 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\_git\_commit | If true it will add and commit the files | true | false |
| tf\_docs\_git\_push | If true it will push the committed changes | false | false |
| tf\_docs\_git\_commit\_message | Commit message | terraform-docs Automated render | false |
| tf\_docs\_template | When provided will be used as the template if/when the OUTPUT\_FILE does not exist | # Usage
\<!--- BEGIN\_TF\_DOCS --->
\<!--- END\_TF\_DOCS --->
| false |
| tf\_docs\_template | When provided will be used as the template if/when the OUTPUT\_FILE does not exist | # Usage \<!--- BEGIN\_TF\_DOCS --->\<!--- END\_TF\_DOCS ---> | false |


## Outputs
| Name | Description | Default | Required |
|------|-------------|---------|:-----:|
| Name | Description |
|------|-------------|
| num\_changed | Number of files changed |


## Examples

### Generate terraform docs for a single folder
```
name: Generate terraform docs
on:
- pull_request
jobs:
docs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
ref: ${{ github.event.pull_request.head.ref }}
- name: Generate TF Docs
uses: Dirrk/terraform-docs-action@v1
with:
tf_docs_working_dir: examples/tf12_inject
tf_docs_output_file: README.md
tf_docs_git_push: 'true'
```

### Generate terraform docs based on atlantis.yaml v3
```
name: Generate terraform docs
on:
- pull_request
jobs:
docs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
ref: ${{ github.event.pull_request.head.ref }}
- name: Generate TF docs
uses: Dirrk/terraform-docs-action@v1
with:
tf_docs_atlantis_file: atlantis.yaml
tf_docs_git_push: 'true'
```

### Generate terraform docs for any folder containing .tf under the find_dir
```
name: Generate terraform docs
on:
- pull_request
jobs:
docs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
ref: ${{ github.event.pull_request.head.ref }}
- name: Generate TF docs
uses: Dirrk/terraform-docs-action@v1
with:
tf_docs_find_dir: .
tf_docs_git_push: 'true'
```
8 changes: 2 additions & 6 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,14 @@ inputs:
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
required: false
default: 'inject'
tf_docs_git_commit:
description: If true it will add and commit the files
required: false
default: 'true'
tf_docs_git_push:
description: If true it will push the committed changes
description: If true it will commit and push the changes
required: false
default: 'false'
tf_docs_git_commit_message:
description: Commit message
required: false
default: 'terraform-docs Automated render'
default: 'terraform-docs: automated action'
tf_docs_template:
description: When provided will be used as the template if/when the OUTPUT_FILE does not exist
default: |
Expand Down
25 changes: 25 additions & 0 deletions examples/tf11_basic/USAGE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Test tf11 basic

## Verify
Should use the template defined instead of the default
Should inject the table under usage

# Usage
<!--- BEGIN_TF_DOCS --->
## Inputs

| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:-----:|
| subnet\_ids | A list of subnet ids to use | `list` | n/a | yes |
| vpc\_id | The id of the vpc | `string` | n/a | yes |
| extra\_environment | List of additional environment variables | `list` | `[]` | no |
| extra\_tags | Additional tags | `map` | `{}` | no |
| instance\_count | Number of instances to create | `string` | `"1"` | no |
| instance\_name | Instance name prefix | `string` | `"test-"` | no |

## Outputs

| Name | Description |
|------|-------------|
| vpc\_id | The Id of the VPC |
<!--- END_TF_DOCS --->
59 changes: 59 additions & 0 deletions examples/tf11_extra_args/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
### Inputs

The following input variables are supported:

#### extra\_environment

Description: List of additional environment variables

Type: `list`

Default: `[]`

#### extra\_tags

Description: Additional tags

Type: `map`

Default: `{}`

#### instance\_count

Description: Number of instances to create

Type: `string`

Default: `"1"`

#### instance\_name

Description: Instance name prefix

Type: `string`

Default: `"test-"`

#### subnet\_ids

Description: A list of subnet ids to use

Type: `list`

Default: n/a

#### vpc\_id

Description: The id of the vpc

Type: `string`

Default: n/a

### Outputs

The following outputs are exported:

#### vpc\_id

Description: The Id of the VPC
16 changes: 16 additions & 0 deletions examples/tf12_atlantis/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,20 @@ Should inject below Usage

# Usage
<!--- BEGIN_TF_DOCS --->
## Inputs

| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:-----:|
| subnet\_ids | A list of subnet ids to use | `list(string)` | n/a | yes |
| vpc\_id | The id of the vpc | `string` | n/a | yes |
| extra\_environment | List of additional environment variables | <code><pre>list(object({<br> name = string<br> value = string<br> }))<br></pre></code> | `[]` | no |
| extra\_tags | Additional tags | `map(string)` | `{}` | no |
| instance\_count | Number of instances to create | `number` | `1` | no |
| instance\_name | Instance name prefix | `string` | `"test-"` | no |

## Outputs

| Name | Description |
|------|-------------|
| vpc\_id | The Id of the VPC |
<!--- END_TF_DOCS --->
19 changes: 19 additions & 0 deletions examples/tf12_find/USAGE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Usage
<!--- BEGIN_TF_DOCS --->
## Inputs

| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:-----:|
| subnet\_ids | A list of subnet ids to use | `list(string)` | n/a | yes |
| vpc\_id | The id of the vpc | `string` | n/a | yes |
| extra\_environment | List of additional environment variables | <code><pre>list(object({<br> name = string<br> value = string<br> }))<br></pre></code> | `[]` | no |
| extra\_tags | Additional tags | `map(string)` | `{}` | no |
| instance\_count | Number of instances to create | `number` | `1` | no |
| instance\_name | Instance name prefix | `string` | `"test-"` | no |

## Outputs

| Name | Description |
|------|-------------|
| vpc\_id | The Id of the VPC |
<!--- END_TF_DOCS --->
19 changes: 19 additions & 0 deletions examples/tf12_find/modules/tf12_find_submodules/USAGE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Usage
<!--- BEGIN_TF_DOCS --->
## Inputs

| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:-----:|
| subnet\_ids | A list of subnet ids to use | `list(string)` | n/a | yes |
| vpc\_id | The id of the vpc | `string` | n/a | yes |
| extra\_environment | List of additional environment variables | <code><pre>list(object({<br> name = string<br> value = string<br> }))<br></pre></code> | `[]` | no |
| extra\_tags | Additional tags | `map(string)` | `{}` | no |
| instance\_count | Number of instances to create | `number` | `1` | no |
| instance\_name | Instance name prefix | `string` | `"test-"` | no |

## Outputs

| Name | Description |
|------|-------------|
| vpc\_id | The Id of the VPC |
<!--- END_TF_DOCS --->
16 changes: 16 additions & 0 deletions examples/tf12_inject/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,20 @@ Should inject below Usage

# Usage
<!--- BEGIN_TF_DOCS --->
## Inputs

| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:-----:|
| subnet\_ids | A list of subnet ids to use | `list(string)` | n/a | yes |
| vpc\_id | The id of the vpc | `string` | n/a | yes |
| extra\_environment | List of additional environment variables | <code><pre>list(object({<br> name = string<br> value = string<br> }))<br></pre></code> | `[]` | no |
| extra\_tags | Additional tags | `map(string)` | `{}` | no |
| instance\_count | Number of instances to create | `number` | `1` | no |
| instance\_name | Instance name prefix | `string` | `"test-"` | no |

## Outputs

| Name | Description |
|------|-------------|
| vpc\_id | The Id of the VPC |
<!--- END_TF_DOCS --->
11 changes: 4 additions & 7 deletions src/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,14 @@ git_commit () {
echo "::debug file=common.sh,line=20,col=1 No files changed, skipping commit"
else
git commit -m "${INPUT_TF_DOCS_GIT_COMMIT_MESSAGE}"

if [ "${INPUT_TF_DOCS_GIT_PUSH}" = "true" ]; then
git push -u origin HEAD
fi
git push
fi
}

update_doc () {

WORKING_DIR="${1}"
echo "::debug file=common.sh,line=33,col=1 WORKING_DIR=${WORKING_DIR}"
echo "::debug file=common.sh,line=30,col=1 WORKING_DIR=${WORKING_DIR}"

MY_DOC=`terraform-docs markdown "${INPUT_TF_DOCS_CONTENT_TYPE}" "${WORKING_DIR}" $TF_ARGS`

Expand All @@ -47,10 +44,10 @@ update_doc () {
fi

HAS_TF_DOCS=`grep -E '(BEGIN|END)_TF_DOCS' ${WORKING_DIR}/${INPUT_TF_DOCS_OUTPUT_FILE} | wc -l`
echo "::debug file=common.sh,line=50,col=1 HAS_TF_DOCS=${HAS_TF_DOCS}"
echo "::debug file=common.sh,line=47,col=1 HAS_TF_DOCS=${HAS_TF_DOCS}"
# Verify it has BEGIN and END markers
if [ "${HAS_TF_DOCS}" -ne 2 ]; then
echo "::error file=common.sh,line=53,col=1::Output file ${WORKING_DIR}/${INPUT_TF_DOCS_OUTPUT_FILE} does not contain BEGIN_TF_DOCS and END_TF_DOCS"
echo "::error file=common.sh,line=50,col=1::Output file ${WORKING_DIR}/${INPUT_TF_DOCS_OUTPUT_FILE} does not contain BEGIN_TF_DOCS and END_TF_DOCS"
exit 2
fi

Expand Down
2 changes: 1 addition & 1 deletion src/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ else
done
fi

if [ "${INPUT_TF_DOCS_GIT_COMMIT}" = "true" ]; then
if [ "${INPUT_TF_DOCS_GIT_PUSH}" = "true" ]; then
git_commit
else
git_changed
Expand Down

0 comments on commit 04e24ca

Please sign in to comment.