Professional Documents
Culture Documents
16 contributors +4
terraform-docs
ci passing go report A+ codecov 80% license MIT
release v0.16.0
What is terraform-docs
https://github.com/terraform-docs/terraform-docs/blob/master/README.md Page 1 of 11
terraform-docs/README.md at master · terraform-docs/terraform-docs · GitHub 12/04/22, 8:24 PM
Installation
or
or Chocolatey:
Stable binaries are also available on the releases page. To install, download
the binary for your platform from "Assets" and place this into your $PATH :
# go1.17+
go install github.com/terraform-docs/terraform-docs@v0.16.0
# go1.16
https://github.com/terraform-docs/terraform-docs/blob/master/README.md Page 2 of 11
terraform-docs/README.md at master · terraform-docs/terraform-docs · GitHub 12/04/22, 8:24 PM
Usage
Using docker
terraform-docs can be run as a container by mounting a directory with .tf
files in it and run the following command:
NOTE: Docker tag latest refers to latest stable released version and
edge refers to HEAD of master at any given point in time.
https://github.com/terraform-docs/terraform-docs/blob/master/README.md Page 3 of 11
terraform-docs/README.md at master · terraform-docs/terraform-docs · GitHub 12/04/22, 8:24 PM
jobs:
docs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
ref: ${{ github.event.pull_request.head.ref }}
Read more about terraform-docs GitHub Action and its configuration and
examples.
pre-commit hook
With pre-commit, you can ensure your Terraform module documentation is
kept up-to-date each time you make a commit.
repos:
- repo: https://github.com/terraform-docs/terraform-docs
rev: "v0.16.0"
hooks:
- id: terraform-docs-go
args: ["markdown", "table", "--output-file", "README.md", "./mymodul
https://github.com/terraform-docs/terraform-docs/blob/master/README.md Page 4 of 11
terraform-docs/README.md at master · terraform-docs/terraform-docs · GitHub 12/04/22, 8:24 PM
Then run:
pre-commit install
pre-commit install-hooks
Configuration
terraform-docs can be configured with a yaml file. The default name of this
file is .terraform-docs.yml and the path order for locating it is:
version: ""
header-from: main.tf
footer-from: ""
recursive:
enabled: false
path: modules
sections:
hide: []
show: []
content: ""
output:
file: ""
mode: inject
https://github.com/terraform-docs/terraform-docs/blob/master/README.md Page 5 of 11
terraform-docs/README.md at master · terraform-docs/terraform-docs · GitHub 12/04/22, 8:24 PM
template: |-
<!-- BEGIN_TF_DOCS -->
{{ .Content }}
<!-- END_TF_DOCS -->
output-values:
enabled: false
from: ""
sort:
enabled: true
by: name
settings:
anchor: true
color: true
default: true
description: false
escape: true
hide-empty: false
html: true
indent: 2
lockfile: true
read-comments: true
required: true
sensitive: true
type: true
Content Template
{{ .Header }}
{{ .Footer }}
{{ .Inputs }}
{{ .Modules }}
https://github.com/terraform-docs/terraform-docs/blob/master/README.md Page 6 of 11
terraform-docs/README.md at master · terraform-docs/terraform-docs · GitHub 12/04/22, 8:24 PM
{{ .Outputs }}
{{ .Providers }}
{{ .Requirements }}
{{ .Resources }}
{{ include "relative/path/to/file" }}
Additionally there's also one extra special variable avaialble to the content :
{{ .Module }}
content: |-
Any arbitrary text can be placed anywhere in the content
{{ .Header }}
{{ .Providers }}
{{ .Outputs }}
{{ include "relative/path/to/file" }}
{{ .Inputs }}
https://github.com/terraform-docs/terraform-docs/blob/master/README.md Page 7 of 11
terraform-docs/README.md at master · terraform-docs/terraform-docs · GitHub 12/04/22, 8:24 PM
# Examples
```hcl
{{ include "examples/foo/main.tf" }}
```
## Resources
{{ range .Module.Resources }}
- {{ .GetMode }}.{{ .Spec }} ({{ .Position.Filename }}#{{ .Position.Line }
{{- end }}
import (
"github.com/terraform-docs/terraform-docs/format"
"github.com/terraform-docs/terraform-docs/print"
"github.com/terraform-docs/terraform-docs/terraform"
)
https://github.com/terraform-docs/terraform-docs/blob/master/README.md Page 8 of 11
terraform-docs/README.md at master · terraform-docs/terraform-docs · GitHub 12/04/22, 8:24 PM
return formatter.Render(tmpl)
}
Plugin
Important notes:
if the plugin file name is different than the example above, terraform-
docs won't be able to to pick it up nor register it properly
you can only use plugin thorough .terraform-docs.yml file and it
cannot be used with CLI arguments
package main
import (
_ "embed" //nolint
"github.com/terraform-docs/terraform-docs/plugin"
"github.com/terraform-docs/terraform-docs/print"
"github.com/terraform-docs/terraform-docs/template"
"github.com/terraform-docs/terraform-docs/terraform"
)
https://github.com/terraform-docs/terraform-docs/blob/master/README.md Page 9 of 11
terraform-docs/README.md at master · terraform-docs/terraform-docs · GitHub 12/04/22, 8:24 PM
func main() {
plugin.Serve(&plugin.ServeOpts{
Name: "<NAME>",
Version: "0.1.0",
Printer: printerFunc,
})
}
//go:embed sections.tmpl
var tplCustom []byte
Documentation
Users
Read the User Guide to learn how to use terraform-docs
Read the Formats Guide to learn about different output formats of
terraform-docs
Refer to Config File Reference for all the available configuration
options
Developers
Read Contributing Guide before submitting a pull request
https://github.com/terraform-docs/terraform-docs/blob/master/README.md Page 10 of 11
terraform-docs/README.md at master · terraform-docs/terraform-docs · GitHub 12/04/22, 8:24 PM
Community
Discuss terraform-docs on Slack
License
https://github.com/terraform-docs/terraform-docs/blob/master/README.md Page 11 of 11