@@ -12,42 +12,31 @@ Sponsored by [Scalr - Terraform Automation & Collaboration Software](https://sca
12
12
13
13
A utility to generate documentation from Terraform modules in various output formats.
14
14
15
- ## Documentation
16
-
17
- - ** Users**
18
- - Read the [ User Guide] to learn how to use terraform-docs
19
- - Read the [ Formats Guide] to learn about different output formats of terraform-docs
20
- - Refer to [ Config File Reference] for all the available configuration options
21
- - ** Developers**
22
- - Read [ Contributing Guide] before submitting a pull request
23
-
24
- Visit [ our website] for all documentation.
25
-
26
15
## Installation
27
16
28
- The latest version can be installed using ` go get ` :
17
+ macOS users can install using [ Homebrew ] :
29
18
30
19
``` bash
31
- GO111MODULE= " on " go get github.com/ terraform-docs/terraform-docs@v0.15.0
20
+ brew install terraform-docs
32
21
```
33
22
34
- ** NOTE:** to download any version ** before** ` v0.9.1 ` (inclusive) you need to use to
35
- old module namespace (` segmentio ` ):
23
+ or
36
24
37
25
``` bash
38
- # only for v0.9.1 and before
39
- GO111MODULE=" on" go get github.com/segmentio/terraform-docs@v0.9.1
26
+ brew install terraform-docs/tap/terraform-docs
40
27
```
41
28
42
- ** NOTE: ** please use the latest Go to do this, minimum ` go1.16 ` or greater.
29
+ Windows users can install using [ Scoop ] :
43
30
44
- This will put ` terraform-docs ` in ` $(go env GOPATH)/bin ` . If you encounter the error
45
- ` terraform-docs: command not found ` after installation then you may need to either add
46
- that directory to your ` $PATH ` as shown [ here] or do a manual installation by cloning
47
- the repo and run ` make build ` from the repository which will put ` terraform-docs ` in:
31
+ ``` bash
32
+ scoop bucket add terraform-docs https://github.com/terraform-docs/scoop-bucket
33
+ scoop install terraform-docs
34
+ ```
35
+
36
+ or [ Chocolatey] :
48
37
49
38
``` bash
50
- $( go env GOPATH ) /src/github.com/terraform-docs/terraform-docs/bin/ $( uname | tr ' [:upper:] ' ' [:lower:] ' ) -amd64/ terraform-docs
39
+ choco install terraform-docs
51
40
```
52
41
53
42
Stable binaries are also available on the [ releases] page. To install, download the
@@ -57,45 +46,246 @@ binary for your platform from "Assets" and place this into your `$PATH`:
57
46
curl -Lo ./terraform-docs.tar.gz https://github.com/terraform-docs/terraform-docs/releases/download/v0.15.0/terraform-docs-v0.15.0-$( uname) -amd64.tar.gz
58
47
tar -xzf terraform-docs.tar.gz
59
48
chmod +x terraform-docs
60
- mv terraform-docs /some-dir-in-your-PATH /terraform-docs
49
+ mv terraform-docs /usr/local /terraform-docs
61
50
```
62
51
63
52
** NOTE:** Windows releases are in ` ZIP ` format.
64
53
65
- If you are a Mac OS X user, you can use [ Homebrew ] :
54
+ The latest version can be installed using ` go install ` or ` go get ` :
66
55
67
56
``` bash
68
- brew install terraform-docs
57
+ # go1.17+
58
+ go install github.com/terraform-docs/terraform-docs@v0.15.0
69
59
```
70
60
71
- or
61
+ ``` bash
62
+ # go1.16
63
+ GO111MODULE=" on" go get github.com/terraform-docs/terraform-docs@v0.15.0
64
+ ```
65
+
66
+ ** NOTE:** please use the latest Go to do this, minimum ` go1.16 ` is required.
67
+
68
+ This will put ` terraform-docs ` in ` $(go env GOPATH)/bin ` . If you encounter the error
69
+ ` terraform-docs: command not found ` after installation then you may need to either add
70
+ that directory to your ` $PATH ` as shown [ here] or do a manual installation by cloning
71
+ the repo and run ` make build ` from the repository which will put ` terraform-docs ` in:
72
72
73
73
``` bash
74
- brew install terraform-docs/tap /terraform-docs
74
+ $( go env GOPATH ) /src/github.com/ terraform-docs/terraform-docs/bin/ $( uname | tr ' [:upper:] ' ' [:lower:] ' ) -amd64 /terraform-docs
75
75
```
76
76
77
- Windows users can install using [ Scoop] :
77
+ ## Usage
78
+
79
+ ### Running the binary directly
80
+
81
+ To run and generate documentation into README within a directory:
78
82
79
83
``` bash
80
- scoop bucket add terraform-docs https://github.com/terraform-docs/scoop-bucket
81
- scoop install terraform-docs
84
+ terraform-docs markdown table --output-file README.md --output-mode inject /path/to/module
82
85
```
83
86
84
- or [ Chocolatey] :
87
+ Check [ ` output ` ] configuration for more details and examples.
88
+
89
+ ### Using docker
90
+
91
+ terraform-docs can be run as a container by mounting a directory with ` .tf `
92
+ files in it and run the following command:
85
93
86
94
``` bash
87
- choco install terraform-docs
95
+ docker run --rm --volume " $( pwd ) :/terraform-docs " -u $( id -u ) quay.io/terraform-docs/terraform-docs:0.15.0 markdown / terraform-docs
88
96
```
89
97
90
- Alternatively you also can run ` terraform-docs ` as a container:
98
+ If ` output.file ` is not enabled for this module, generated output can be redirected
99
+ back to a file:
91
100
92
101
``` bash
93
- docker run quay.io/terraform-docs/terraform-docs:0.15.0
102
+ docker run --rm --volume " $( pwd ) :/terraform-docs " -u $( id -u ) quay.io/terraform-docs/terraform-docs:0.15.0 markdown /terraform-docs > doc.md
94
103
```
95
104
96
105
** NOTE:** Docker tag ` latest ` refers to _ latest_ stable released version and ` edge `
97
106
refers to HEAD of ` master ` at any given point in time.
98
107
108
+ ### Using GitHub Actions
109
+
110
+ To use terraform-docs GitHub Action, configure a YAML workflow file (e.g.
111
+ ` .github/workflows/documentation.yml ` ) with the following:
112
+
113
+ ``` yaml
114
+ name : Generate terraform docs
115
+ on :
116
+ - pull_request
117
+
118
+ jobs :
119
+ docs :
120
+ runs-on : ubuntu-latest
121
+ steps :
122
+ - uses : actions/checkout@v2
123
+ with :
124
+ ref : ${{ github.event.pull_request.head.ref }}
125
+
126
+ - name : Render terraform docs and push changes back to PR
127
+ uses : terraform-docs/gh-actions@main
128
+ with :
129
+ working-dir : .
130
+ output-file : README.md
131
+ output-method : inject
132
+ git-push : " true"
133
+ ` ` `
134
+
135
+ Read more about [terraform-docs GitHub Action] and its configuration and
136
+ examples.
137
+
138
+ ### pre-commit hook
139
+
140
+ With pre-commit, you can ensure your Terraform module documentation is kept
141
+ up-to-date each time you make a commit.
142
+
143
+ First [install pre-commit] and then create or update a ` .pre-commit-config.yaml`
144
+ in the root of your Git repo with at least the following content :
145
+
146
+ ` ` ` yaml
147
+ repos:
148
+ - repo: https://github.com/terraform-docs/terraform-docs
149
+ rev: "v0.15.0"
150
+ hooks:
151
+ - id: terraform-docs-go
152
+ args: ["markdown", "table", "--output-file", "README.md", "./mymodule/path"]
153
+ ` ` `
154
+
155
+ Then run :
156
+
157
+ ` ` ` bash
158
+ pre-commit install
159
+ pre-commit install-hooks
160
+ ` ` `
161
+
162
+ Further changes to your module's `.tf` files will cause an update to documentation
163
+ when you make a commit.
164
+
165
+ # # Configuration
166
+
167
+ terraform-docs can be configured with a yaml file. Default name of this file is
168
+ `.terraform-docs.yml` and the order for lookig for it is :
169
+
170
+ 1. root of module directory
171
+ 1. `.config/` folder at root of module directory
172
+ 1. current directory
173
+ 1. `.config/` folder at current directory
174
+ 1. `$HOME/.tfdocs.d/`
175
+
176
+ ` ` ` yaml
177
+ formatter: "" # this is required
178
+
179
+ version: ""
180
+
181
+ header-from: main.tf
182
+ footer-from: ""
183
+
184
+ sections:
185
+ hide: []
186
+ show: []
187
+
188
+ content: ""
189
+
190
+ output:
191
+ file: ""
192
+ mode: inject
193
+ template: |-
194
+ <!-- BEGIN_TF_DOCS -->
195
+ {{ .Content }}
196
+ <!-- END_TF_DOCS -->
197
+
198
+ output-values:
199
+ enabled: false
200
+ from: ""
201
+
202
+ sort:
203
+ enabled: true
204
+ by: name
205
+
206
+ settings:
207
+ anchor: true
208
+ color: true
209
+ default: true
210
+ description: false
211
+ escape: true
212
+ hide-empty: false
213
+ html: true
214
+ indent: 2
215
+ lockfile: true
216
+ required: true
217
+ sensitive: true
218
+ type: true
219
+ ` ` `
220
+
221
+ # # Content Template
222
+
223
+ Generated content can be customized further away with `content` in configuration.
224
+ If the `content` is empty the default order of sections is used.
225
+
226
+ Compatible formatters for customized content are `asciidoc` and `markdown`. `content`
227
+ will be ignored for other formatters.
228
+
229
+ `content` is a Go template with following additional variables :
230
+
231
+ - ` {{ .Header }}`
232
+ - ` {{ .Footer }}`
233
+ - ` {{ .Inputs }}`
234
+ - ` {{ .Modules }}`
235
+ - ` {{ .Outputs }}`
236
+ - ` {{ .Providers }}`
237
+ - ` {{ .Requirements }}`
238
+ - ` {{ .Resources }}`
239
+
240
+ and following functions :
241
+
242
+ - ` {{ include "relative/path/to/file" }}`
243
+
244
+ These variables are the generated output of individual sections in the selected
245
+ formatter. For example `{{ .Inputs }}` is Markdown Table representation of _inputs_
246
+ when formatter is set to `markdown table`.
247
+
248
+ Note that sections visibility (i.e. `sections.show` and `sections.hide`) takes
249
+ precedence over the `content`.
250
+
251
+ ` ` ` ` yaml
252
+ content : |-
253
+ Any arbitrary text can be placed anywhere in the content
254
+
255
+ {{ .Header }}
256
+
257
+ and even in between sections
258
+
259
+ {{ .Providers }}
260
+
261
+ and they don't even need to be in the default order
262
+
263
+ {{ .Outputs }}
264
+
265
+ include any relative files
266
+
267
+ {{ include "relative/path/to/file" }}
268
+
269
+ {{ .Inputs }}
270
+
271
+ # Examples
272
+
273
+ ```hcl
274
+ {{ include "examples/foo/main.tf" }}
275
+ ```
276
+ ` ` ` `
277
+
278
+ # # Documentation
279
+
280
+ - **Users**
281
+ - Read the [User Guide] to learn how to use terraform-docs
282
+ - Read the [Formats Guide] to learn about different output formats of terraform-docs
283
+ - Refer to [Config File Reference] for all the available configuration options
284
+ - **Developers**
285
+ - Read [Contributing Guide] before submitting a pull request
286
+
287
+ Visit [our website] for all documentation.
288
+
99
289
# # Community
100
290
101
291
- Discuss terraform-docs on [Slack]
@@ -104,14 +294,17 @@ refers to HEAD of `master` at any given point in time.
104
294
105
295
MIT License - Copyright (c) 2021 The terraform-docs Authors.
106
296
107
- [ User Guide ] : ./docs/user-guide/introduction.md
108
- [ Formats Guide ] : ./docs/reference/terraform-docs.md
109
- [ Config File Reference ] : ./docs/user-guide/configuration.md
297
+ [Chocolatey] : https://www.chocolatey.org
298
+ [Config File Reference] : https://terraform-docs.io/user-guide/configuration/
110
299
[Contributing Guide] : CONTRIBUTING.md
111
- [ our website ] : https://terraform-docs.io/
300
+ [Formats Guide ] : https://terraform-docs.io/reference/terraform-docs /
112
301
[here] : https://golang.org/doc/code.html#GOPATH
113
- [ releases ] : https://github.com/terraform-docs/terraform-docs/releases
114
302
[Homebrew] : https://brew.sh
303
+ [install pre-commit] : https://pre-commit.com/#install
304
+ [`output`] : https://terraform-docs.io/user-guide/configuration/output/
305
+ [releases] : https://github.com/terraform-docs/terraform-docs/releases
115
306
[Scoop] : https://scoop.sh/
116
- [ Chocolatey ] : https://www.chocolatey.org
117
307
[Slack] : https://slack.terraform-docs.io/
308
+ [terraform-docs GitHub Action] : https://github.com/terraform-docs/gh-actions
309
+ [our website] : https://terraform-docs.io/
310
+ [User Guide] : https://terraform-docs.io/user-guide/introduction/
0 commit comments