Skip to content

Commit aa1e6bb

Browse files
simonc-613khos2ow
authored andcommitted
Add support for footer docs
Enables a footer to be appended to the end of a generated document sourced from tf files or documents in the same way as the header Adds the `footer-from` field to the config yml Adds the `--footer-from` flag to the cli Signed-off-by: Simon Clifford <siclifford@gmail.com> Signed-off-by: Khosrow Moossavi <khos2ow@gmail.com>
1 parent 5fae473 commit aa1e6bb

File tree

140 files changed

+909
-151
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

140 files changed

+909
-151
lines changed

.editorconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ indent_size = 4
1919
[*.md]
2020
trim_trailing_whitespace = true
2121

22-
[examples/doc.{adoc,md,tf,txt}]
22+
[examples/doc.{adoc,md,tf,txt};examples/footer.md]
2323
trim_trailing_whitespace = false
2424
insert_final_newline = false
2525

cmd/root.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ func NewCommand() *cobra.Command {
7171
cmd.PersistentFlags().BoolVar(&config.Sort.By.Type, "sort-by-type", false, "sort items by type of them (default false)")
7272

7373
cmd.PersistentFlags().StringVar(&config.HeaderFrom, "header-from", "main.tf", "relative path of a file to read header from")
74+
cmd.PersistentFlags().StringVar(&config.FooterFrom, "footer-from", "", "relative path of a file to read footer from (default \"\")")
7475

7576
cmd.PersistentFlags().BoolVar(&config.OutputValues.Enabled, "output-values", false, "inject output values into outputs (default false)")
7677
cmd.PersistentFlags().StringVar(&config.OutputValues.From, "output-values-from", "", "inject output values from file into outputs (default \"\")")

docs/reference/asciidoc-document.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,9 @@ terraform-docs asciidoc document [PATH] [flags]
2828
--anchor create anchor links (default true)
2929
-c, --config string config file name (default ".terraform-docs.yml")
3030
--default show Default column or section (default true)
31+
--footer-from string relative path of a file to read footer from (default "")
3132
--header-from string relative path of a file to read header from (default "main.tf")
32-
--hide strings hide section [header, inputs, modules, outputs, providers, requirements, resources]
33+
--hide strings hide section [footer, header, inputs, modules, outputs, providers, requirements, resources]
3334
--hide-all hide all sections (default false)
3435
--indent int indention level of AsciiDoc sections [1, 2, 3, 4, 5] (default 2)
3536
--output-file string File in module directory to insert output into (default "")
@@ -39,7 +40,7 @@ terraform-docs asciidoc document [PATH] [flags]
3940
--output-values-from string inject output values from file into outputs (default "")
4041
--required show Required column or section (default true)
4142
--sensitive show Sensitive column or section (default true)
42-
--show strings show section [header, inputs, modules, outputs, providers, requirements, resources]
43+
--show strings show section [footer, header, inputs, modules, outputs, providers, requirements, resources]
4344
--show-all show all sections (default true)
4445
--sort sort items (default true)
4546
--sort-by-required sort items by name and print required ones first (default false)
@@ -52,7 +53,7 @@ terraform-docs asciidoc document [PATH] [flags]
5253
Given the [`examples`][examples] module:
5354

5455
```shell
55-
terraform-docs asciidoc document ./examples/
56+
terraform-docs asciidoc document --footer-from footer.md ./examples/
5657
```
5758

5859
generates the following output:
@@ -469,4 +470,8 @@ generates the following output:
469470

470471
Description: It's unquoted output.
471472

473+
## This is an example of a footer
474+
475+
It looks exactly like a header, but is placed at the end of the document
476+
472477
[examples]: https://github.com/terraform-docs/terraform-docs/tree/master/examples

docs/reference/asciidoc-table.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,9 @@ terraform-docs asciidoc table [PATH] [flags]
2828
--anchor create anchor links (default true)
2929
-c, --config string config file name (default ".terraform-docs.yml")
3030
--default show Default column or section (default true)
31+
--footer-from string relative path of a file to read footer from (default "")
3132
--header-from string relative path of a file to read header from (default "main.tf")
32-
--hide strings hide section [header, inputs, modules, outputs, providers, requirements, resources]
33+
--hide strings hide section [footer, header, inputs, modules, outputs, providers, requirements, resources]
3334
--hide-all hide all sections (default false)
3435
--indent int indention level of AsciiDoc sections [1, 2, 3, 4, 5] (default 2)
3536
--output-file string File in module directory to insert output into (default "")
@@ -39,7 +40,7 @@ terraform-docs asciidoc table [PATH] [flags]
3940
--output-values-from string inject output values from file into outputs (default "")
4041
--required show Required column or section (default true)
4142
--sensitive show Sensitive column or section (default true)
42-
--show strings show section [header, inputs, modules, outputs, providers, requirements, resources]
43+
--show strings show section [footer, header, inputs, modules, outputs, providers, requirements, resources]
4344
--show-all show all sections (default true)
4445
--sort sort items (default true)
4546
--sort-by-required sort items by name and print required ones first (default false)
@@ -52,7 +53,7 @@ terraform-docs asciidoc table [PATH] [flags]
5253
Given the [`examples`][examples] module:
5354

5455
```shell
55-
terraform-docs asciidoc table ./examples/
56+
terraform-docs asciidoc table --footer-from footer.md ./examples/
5657
```
5758

5859
generates the following output:
@@ -413,4 +414,8 @@ generates the following output:
413414
|[[output_unquoted]] <<output_unquoted,unquoted>> |It's unquoted output.
414415
|===
415416

417+
## This is an example of a footer
418+
419+
It looks exactly like a header, but is placed at the end of the document
420+
416421
[examples]: https://github.com/terraform-docs/terraform-docs/tree/master/examples

docs/reference/asciidoc.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,16 @@ terraform-docs asciidoc [PATH] [flags]
3232

3333
```console
3434
-c, --config string config file name (default ".terraform-docs.yml")
35+
--footer-from string relative path of a file to read footer from (default "")
3536
--header-from string relative path of a file to read header from (default "main.tf")
36-
--hide strings hide section [header, inputs, modules, outputs, providers, requirements, resources]
37+
--hide strings hide section [footer, header, inputs, modules, outputs, providers, requirements, resources]
3738
--hide-all hide all sections (default false)
3839
--output-file string File in module directory to insert output into (default "")
3940
--output-mode string Output to file method [inject, replace] (default "inject")
4041
--output-template string Output template (default "<!-- BEGIN_TF_DOCS -->\n{{ .Content }}\n<!-- END_TF_DOCS -->")
4142
--output-values inject output values into outputs (default false)
4243
--output-values-from string inject output values from file into outputs (default "")
43-
--show strings show section [header, inputs, modules, outputs, providers, requirements, resources]
44+
--show strings show section [footer, header, inputs, modules, outputs, providers, requirements, resources]
4445
--show-all show all sections (default true)
4546
--sort sort items (default true)
4647
--sort-by-required sort items by name and print required ones first (default false)

docs/reference/json.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,16 @@ terraform-docs json [PATH] [flags]
2727

2828
```console
2929
-c, --config string config file name (default ".terraform-docs.yml")
30+
--footer-from string relative path of a file to read footer from (default "")
3031
--header-from string relative path of a file to read header from (default "main.tf")
31-
--hide strings hide section [header, inputs, modules, outputs, providers, requirements, resources]
32+
--hide strings hide section [footer, header, inputs, modules, outputs, providers, requirements, resources]
3233
--hide-all hide all sections (default false)
3334
--output-file string File in module directory to insert output into (default "")
3435
--output-mode string Output to file method [inject, replace] (default "inject")
3536
--output-template string Output template (default "<!-- BEGIN_TF_DOCS -->\n{{ .Content }}\n<!-- END_TF_DOCS -->")
3637
--output-values inject output values into outputs (default false)
3738
--output-values-from string inject output values from file into outputs (default "")
38-
--show strings show section [header, inputs, modules, outputs, providers, requirements, resources]
39+
--show strings show section [footer, header, inputs, modules, outputs, providers, requirements, resources]
3940
--show-all show all sections (default true)
4041
--sort sort items (default true)
4142
--sort-by-required sort items by name and print required ones first (default false)
@@ -47,13 +48,14 @@ terraform-docs json [PATH] [flags]
4748
Given the [`examples`][examples] module:
4849

4950
```shell
50-
terraform-docs json ./examples/
51+
terraform-docs json --footer-from footer.md ./examples/
5152
```
5253

5354
generates the following output:
5455

5556
{
5657
"header": "Usage:\n\nExample of 'foo_bar' module in `foo_bar.tf`.\n\n- list item 1\n- list item 2\n\nEven inline **formatting** in _here_ is possible.\nand some [link](https://domain.com/)\n\n* list item 3\n* list item 4\n\n```hcl\nmodule \"foo_bar\" {\n source = \"github.com/foo/bar\"\n\n id = \"1234567890\"\n name = \"baz\"\n\n zones = [\"us-east-1\", \"us-west-1\"]\n\n tags = {\n Name = \"baz\"\n Created-By = \"first.last@email.com\"\n Date-Created = \"20180101\"\n }\n}\n```\n\nHere is some trailing text after code block,\nfollowed by another line of text.\n\n| Name | Description |\n|------|-----------------|\n| Foo | Foo description |\n| Bar | Bar description |",
58+
"footer": "## This is an example of a footer\n\nIt looks exactly like a header, but is placed at the end of the document",
5759
"inputs": [
5860
{
5961
"name": "bool-1",

docs/reference/markdown-document.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,9 @@ terraform-docs markdown document [PATH] [flags]
2929
-c, --config string config file name (default ".terraform-docs.yml")
3030
--default show Default column or section (default true)
3131
--escape escape special characters (default true)
32+
--footer-from string relative path of a file to read footer from (default "")
3233
--header-from string relative path of a file to read header from (default "main.tf")
33-
--hide strings hide section [header, inputs, modules, outputs, providers, requirements, resources]
34+
--hide strings hide section [footer, header, inputs, modules, outputs, providers, requirements, resources]
3435
--hide-all hide all sections (default false)
3536
--indent int indention level of Markdown sections [1, 2, 3, 4, 5] (default 2)
3637
--output-file string File in module directory to insert output into (default "")
@@ -40,7 +41,7 @@ terraform-docs markdown document [PATH] [flags]
4041
--output-values-from string inject output values from file into outputs (default "")
4142
--required show Required column or section (default true)
4243
--sensitive show Sensitive column or section (default true)
43-
--show strings show section [header, inputs, modules, outputs, providers, requirements, resources]
44+
--show strings show section [footer, header, inputs, modules, outputs, providers, requirements, resources]
4445
--show-all show all sections (default true)
4546
--sort sort items (default true)
4647
--sort-by-required sort items by name and print required ones first (default false)
@@ -53,7 +54,7 @@ terraform-docs markdown document [PATH] [flags]
5354
Given the [`examples`][examples] module:
5455

5556
```shell
56-
terraform-docs markdown document ./examples/
57+
terraform-docs markdown document --footer-from footer.md ./examples/
5758
```
5859

5960
generates the following output:
@@ -470,4 +471,8 @@ generates the following output:
470471

471472
Description: It's unquoted output.
472473

474+
## This is an example of a footer
475+
476+
It looks exactly like a header, but is placed at the end of the document
477+
473478
[examples]: https://github.com/terraform-docs/terraform-docs/tree/master/examples

docs/reference/markdown-table.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,9 @@ terraform-docs markdown table [PATH] [flags]
2929
-c, --config string config file name (default ".terraform-docs.yml")
3030
--default show Default column or section (default true)
3131
--escape escape special characters (default true)
32+
--footer-from string relative path of a file to read footer from (default "")
3233
--header-from string relative path of a file to read header from (default "main.tf")
33-
--hide strings hide section [header, inputs, modules, outputs, providers, requirements, resources]
34+
--hide strings hide section [footer, header, inputs, modules, outputs, providers, requirements, resources]
3435
--hide-all hide all sections (default false)
3536
--indent int indention level of Markdown sections [1, 2, 3, 4, 5] (default 2)
3637
--output-file string File in module directory to insert output into (default "")
@@ -40,7 +41,7 @@ terraform-docs markdown table [PATH] [flags]
4041
--output-values-from string inject output values from file into outputs (default "")
4142
--required show Required column or section (default true)
4243
--sensitive show Sensitive column or section (default true)
43-
--show strings show section [header, inputs, modules, outputs, providers, requirements, resources]
44+
--show strings show section [footer, header, inputs, modules, outputs, providers, requirements, resources]
4445
--show-all show all sections (default true)
4546
--sort sort items (default true)
4647
--sort-by-required sort items by name and print required ones first (default false)
@@ -53,7 +54,7 @@ terraform-docs markdown table [PATH] [flags]
5354
Given the [`examples`][examples] module:
5455

5556
```shell
56-
terraform-docs markdown table ./examples/
57+
terraform-docs markdown table --footer-from footer.md ./examples/
5758
```
5859

5960
generates the following output:
@@ -175,4 +176,8 @@ generates the following output:
175176
| <a name="output_output-2"></a> [output-2](#output\_output-2) | It's output number two. |
176177
| <a name="output_unquoted"></a> [unquoted](#output\_unquoted) | It's unquoted output. |
177178

179+
## This is an example of a footer
180+
181+
It looks exactly like a header, but is placed at the end of the document
182+
178183
[examples]: https://github.com/terraform-docs/terraform-docs/tree/master/examples

docs/reference/markdown.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,16 @@ terraform-docs markdown [PATH] [flags]
3333

3434
```console
3535
-c, --config string config file name (default ".terraform-docs.yml")
36+
--footer-from string relative path of a file to read footer from (default "")
3637
--header-from string relative path of a file to read header from (default "main.tf")
37-
--hide strings hide section [header, inputs, modules, outputs, providers, requirements, resources]
38+
--hide strings hide section [footer, header, inputs, modules, outputs, providers, requirements, resources]
3839
--hide-all hide all sections (default false)
3940
--output-file string File in module directory to insert output into (default "")
4041
--output-mode string Output to file method [inject, replace] (default "inject")
4142
--output-template string Output template (default "<!-- BEGIN_TF_DOCS -->\n{{ .Content }}\n<!-- END_TF_DOCS -->")
4243
--output-values inject output values into outputs (default false)
4344
--output-values-from string inject output values from file into outputs (default "")
44-
--show strings show section [header, inputs, modules, outputs, providers, requirements, resources]
45+
--show strings show section [footer, header, inputs, modules, outputs, providers, requirements, resources]
4546
--show-all show all sections (default true)
4647
--sort sort items (default true)
4748
--sort-by-required sort items by name and print required ones first (default false)

docs/reference/pretty.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,16 @@ terraform-docs pretty [PATH] [flags]
2727

2828
```console
2929
-c, --config string config file name (default ".terraform-docs.yml")
30+
--footer-from string relative path of a file to read footer from (default "")
3031
--header-from string relative path of a file to read header from (default "main.tf")
31-
--hide strings hide section [header, inputs, modules, outputs, providers, requirements, resources]
32+
--hide strings hide section [footer, header, inputs, modules, outputs, providers, requirements, resources]
3233
--hide-all hide all sections (default false)
3334
--output-file string File in module directory to insert output into (default "")
3435
--output-mode string Output to file method [inject, replace] (default "inject")
3536
--output-template string Output template (default "<!-- BEGIN_TF_DOCS -->\n{{ .Content }}\n<!-- END_TF_DOCS -->")
3637
--output-values inject output values into outputs (default false)
3738
--output-values-from string inject output values from file into outputs (default "")
38-
--show strings show section [header, inputs, modules, outputs, providers, requirements, resources]
39+
--show strings show section [footer, header, inputs, modules, outputs, providers, requirements, resources]
3940
--show-all show all sections (default true)
4041
--sort sort items (default true)
4142
--sort-by-required sort items by name and print required ones first (default false)
@@ -47,7 +48,7 @@ terraform-docs pretty [PATH] [flags]
4748
Given the [`examples`][examples] module:
4849

4950
```shell
50-
terraform-docs pretty --no-color ./examples/
51+
terraform-docs pretty --footer-from footer.md --no-color ./examples/
5152
```
5253

5354
generates the following output:
@@ -252,4 +253,8 @@ generates the following output:
252253
output.unquoted
253254
It's unquoted output.
254255

256+
## This is an example of a footer
257+
258+
It looks exactly like a header, but is placed at the end of the document
259+
255260
[examples]: https://github.com/terraform-docs/terraform-docs/tree/master/examples

0 commit comments

Comments
 (0)