Files
terraform-docs/docs/user-guide/configuration/content.md
Khosrow Moossavi 465dd14cff Make terraform.Module available in content
Add one extra special variable the `content`:

- `{{ .Module }}`

As opposed to the other variables, which are generated sections based on
a selected formatter, the `{{ .Module }}` variable is just a `struct`
representing a Terraform module.

It can be used to build highly complex and highly customized content:

```yaml
content: |-
  ## Resources

  {{ range .Module.Resources }}
  - {{ .GetMode }}.{{ .Spec }} ({{ .Position.Filename }}#{{ .Position.Line }})
  {{- end }}
```

Signed-off-by: Khosrow Moossavi <khos2ow@gmail.com>
2021-10-04 20:01:44 -04:00

2.8 KiB

title, description, menu, weight, toc
title description menu weight toc
content content configuration
docs
parent
configuration
121 true

Since v0.14.0

Generated content can be customized further away with content in configuration. If the content is empty the default order of sections is used.

{{< alert type="info" >}} Compatible formatters for customized content are asciidoc and markdown. content will be ignored for other formatters. {{< /alert >}}

content is a Go template with following additional variables:

  • {{ .Header }}
  • {{ .Footer }}
  • {{ .Inputs }}
  • {{ .Modules }}
  • {{ .Outputs }}
  • {{ .Providers }}
  • {{ .Requirements }}
  • {{ .Resources }}

These variables are the generated output of individual sections in the selected formatter. For example {{ .Inputs }} is Markdown Table representation of inputs when formatter is set to markdown table.

{{< alert type="info" >}} Sections visibility (i.e. sections.show and sections.hide) takes precedence over the content. {{< /alert >}}

content also has the following function:

  • {{ include "relative/path/to/file" }}

Additionally there's also one extra special variable avaialble to the content:

  • {{ .Module }}

As opposed to the other variables mentioned above, which are generated sections based on a selected formatter, the {{ .Module }} variable is just a struct representing a Terraform module.

Options

Available options with their default values.

content: ""

Examples

Content can be customized, rearranged. It can have arbitrary text in between sections:

content: |-
  Any arbitrary text can be placed anywhere in the content

  {{ .Header }}

  and even in between sections

  {{ .Providers }}

  and they don't even need to be in the default order

  {{ .Outputs }}

  {{ .Inputs }}

Relative files can be included in the content:

content: |-
  include any relative files

  {{ include "relative/path/to/file" }}

include can be used to add example snippet code in the content:

content: |-
  # Examples

  ```hcl
  {{ include "examples/foo/main.tf" }}
  ```

In the following example, although {{ .Providers }} is defined it won't be rendered because providers is not set to be shown in sections.show:

sections:
  show:
    - header
    - inputs
    - outputs

content: |-
  {{ .Header }}

  Some more information can go here.

  {{ .Providers }}

  {{ .Inputs }}

  {{ .Outputs }}

Building highly complex and highly customized content using {{ .Module }} struct:

content: |-
  ## Resources

  {{ range .Module.Resources }}
  - {{ .GetMode }}.{{ .Spec }} ({{ .Position.Filename }}#{{ .Position.Line }})
  {{- end }}