.
675 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # This repository has been moved to https://github.com/terraform-docs/gh-actions
2 |
3 | ---
4 |
5 | # terraform-docs
6 | 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.
7 | ## Version
8 | v1.0.8
9 |
10 | 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.
11 |
12 |
13 |
14 | # Usage
15 | To use terraform-docs github action, configure a YAML workflow file, e.g. `.github/workflows/documentation.yml`, with the following:
16 | ```yaml
17 | name: Generate terraform docs
18 | on:
19 | - pull_request
20 | jobs:
21 | docs:
22 | runs-on: ubuntu-latest
23 | steps:
24 | - uses: actions/checkout@v2
25 | with:
26 | ref: ${{ github.event.pull_request.head.ref }}
27 |
28 | - name: Render terraform docs inside the USAGE.md and push changes back to PR branch
29 | uses: Dirrk/terraform-docs@v1.0.8
30 | with:
31 | tf_docs_working_dir: .
32 | tf_docs_output_file: USAGE.md
33 | tf_docs_output_method: inject
34 | tf_docs_git_push: 'true'
35 | ```
36 | | WARNING: If USAGE.md already exists it will need to be updated, with the block delimeters `` and ``, where the generated markdown will be injected. |
37 | | --- |
38 |
39 | ### Renders
40 | 
41 |
42 | # Configuration
43 |
44 | ## Inputs
45 |
46 | | Name | Description | Default | Required |
47 | |------|-------------|---------|----------|
48 | | tf\_docs\_args | Additional args to pass to the command see https://github.com/segmentio/terraform-docs/tree/master/docs | | false |
49 | | 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 |
50 | | tf\_docs\_content\_type | Generate document or table | table | false |
51 | | tf\_docs\_find\_dir | Generate directories by running find ./tf\_docs\_find\_dir -name \*.tf | disabled | false |
52 | | tf\_docs\_git\_commit\_message | Commit message | terraform-docs: automated action | false |
53 | | tf\_docs\_git\_push | If true it will commit and push the changes | false | false |
54 | | tf\_docs\_indention | Indention level of Markdown sections [1, 2, 3, 4, 5] | 2 | false |
55 | | tf\_docs\_output\_file | File in module directory where the docs should be placed | USAGE.md | false |
56 | | 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 |
57 | | tf\_docs\_template | When provided will be used as the template if/when the OUTPUT\_FILE does not exist | # Usage
| false |
58 | | tf\_docs\_working\_dir | Directories of terraform modules to generate docs for seperated by commas (conflicts with atlantis/find dirs) | . | false |
59 |
60 | ## Outputs
61 |
62 | | Name | Description |
63 | |------|-------------|
64 | | num\_changed | Number of files changed |
65 |
66 | # Important Notes
67 |
68 | In addition to the below notes, further documentation on terraform-docs can be found [here](https://github.com/segmentio/terraform-docs)
69 |
70 | ## Output Method (tf\_docs\_output\_method)
71 |
72 | ### print
73 | This will just print the generated file
74 |
75 | ### replace
76 | This will create/replace the tf\_docs\_output\_file at the determined module path(s)
77 |
78 | ### inject
79 | Instead of replacing the output file, this will inject the generated documentation into the existing file between the predefined delimeters: `` and ``. 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.
80 |
81 | ## Auto commit changes
82 | To enable you need to ensure a few things first:
83 | - set tf\_docs\_git\_push to 'true'
84 | - use actions/checkout@v2 with the head ref for PRs or branch name for pushes
85 |
86 | ### PR
87 | ```yaml
88 | on:
89 | - pull_request
90 | jobs:
91 | docs:
92 | runs-on: ubuntu-latest
93 | steps:
94 | - uses: actions/checkout@v2
95 | with:
96 | ref: ${{ github.event.pull_request.head.ref }}
97 | ```
98 |
99 | ### Push
100 | ```yaml
101 | on:
102 | push:
103 | branches:
104 | - master
105 | jobs:
106 | docs:
107 | runs-on: ubuntu-latest
108 | steps:
109 | - uses: actions/checkout@v2
110 | with:
111 | ref: master
112 | ```
113 |
114 | ## Content type (tf\_docs\_content\_type)
115 | - document - long form document
116 | - table - github formatted table
117 | - json - pure json output
118 |
119 |
120 | # Examples
121 |
122 | ## Simple / Single folder
123 | ```
124 | - name: Generate TF Docs
125 | uses: Dirrk/terraform-docs@v1.0.8
126 | with:
127 | tf_docs_working_dir: .
128 | tf_docs_output_file: README.md
129 | ```
130 |
131 | ## Multi folder
132 | ```
133 | - name: Generate TF Docs
134 | uses: Dirrk/terraform-docs@v1.0.8
135 | with:
136 | tf_docs_working_dir: .,example1,example3/modules/test
137 | tf_docs_output_file: README.md
138 | ```
139 |
140 | ## Use atlantis.yaml v3 to find all dirs
141 | ```
142 | - name: Generate TF docs
143 | uses: Dirrk/terraform-docs@v1.0.8
144 | with:
145 | tf_docs_atlantis_file: atlantis.yaml
146 | ```
147 |
148 | ## Find all .tf file folders under a given directory
149 | ```yaml
150 | - name: Generate TF docs
151 | uses: Dirrk/terraform-docs@v1.0.8
152 | with:
153 | tf_docs_find_dir: examples/
154 | ```
155 |
156 | Complete examples can be found [here](https://github.com/Dirrk/terraform-docs/tree/v1.0.8/examples)
157 |
--------------------------------------------------------------------------------
/action.yml:
--------------------------------------------------------------------------------
1 | name: terraform-docs-archived
2 | author: Derek Rada
3 | description: A Github action for generating terraform module documentation using terraform-docs and gomplate.
4 | inputs:
5 | tf_docs_working_dir:
6 | description: Directories of terraform modules to generate docs for seperated by commas (conflicts with atlantis/find dirs)
7 | required: false
8 | default: '.'
9 | tf_docs_atlantis_file:
10 | description: Generate directories by parsing an atlantis formatted yaml to enable provide the file name to parse (eg atlantis.yaml)
11 | required: false
12 | default: 'disabled'
13 | tf_docs_find_dir:
14 | description: Generate directories by running find ./tf_docs_find_dir -name *.tf
15 | required: false
16 | default: 'disabled'
17 | tf_docs_output_file:
18 | description: File in module directory where the docs should be placed
19 | required: false
20 | default: 'USAGE.md'
21 | tf_docs_content_type:
22 | description: Generate document or table
23 | required: false
24 | default: 'table'
25 | tf_docs_indention:
26 | description: Indention level of Markdown sections [1, 2, 3, 4, 5]
27 | required: false
28 | default: '2'
29 | tf_docs_args:
30 | description: Additional args to pass to the command see https://github.com/segmentio/terraform-docs/tree/master/docs
31 | required: false
32 | default: ''
33 | tf_docs_output_method:
34 | 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
35 | required: false
36 | default: 'inject'
37 | tf_docs_git_push:
38 | description: If true it will commit and push the changes
39 | required: false
40 | default: 'false'
41 | tf_docs_git_commit_message:
42 | description: Commit message
43 | required: false
44 | default: 'terraform-docs: automated action'
45 | tf_docs_template:
46 | description: When provided will be used as the template if/when the OUTPUT_FILE does not exist
47 | default: |
48 | # Usage
49 |
50 |
51 | required: false
52 |
53 | outputs:
54 | num_changed:
55 | description: Number of files changed
56 |
57 | runs:
58 | using: docker
59 | image: Dockerfile
60 |
61 | branding:
62 | icon: file-text
63 | color: gray-dark
64 |
--------------------------------------------------------------------------------
/atlantis.yaml:
--------------------------------------------------------------------------------
1 | version: 3
2 | projects:
3 | - name: examples_atlantis
4 | dir: examples/tf12_atlantis
5 |
--------------------------------------------------------------------------------
/docker/Dockerfile:
--------------------------------------------------------------------------------
1 | FROM golang:1.13-alpine3.10 as builder
2 | ARG VERSION=v0.9.1
3 |
4 | # Install dependencies
5 | RUN set -x \
6 | && apk add --no-cache \
7 | bash \
8 | curl \
9 | gcc \
10 | git \
11 | make \
12 | wget \
13 | && GO111MODULE="on" go get "github.com/segmentio/terraform-docs@${VERSION}"
14 |
15 | RUN set -x \
16 | && mkdir -p /outputs \
17 | && wget -O yq https://github.com/mikefarah/yq/releases/download/2.4.1/yq_linux_amd64 \
18 | && chmod 755 yq \
19 | && mv yq /outputs/yq
20 |
21 | FROM alpine:3.10
22 | COPY --from=builder /go/bin/terraform-docs /usr/local/bin/terraform-docs
23 | COPY --from=builder /outputs/* /usr/local/bin/
24 |
25 | RUN apk add --no-cache bash sed git jq
26 |
27 | ENTRYPOINT ["/usr/local/bin/terraform-docs"]
28 |
--------------------------------------------------------------------------------
/examples/README.md:
--------------------------------------------------------------------------------
1 | # Examples
2 |
3 | These examples are committed with the documentation rendered just like a normal repo would. They are generated using this github action on each build of the code. Which you can find here https://github.com/Dirrk/terraform-docs/tree/master/.github/workflows/example.yml
4 |
--------------------------------------------------------------------------------
/examples/example.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Dirrk/terraform-docs/9a7ec5a750e86925fbe94ba1193f937466eb8bc6/examples/example.png
--------------------------------------------------------------------------------
/examples/tf11_basic/README.md:
--------------------------------------------------------------------------------
1 | # Test tf11 basic
2 |
3 | ## Input
4 | ```
5 | - name: Should generate USAGE.md for tf11_basic
6 | uses: ./
7 | with:
8 | tf_docs_working_dir: examples/tf11_basic
9 | tf_docs_template: |
10 | # Test tf11 basic
11 |
12 | ## Verify
13 | Should use the template defined instead of the default
14 | Should inject the table under usage
15 |
16 | # Usage
17 |
18 |
19 | ```
20 |
21 | ## Verify
22 | - Should use the template defined instead of the default
23 | - Should inject the table under usage
24 |
25 |
26 | ## Output
27 | See USAGE.md
28 |
--------------------------------------------------------------------------------
/examples/tf11_basic/USAGE.md:
--------------------------------------------------------------------------------
1 | # Test tf11 basic
2 |
3 | # Usage
4 |
5 | ## Requirements
6 |
7 | | Name | Version |
8 | |------|---------|
9 | | aws | < 2.2.0 |
10 | | consul | >= 1.0.0 |
11 |
12 | ## Providers
13 |
14 | | Name | Version |
15 | |------|---------|
16 | | aws | < 2.2.0 |
17 | | consul | >= 1.0.0 |
18 |
19 | ## Inputs
20 |
21 | | Name | Description | Type | Default | Required |
22 | |------|-------------|------|---------|:--------:|
23 | | extra\_environment | List of additional environment variables | `list` | `[]` | no |
24 | | extra\_tags | Additional tags | `map` | `{}` | no |
25 | | instance\_count | Number of instances to create | `string` | `"1"` | no |
26 | | instance\_name | Instance name prefix | `string` | `"test-"` | no |
27 | | subnet\_ids | A list of subnet ids to use | `list` | n/a | yes |
28 | | vpc\_id | The id of the vpc | `string` | n/a | yes |
29 |
30 | ## Outputs
31 |
32 | | Name | Description |
33 | |------|-------------|
34 | | vpc\_id | The Id of the VPC |
35 |
36 |
37 |
--------------------------------------------------------------------------------
/examples/tf11_basic/main.tf:
--------------------------------------------------------------------------------
1 | variable "vpc_id" {
2 | description = "The id of the vpc"
3 | type = "string"
4 | }
5 |
6 | variable "subnet_ids" {
7 | description = "A list of subnet ids to use"
8 | type = "list"
9 | }
10 |
11 | variable "instance_name" {
12 | description = "Instance name prefix"
13 | type = "string"
14 | default = "test-"
15 | }
16 |
17 | variable "instance_count" {
18 | description = "Number of instances to create"
19 | type = "string"
20 | default = "1"
21 | }
22 |
23 | variable "extra_tags" {
24 | description = "Additional tags"
25 | type = "map"
26 | default = {}
27 | }
28 |
29 | variable "extra_environment" {
30 | description = "List of additional environment variables"
31 | type = "list"
32 | default = []
33 | }
34 |
35 | output "vpc_id" {
36 | description = "The Id of the VPC"
37 | value = "${var.vpc_id}"
38 | }
39 |
40 | provider "aws" {
41 | region = "us-east-1"
42 | version = "< 2.2.0"
43 | }
44 |
45 | provider "consul" {
46 | alias = "ae1"
47 | version = ">= 1.0.0"
48 | }
49 |
50 | data "aws_acm_certificate" "test-cert" {
51 | domain = "test.example.com"
52 | statuses = ["ISSUED"]
53 | }
54 |
55 | data "consul_key" "test" {
56 | key {
57 | name = "test"
58 | path = "examples/test.json"
59 | default = "{}"
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/examples/tf11_extra_args/README.md:
--------------------------------------------------------------------------------
1 | # TF 11 Extra Args
2 |
3 | ## Input
4 | ```
5 | - name: Should generate USAGE.md for tf11_extra_args
6 | uses: ./
7 | with:
8 | tf_docs_working_dir: examples/tf11_extra_args
9 | tf_docs_content_type: document
10 | tf_docs_indention: '3'
11 | tf_docs_args: '--no-sensitive --no-requirements --no-required'
12 | tf_docs_output_method: replace
13 | ```
14 |
15 | ## Verify
16 | - Creates a document instead of table
17 | - Indents the "##" by 3 instead of 2 ie: "###"
18 | - Should not document required fields
19 | - Should replace USAGE.md
20 |
21 | # Usage
22 | See USAGE.md
23 |
--------------------------------------------------------------------------------
/examples/tf11_extra_args/USAGE.md:
--------------------------------------------------------------------------------
1 | ### Providers
2 |
3 | The following providers are used by this module:
4 |
5 | - aws (< 2.2.0)
6 |
7 | - consul (>= 1.0.0)
8 |
9 | ### Inputs
10 |
11 | The following input variables are supported:
12 |
13 | #### extra\_environment
14 |
15 | Description: List of additional environment variables
16 |
17 | Type: `list`
18 |
19 | Default: `[]`
20 |
21 | #### extra\_tags
22 |
23 | Description: Additional tags
24 |
25 | Type: `map`
26 |
27 | Default: `{}`
28 |
29 | #### instance\_count
30 |
31 | Description: Number of instances to create
32 |
33 | Type: `string`
34 |
35 | Default: `"1"`
36 |
37 | #### instance\_name
38 |
39 | Description: Instance name prefix
40 |
41 | Type: `string`
42 |
43 | Default: `"test-"`
44 |
45 | #### subnet\_ids
46 |
47 | Description: A list of subnet ids to use
48 |
49 | Type: `list`
50 |
51 | Default: n/a
52 |
53 | #### vpc\_id
54 |
55 | Description: The id of the vpc
56 |
57 | Type: `string`
58 |
59 | Default: n/a
60 |
61 | ### Outputs
62 |
63 | The following outputs are exported:
64 |
65 | #### vpc\_id
66 |
67 | Description: The Id of the VPC
68 |
--------------------------------------------------------------------------------
/examples/tf11_extra_args/main.tf:
--------------------------------------------------------------------------------
1 | ../tf11_basic/main.tf
--------------------------------------------------------------------------------
/examples/tf12_atlantis/README.md:
--------------------------------------------------------------------------------
1 | # Test Atlantis
2 |
3 | ## Input
4 | ```
5 | - name: Should generate README.md for tf12_atlantis
6 | uses: ./
7 | with:
8 | tf_docs_atlantis_file: atlantis.yaml
9 | tf_docs_output_file: README.md
10 | ```
11 |
12 | ## Verify
13 | - Should inject below Usage in README.md
14 |
15 | # Usage
16 |
17 | ## Requirements
18 |
19 | | Name | Version |
20 | |------|---------|
21 | | aws | ~> 2.20.0 |
22 | | consul | >= 2.4.0 |
23 |
24 | ## Inputs
25 |
26 | | Name | Description | Type | Default | Required |
27 | |------|-------------|------|---------|:--------:|
28 | | extra\_environment | List of additional environment variables | list(object({
name = string
value = string
}))
| `[]` | no |
29 | | extra\_tags | Additional tags | `map(string)` | `{}` | no |
30 | | instance\_count | Number of instances to create | `number` | `1` | no |
31 | | instance\_name | Instance name prefix | `string` | `"test-"` | no |
32 | | subnet\_ids | A list of subnet ids to use | `list(string)` | n/a | yes |
33 | | vpc\_id | The id of the vpc | `string` | n/a | yes |
34 |
35 | ## Outputs
36 |
37 | | Name | Description |
38 | |------|-------------|
39 | | vpc\_id | The Id of the VPC |
40 |
41 |
42 |
--------------------------------------------------------------------------------
/examples/tf12_atlantis/main.tf:
--------------------------------------------------------------------------------
1 | ../tf12_basic/main.tf
--------------------------------------------------------------------------------
/examples/tf12_basic/README.md:
--------------------------------------------------------------------------------
1 | # Test TF12 Basic
2 |
3 | ## Input
4 | ```
5 | - name: Should inject into README.md
6 | uses: ./
7 | with:
8 | tf_docs_working_dir: examples/tf12_basic
9 | tf_docs_output_file: README.md
10 | ```
11 |
12 | ## Verify
13 | - Should inject below Usage in README.md
14 |
15 | # Usage
16 |
17 |
18 | ## Requirements
19 |
20 | | Name | Version |
21 | |------|---------|
22 | | aws | ~> 2.20.0 |
23 | | consul | >= 2.4.0 |
24 |
25 | ## Providers
26 |
27 | | Name | Version |
28 | |------|---------|
29 | | aws | ~> 2.20.0 |
30 | | consul | >= 2.4.0 |
31 |
32 | ## Inputs
33 |
34 | | Name | Description | Type | Default | Required |
35 | |------|-------------|------|---------|:--------:|
36 | | extra\_environment | List of additional environment variables | list(object({
name = string
value = string
}))
| `[]` | no |
37 | | extra\_tags | Additional tags | `map(string)` | `{}` | no |
38 | | instance\_count | Number of instances to create | `number` | `1` | no |
39 | | instance\_name | Instance name prefix | `string` | `"test-"` | no |
40 | | subnet\_ids | A list of subnet ids to use | `list(string)` | n/a | yes |
41 | | vpc\_id | The id of the vpc | `string` | n/a | yes |
42 |
43 | ## Outputs
44 |
45 | | Name | Description |
46 | |------|-------------|
47 | | vpc\_id | The Id of the VPC |
48 |
49 |
50 |
--------------------------------------------------------------------------------
/examples/tf12_basic/main.tf:
--------------------------------------------------------------------------------
1 | provider "aws" {
2 | version = "~> 2.20.0"
3 |
4 | region = "us-east-1"
5 | }
6 |
7 | provider "consul" {
8 | alias = "test"
9 | }
10 |
11 | terraform {
12 | required_providers {
13 | consul = ">= 2.4.0"
14 | }
15 | }
16 |
17 | data "aws_acm_certificate" "test-cert" {
18 | domain = "test.example.com"
19 | statuses = ["ISSUED"]
20 | }
21 |
22 | data "consul_key" "test" {
23 | key {
24 | name = "test"
25 | path = "examples/test.json"
26 | default = "{}"
27 | }
28 | }
29 |
30 | variable "vpc_id" {
31 | description = "The id of the vpc"
32 | type = string
33 | }
34 |
35 | variable "subnet_ids" {
36 | description = "A list of subnet ids to use"
37 | type = list(string)
38 | }
39 |
40 | variable "instance_name" {
41 | description = "Instance name prefix"
42 | type = string
43 | default = "test-"
44 | }
45 |
46 | variable "instance_count" {
47 | description = "Number of instances to create"
48 | type = number
49 | default = 1
50 | }
51 |
52 | variable "extra_tags" {
53 | description = "Additional tags"
54 | type = map(string)
55 | default = {}
56 | }
57 |
58 | variable "extra_environment" {
59 | description = "List of additional environment variables"
60 | type = list(object({
61 | name = string
62 | value = string
63 | }))
64 | default = []
65 | }
66 |
67 | output "vpc_id" {
68 | description = "The Id of the VPC"
69 | value = var.vpc_id
70 | }
71 |
--------------------------------------------------------------------------------
/examples/tf12_find/README.md:
--------------------------------------------------------------------------------
1 | # Test Find
2 |
3 | ## Input
4 | ```
5 | - name: Should generate README.md for tf12_find and its submodules
6 | uses: ./
7 | with:
8 | tf_docs_find_dir: examples/tf12_find
9 | ```
10 |
11 | ## Verify
12 |
13 | - Should replace USAGE.md in examples/tf12\_find and examples/tf12\_find/modules/tf12\_find_submodules
14 |
15 | # Usage
16 | See USAGE.md
17 |
--------------------------------------------------------------------------------
/examples/tf12_find/USAGE.md:
--------------------------------------------------------------------------------
1 | # Usage
2 |
3 | ## Requirements
4 |
5 | | Name | Version |
6 | |------|---------|
7 | | aws | ~> 2.20.0 |
8 | | consul | >= 2.4.0 |
9 |
10 | ## Providers
11 |
12 | | Name | Version |
13 | |------|---------|
14 | | aws | ~> 2.20.0 |
15 | | consul | >= 2.4.0 |
16 |
17 | ## Inputs
18 |
19 | | Name | Description | Type | Default | Required |
20 | |------|-------------|------|---------|:--------:|
21 | | extra\_environment | List of additional environment variables | list(object({
name = string
value = string
}))
| `[]` | no |
22 | | extra\_tags | Additional tags | `map(string)` | `{}` | no |
23 | | instance\_count | Number of instances to create | `number` | `1` | no |
24 | | instance\_name | Instance name prefix | `string` | `"test-"` | no |
25 | | subnet\_ids | A list of subnet ids to use | `list(string)` | n/a | yes |
26 | | vpc\_id | The id of the vpc | `string` | n/a | yes |
27 |
28 | ## Outputs
29 |
30 | | Name | Description |
31 | |------|-------------|
32 | | vpc\_id | The Id of the VPC |
33 |
34 |
35 |
--------------------------------------------------------------------------------
/examples/tf12_find/main.tf:
--------------------------------------------------------------------------------
1 | ../tf12_basic/main.tf
--------------------------------------------------------------------------------
/examples/tf12_find/modules/tf12_find_submodules/USAGE.md:
--------------------------------------------------------------------------------
1 | # Usage
2 |
3 | ## Requirements
4 |
5 | No requirements.
6 |
7 | ## Providers
8 |
9 | No provider.
10 |
11 | ## Inputs
12 |
13 | | Name | Description | Type | Default | Required |
14 | |------|-------------|------|---------|:--------:|
15 | | extra\_environment | List of additional environment variables | list(object({
name = string
value = string
}))
| `[]` | no |
16 | | extra\_tags | Additional tags | `map(string)` | `{}` | no |
17 | | instance\_count | Number of instances to create | `number` | `1` | no |
18 | | instance\_name | Instance name prefix | `string` | `"test-"` | no |
19 | | subnet\_ids | A list of subnet ids to use | `list(string)` | n/a | yes |
20 | | vpc\_id | The id of the vpc | `string` | n/a | yes |
21 |
22 | ## Outputs
23 |
24 | | Name | Description |
25 | |------|-------------|
26 | | vpc\_id | The Id of the VPC |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/examples/tf12_find/modules/tf12_find_submodules/main.tf:
--------------------------------------------------------------------------------
1 | variable "vpc_id" {
2 | description = "The id of the vpc"
3 | type = string
4 | }
5 |
6 | variable "subnet_ids" {
7 | description = "A list of subnet ids to use"
8 | type = list(string)
9 | }
10 |
11 | variable "instance_name" {
12 | description = "Instance name prefix"
13 | type = string
14 | default = "test-"
15 | }
16 |
17 | variable "instance_count" {
18 | description = "Number of instances to create"
19 | type = number
20 | default = 1
21 | }
22 |
23 | variable "extra_tags" {
24 | description = "Additional tags"
25 | type = map(string)
26 | default = {}
27 | }
28 |
29 | variable "extra_environment" {
30 | description = "List of additional environment variables"
31 | type = list(object({
32 | name = string
33 | value = string
34 | }))
35 | default = []
36 | }
37 |
38 | output "vpc_id" {
39 | description = "The Id of the VPC"
40 | value = var.vpc_id
41 | }
42 |
--------------------------------------------------------------------------------
/examples/tf12_inject/README.md:
--------------------------------------------------------------------------------
1 | # Test Inject
2 |
3 | ## Input
4 | ```
5 | - name: Should generate README.md for tf12_inject and push up all changes
6 | uses: ./
7 | with:
8 | tf_docs_find_dir: examples/tf12_inject
9 | tf_docs_output_file: README.md
10 | tf_docs_git_push: 'true'
11 | tf_docs_git_commit_message: 'terraform-docs: automated action'
12 | ```
13 |
14 | ## Verify
15 | - Should inject below Usage
16 | - Should push up changes on build with commit message 'terraform-docs: automated action'
17 |
18 | # Usage
19 |
20 | ## Requirements
21 |
22 | | Name | Version |
23 | |------|---------|
24 | | aws | ~> 2.20.0 |
25 | | consul | >= 2.4.0 |
26 |
27 | ## Providers
28 |
29 | | Name | Version |
30 | |------|---------|
31 | | aws | ~> 2.20.0 |
32 | | consul | >= 2.4.0 |
33 |
34 | ## Inputs
35 |
36 | | Name | Description | Type | Default | Required |
37 | |------|-------------|------|---------|:--------:|
38 | | subnet\_ids | A list of subnet ids to use | `list(string)` | n/a | yes |
39 | | vpc\_id | The id of the vpc | `string` | n/a | yes |
40 | | extra\_environment | List of additional environment variables | list(object({
name = string
value = string
}))
| `[]` | no |
41 | | extra\_tags | Additional tags | `map(string)` | `{}` | no |
42 | | instance\_count | Number of instances to create | `number` | `1` | no |
43 | | instance\_name | Instance name prefix | `string` | `"test-"` | no |
44 |
45 | ## Outputs
46 |
47 | | Name | Description |
48 | |------|-------------|
49 | | vpc\_id | The Id of the VPC |
50 |
51 |
52 |
--------------------------------------------------------------------------------
/examples/tf12_inject/main.tf:
--------------------------------------------------------------------------------
1 | ../tf12_basic/main.tf
--------------------------------------------------------------------------------
/scripts/pre-release.sh:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 | set -e
3 |
4 | NEW_VERSION=$1
5 |
6 | if [ -z "${NEW_VERSION}" ]; then
7 | echo "Must have version like: v1.0.1"
8 | exit 1
9 | fi
10 |
11 | CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
12 |
13 | if [[ "${CURRENT_BRANCH}" == "master" ]]; then
14 | git pull origin master
15 | git checkout -b "release/${NEW_VERSION}"
16 | elif [[ "${CURRENT_BRANCH}" == "release/${NEW_VERSION}" ]]; then
17 | git pull origin master
18 | else
19 | echo "Invalid branch"
20 | exit 1
21 | fi
22 |
23 | # Update the README
24 | VERSION=$NEW_VERSION gomplate -d action=action.yml -f .github/templates/README.tpl -o README.md
25 |
26 | # Update Dockerfile
27 | gsed -i "s|FROM derekrada/terraform-docs:.*|FROM derekrada/terraform-docs:${NEW_VERSION}|" ./Dockerfile
28 |
29 | git commit -am "chore: prepare release ${NEW_VERSION}"
30 | git push --set-upstream origin "release/${NEW_VERSION}"
31 |
--------------------------------------------------------------------------------
/scripts/release.sh:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 | set -e
3 |
4 | CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
5 |
6 | if [[ "${CURRENT_BRANCH}" != "master" ]]; then
7 | echo "Must be on master"
8 | exit 1
9 | fi
10 |
11 | NEW_VERSION=$1
12 |
13 | if [ -z "${NEW_VERSION}" ]; then
14 | echo "Must have version like: v1.0.1"
15 | exit 1
16 | fi
17 |
18 | git pull origin master
19 | git pull --tags --all -f
20 | git tag "${NEW_VERSION}"
21 | git push --tags
22 |
--------------------------------------------------------------------------------
/src/common.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | set -e
3 |
4 | git_add_doc () {
5 |
6 | MY_FILE="${1}"
7 | git add "${MY_FILE}"
8 | }
9 |
10 | git_changed () {
11 | GIT_FILES_CHANGED=`git status --porcelain | grep -E '([MA]\W).+' | wc -l`
12 | echo "::set-output name=num_changed::${GIT_FILES_CHANGED}"
13 | }
14 |
15 | git_setup () {
16 | git config --global user.name ${GITHUB_ACTOR}
17 | git config --global user.email ${GITHUB_ACTOR}@users.noreply.github.com
18 | git fetch --depth=1 origin +refs/tags/*:refs/tags/*
19 | }
20 |
21 | git_commit () {
22 | git_changed
23 | if [ "${GIT_FILES_CHANGED}" -eq 0 ]; then
24 | echo "::debug file=common.sh,line=20,col=1 No files changed, skipping commit"
25 | else
26 | git commit -m "${INPUT_TF_DOCS_GIT_COMMIT_MESSAGE}"
27 | fi
28 | }
29 |
30 | update_doc () {
31 |
32 | WORKING_DIR="${1}"
33 | echo "::debug file=common.sh,line=30,col=1 WORKING_DIR=${WORKING_DIR}"
34 |
35 | if [ "${INPUT_TF_DOCS_CONTENT_TYPE}" = "json" ]; then
36 | MY_DOC=`terraform-docs "${INPUT_TF_DOCS_CONTENT_TYPE}" "${WORKING_DIR}" $INPUT_TF_DOCS_ARGS`
37 |
38 | if [ -f "${INPUT_TF_DOCS_TEMPLATE_FILE}" ]; then
39 | echo "${MY_DOC}" > "/tmp/config.json"
40 | MY_DOC=`gomplate -d "config=/tmp/config.json" -f "${INPUT_TF_DOCS_TEMPLATE_FILE}"`
41 | fi
42 | else
43 | MY_DOC=`terraform-docs markdown "${INPUT_TF_DOCS_CONTENT_TYPE}" "${WORKING_DIR}" $TF_ARGS`
44 | fi
45 |
46 | if [ "${INPUT_TF_DOCS_OUTPUT_METHOD}" = "replace" ]; then
47 | echo "${MY_DOC}" > "${WORKING_DIR}/${INPUT_TF_DOCS_OUTPUT_FILE}"
48 | git_add_doc "${WORKING_DIR}/${INPUT_TF_DOCS_OUTPUT_FILE}"
49 |
50 |
51 | elif [ "${INPUT_TF_DOCS_OUTPUT_METHOD}" = "inject" ]; then
52 |
53 | # Create file if it doesn't exist
54 | if [ ! -f "${WORKING_DIR}/${INPUT_TF_DOCS_OUTPUT_FILE}" ]; then
55 | printf "${TF_DOCS_TEMPLATE}" > "${WORKING_DIR}/${INPUT_TF_DOCS_OUTPUT_FILE}"
56 | fi
57 |
58 | HAS_TF_DOCS=`grep -E '(BEGIN|END)_TF_DOCS' ${WORKING_DIR}/${INPUT_TF_DOCS_OUTPUT_FILE} | wc -l`
59 | echo "::debug file=common.sh,line=47,col=1 HAS_TF_DOCS=${HAS_TF_DOCS}"
60 | # Verify it has BEGIN and END markers
61 | if [ "${HAS_TF_DOCS}" -ne 2 ]; then
62 | 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"
63 | exit 2
64 | fi
65 |
66 | # Output generated markdown to temporary file with a trailing newline and then replace the block
67 | echo "${MY_DOC}" > /tmp/tf_doc.md
68 | echo "" >> /tmp/tf_doc.md
69 | sed -i -ne '// {p; r /tmp/tf_doc.md' -e ':a; n; // {p; b}; ba}; p' "${WORKING_DIR}/${INPUT_TF_DOCS_OUTPUT_FILE}"
70 | git_add_doc "${WORKING_DIR}/${INPUT_TF_DOCS_OUTPUT_FILE}"
71 | else
72 | echo "${MY_DOC}"
73 | fi
74 | }
75 |
--------------------------------------------------------------------------------
/src/docker-entrypoint.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | set -e
3 |
4 | TF_ARGS="--indent ${INPUT_TF_DOCS_INDENTION} ${INPUT_TF_DOCS_ARGS}"
5 |
6 | export TF_DOCS_TEMPLATE=`printf '# Usage\n\n\n\n'`
7 | if [ ! -z "$INPUT_TF_DOCS_TEMPLATE" ]; then
8 | TF_DOCS_TEMPLATE=$INPUT_TF_DOCS_TEMPLATE
9 | fi
10 |
11 | . /common.sh
12 |
13 | # go to github repo
14 | cd $GITHUB_WORKSPACE
15 | git_setup
16 |
17 | if [ -f "${GITHUB_WORKSPACE}/${INPUT_TF_DOCS_ATLANTIS_FILE}" ]; then
18 |
19 | # Parse an atlantis yaml file
20 | yq r "${GITHUB_WORKSPACE}/${INPUT_TF_DOCS_ATLANTIS_FILE}" 'projects[*].dir' > /tmp/atlantis_dirs.txt
21 | while read line
22 | do
23 | project_dir=`echo $line | sed 's/- //'`
24 | update_doc "${project_dir}"
25 | done < /tmp/atlantis_dirs.txt
26 |
27 | elif [ "${INPUT_TF_DOCS_FIND_DIR}" != "disabled" ]; then
28 | # Find all tf
29 | find "${INPUT_TF_DOCS_FIND_DIR}" -name '*.tf' -exec dirname {} \; | uniq > /tmp/find_dirs.txt
30 | while read project_dir
31 | do
32 | update_doc "${project_dir}"
33 | done < /tmp/find_dirs.txt
34 |
35 | else
36 | # Split WORKING_DIR by commas
37 | for project_dir in $(echo "${INPUT_TF_DOCS_WORKING_DIR}" | sed "s/,/ /g")
38 | do
39 | update_doc "${project_dir}"
40 | done
41 | fi
42 |
43 | if [ "${INPUT_TF_DOCS_GIT_PUSH}" = "true" ]; then
44 | git_commit
45 | git push
46 | else
47 | git_changed
48 | fi
49 |
50 | exit 0
51 |
--------------------------------------------------------------------------------