Commit Graph

94 Commits

Author SHA1 Message Date
Ricardo Herrera
21eaab4fc7 add output-check option for outputs
adding option to compare outputted file with generated
terraform-doc and fail if different

Signed-off-by: Ricardo Herrera <rickhl@outlook.com>
Signed-off-by: Khosrow Moossavi <khos2ow@gmail.com>
2021-07-22 17:21:11 -04:00
Khosrow Moossavi
bb1e21acf7 Cosmetic cleanup asciidoc module table
Signed-off-by: Khosrow Moossavi <khos2ow@gmail.com>
2021-06-17 18:18:17 -04:00
Khosrow Moossavi
61cc005548 Render resources without URL correctly in Markdown and Asciidoc
Signed-off-by: Khosrow Moossavi <khos2ow@gmail.com>
2021-06-17 18:17:43 -04:00
Khosrow Moossavi
8577ee60ab Merge pull request #516 from khos2ow/remove-deprecated
Remove deprecated `--sort-by-XXX`, `--show-all`, and `--hide-all` flags
2021-06-02 13:03:29 -04:00
Khosrow Moossavi
d77324cc02 Add new '--show all' and '--hide all' sections
New psuedo section `all` is added and can be used to show or hide _all_
sections. This can be used as a replacement for, now, deprecated and
removed `--show-all` and `--hide-all` flags.

Signed-off-by: Khosrow Moossavi <khos2ow@gmail.com>
2021-06-02 13:01:25 -04:00
Khosrow Moossavi
25f03b4cf4 Remove deprecated '--show-all' and '--hide-all' flags
In v0.13.0 flags `--show-all` and `--hide-all` have been deprecated. And
they are completely being removed now (two releases after original
announcement)

Signed-off-by: Khosrow Moossavi <khos2ow@gmail.com>
2021-06-02 13:01:13 -04:00
frugecn
567cfcce27 updating how-to doc for correct Include Examples syntax
Signed-off-by: frugecn <christopher.fruge@churchofjesuschrist.org>
2021-06-01 16:04:40 -06:00
Khosrow Moossavi
52f0ea072b Release version v0.14.1
Signed-off-by: Khosrow Moossavi <khos2ow@gmail.com>
2021-06-01 16:51:54 -04:00
Khosrow Moossavi
69823736d5 Release version v0.14.0
Signed-off-by: Khosrow Moossavi <khos2ow@gmail.com>
2021-05-31 13:37:43 -04:00
Khosrow Moossavi
2f088f2544 Add '--html bool' flag and config to Markdown
This is to control the generated HTML tags inside markdown output. If
set to false no html tags (e.g. `<br>`, `<pre>`) will be generated. And
as a workaround the multi-line codeblock will be converted to single
line with linebreak converted to `<SPACE>`.

For example:

```
{
  "bar": {
    "bar": "bar",
    "foo": "bar"
  },
  "buzz": [
    "fizz",
    "buzz"
  ],
  "fizz": []
}
```

will be converted to:

```
{ "bar": { "bar": "bar", "foo": "bar" }, "buzz": [ "fizz", "buzz" ], "fizz": [] }
```

Signed-off-by: Khosrow Moossavi <khos2ow@gmail.com>
2021-05-25 13:23:28 -04:00
Edgar R. Sandi
0284283bd1 Separate the module version from module source when using ?ref=
Signed-off-by: Edgar R. Sandi <edgar.r.sandi@gmail.com>
2021-05-18 20:51:50 -03:00
Khosrow Moossavi
ea34bce326 Include relative files into generated content
Local relative files can be included automatically in the generated
content with `{{ include "..." }} function. This can be very useful
for:

- inject arbitrary markdown files in between sections
- automatically include example usage

````yaml
content: |-
  include any relative files

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

  or examples

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

Signed-off-by: Khosrow Moossavi <khos2ow@gmail.com>
2021-05-13 12:53:25 -04:00
Khosrow Moossavi
6777364257 Customize content with individual sections output
Generated content can be customized further away with `content` in configuration.
If the `content` is empty the default orders of section is used. `content` is a
Go template with following additional variables:

- `{{ .Header }}`
- `{{ .Footer }}`
- `{{ .Inputs }}`
- `{{ .Modules }}`
- `{{ .Outputs }}`
- `{{ .Providers }}`
- `{{ .Requirements }}`
- `{{ .Resources }}`

```yaml
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 }}
```

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` and AsciiDoc Document representation
when formatter is set to `asciidoc document` and so on.

Compatible formats for customized content are:

- `asciidoc document`
- `asciidoc table`
- `markdown document`
- `markdown table`

Signed-off-by: Khosrow Moossavi <khos2ow@gmail.com>
2021-05-12 16:12:38 -04:00
Khosrow Moossavi
7327de17ca Clarify deprecated settings in the docs (#499)
Signed-off-by: Khosrow Moossavi <khos2ow@gmail.com>
2021-05-06 12:51:45 -04:00
Khosrow Moossavi
d79abf0447 Documentation cosmetic cleanup
Signed-off-by: Khosrow Moossavi <khos2ow@gmail.com>
2021-05-02 15:12:56 -04:00
Khosrow Moossavi
43546028ad Release version v0.13.0
Signed-off-by: Khosrow Moossavi <khos2ow@gmail.com>
2021-04-30 16:24:04 -04:00
Khosrow Moossavi
1415ac92a0 Add Terraform compatibility matrix documentation
Signed-off-by: Khosrow Moossavi <khos2ow@gmail.com>
2021-04-30 16:07:34 -04:00
Khosrow Moossavi
fcd314b13b Read config from relative path, absolute, or $HOME
Configuration can be loaded with `-c, --config string` which accepts
both relative and absolute paths.

    $ pwd
    /path/to/parent/folder

    $ tree
    .
    ├── module-a
    │   └── main.tf
    ├── module-b
    │   └── main.tf
    ├── ...
    └── .terraform-docs.yml

    # executing from parent
    $ terraform-docs -c .terraform-docs.yml module-a/

    # executing from child
    $ cd module-a/
    $ terraform-docs -c ../.terraform-docs.yml .

    # or an absolute path
    $ terraform-docs -c /path/to/parent/folder/.terraform-docs.yml .

The order for looking for config file is:

1. root of module directory
2. current directory
3. `$HOME/.tfdocs.d/`

if `.terraform-docs.yml` is found in any of the folders above, that will
take precedence and will override the other ones. Note that values passed
directly as CLI flags will override all of the above.

Signed-off-by: Khosrow Moossavi <khos2ow@gmail.com>
2021-04-30 13:59:44 -04:00
Khosrow Moossavi
4be22230e7 In output-mode inject do not fail if file not found
The following scenarios can happen for --output-mode inject:

- file exists, comments exist: inject output between comments
- file exists, comments not found: append output at the end of file
- file exists, but empty: save the whole output into the file
- file not found: create the target file and save the ooutput into it

Signed-off-by: Khosrow Moossavi <khos2ow@gmail.com>
2021-04-27 20:50:30 -04:00
Khosrow Moossavi
845469c45f Support outputing to file for absolute path
`--output-file` or corresponding `output.file` config can now support
absolute path as well as relative path to root of module foler. For
example all of the followings are valid:

    $ cd /path/to/module
    $ tree .
    .
    ├── docs
    │   └── README.md
    ├── ...
    └── main.tf

    # this works, relative path
    $ terraform-docs markdown table --output-file ../docs/README.md .

    # so does this, absolute path
    $ terraform-docs markdown table --output-file /path/to/module/docs/README.md .

Signed-off-by: Khosrow Moossavi <khos2ow@gmail.com>
2021-04-27 13:06:55 -04:00
Khosrow Moossavi
b4981a16a9 Add 'since version' to docs for clarity
Signed-off-by: Khosrow Moossavi <khos2ow@gmail.com>
2021-04-26 20:20:31 -04:00
Khosrow Moossavi
dabf54f29f Version constraints configuration
terraform-docs version constraints is almost identical to the syntax
used by Terraform. A version constraint is a string literal containing
one or more condition, which are separated by commas.

```yaml
version: ">= 0.13.0, < 1.0.0"
```

Each condition consists of an operator and a version number. A version
number is a series of numbers separated by dots (e.g. `0.13.0`). Note
that version number should not have leading `v` in it.

Valid operators are as follow:

- `=` (or no operator): allows for exact version number.
- `!=`: exclude an exact version number.
- `>`, `>=`, `<`, and `<=`: comparisons against a specific version.
- `~>`: only the rightmost version component to increment.

Signed-off-by: Khosrow Moossavi <khos2ow@gmail.com>
2021-04-26 19:45:34 -04:00
Khosrow Moossavi
2784920341 Update doc to indicate minimum go1.16 is needed
Signed-off-by: Khosrow Moossavi <khos2ow@gmail.com>
2021-04-22 13:24:55 -04:00
Khosrow Moossavi
01fdd012b3 Merge pull request #475 from khos2ow/show-hide
Deprecate --show-all and --hide-all flags
2021-04-20 12:06:53 -04:00
Khosrow Moossavi
8c531b6544 Deprecate --show-all and --hide-all flags
As of `v0.13.0` flags `--show-all` and `--hide-all` are deprecated in
favor of explicit use of `--show` and `--hide`. In other words when
`--show <section>` is used, only `<section>` will be shown. If you want
to show multiple sections and hide the rest you can specify multiple
`--show` flags. The same logic is also applied to `--hide`.

    # show 'inputs' and hide everything else
    $ terraform-docs --show inputs <formatter>

    # show 'inputs' and show 'outputs' and hide everything else
    $ terraform-docs --show inputs --show outputs <formatter>

    # hide 'header' and show everything else
    $ terraform-docs --hide header <formatter>

    # hide 'header' and hide 'providers' and show everything else
    $ terraform-docs --hide header --hide providers <formatter>

Note: Using `--show` or `--hide` CLI flag will completely override the
values from `.terraform-docs.yml`. Example:

    $ cat .terraform-docs.yml
    sections:
      show:
        - inputs
        - outputs

    # example 1: this will only show 'providers'
    $ terraform-docs --show providers .

    # example 2: this will hide 'inputs' and hide 'providers' and show everything else
    $ terraform-docs --hide inputs --hide providers .

Signed-off-by: Khosrow Moossavi <khos2ow@gmail.com>
2021-04-20 11:50:58 -04:00
Khosrow Moossavi
1dbebafc84 Merge pull request #470 from khos2ow/template-comment
Support inline comments variation for Markdown and AsciiDoc
2021-04-17 19:58:12 -04:00
Khosrow Moossavi
e2e7a61ad7 Add ShowDescription to Settings
Signed-off-by: Khosrow Moossavi <khos2ow@gmail.com>
2021-04-16 11:29:45 -04:00
Edgar R. Sandi
c8fc7ab4f2 add ability to show or hide data-sources
Signed-off-by: Edgar R. Sandi <edgar.r.sandi@gmail.com>
2021-04-14 17:36:55 -03:00
Khosrow Moossavi
930bfbaf30 Merge pull request #466 from mikiya771/feature/tfvars-hcl/add-description-flag
Feature/lssue461/add description flag
2021-04-14 12:57:44 -04:00
mikiya771
d914ca71e6 Add a flag for showing description with hcl formatted tfvars
Signed-off-by: mikiya771 <22876341+mikiya771@users.noreply.github.com>

add: cli flag of show description

Signed-off-by: mikiya771 <22876341+mikiya771@users.noreply.github.com>

add: test for tfvars-hcl description flag

Signed-off-by: mikiya771 <22876341+mikiya771@users.noreply.github.com>

docs: add tfvars-hcl flag

Signed-off-by: mikiya771 <22876341+mikiya771@users.noreply.github.com>

fix: inser new lines around value with description

Signed-off-by: mikiya771 <22876341+mikiya771@users.noreply.github.com>

fix: replace with -1 to replaceall for linter

Signed-off-by: mikiya771 <22876341+mikiya771@users.noreply.github.com>

fix: use simple format for linter

Signed-off-by: mikiya771 <22876341+mikiya771@users.noreply.github.com>

fix: padding format as terraform-fmt-way

Signed-off-by: mikiya771 <22876341+mikiya771@users.noreply.github.com>
2021-04-14 21:21:37 +09:00
Khosrow Moossavi
0eea133cae Support inline comments variation for Markdown and AsciiDoc
Some of the Markdown engines (e.g. Bitbucket Cloud) are not able to
process HTML comment but as a workaround they support variation of
inline comments as follow:

- `<!-- This is a comment -->`
- `[]: # (This is a comment)`
- `[]: # "This is a comment"`
- `[]: # 'This is a comment'`
- `[//]: # (This is a comment)`
- `[comment]: # (This is a comment)`

The following is also supported for AsciiDoc format:

- `// This is a comment`

Signed-off-by: Khosrow Moossavi <khos2ow@gmail.com>
2021-04-13 14:59:36 -04:00
Khosrow Moossavi
4031c661be Merge pull request #467 from khos2ow/sort-flag
Deprecate '--sort-by-XX' in favor of '--sort-by XX'
2021-04-12 18:44:01 -04:00
Khosrow Moossavi
557d53dd1e Deprecate '--sort-by-XX' in favor of '--sort-by XX'
This deprecates sort by flags in favor of their corresponding dynamic
valued ones. Affected flags are:

- `--sort-by-required`
- `--sort-by-type`

In return new `--sort-by string` is added with following values:

- `name` (default)
- `required`
- `type`

Note that the behavior of `--sort bool` was not changed and to disable
sorting altogether you can run `--sort false`.

Signed-off-by: Khosrow Moossavi <khos2ow@gmail.com>
2021-04-12 18:34:42 -04:00
Khosrow Moossavi
6b0cf547a7 Add document for 'false' value for CLI flag
Boolean flags can only take arguments via '--flag=[true|false]' or for
short names (if available) '-f=[true|false]'. You cannot use
'--flag [true|false]' nor can you use the shorthand '-f [true|false]'.

Signed-off-by: Khosrow Moossavi <khos2ow@gmail.com>
2021-04-05 14:34:24 -04:00
Khosrow Moossavi
4714dd3ef9 Release version v0.12.1
Signed-off-by: Khosrow Moossavi <khos2ow@gmail.com>
2021-03-29 13:06:13 -04:00
Khosrow Moossavi
9c738b97c1 Release version v0.12.0
Signed-off-by: Khosrow Moossavi <khos2ow@gmail.com>
2021-03-22 14:45:26 -04:00
Khosrow Moossavi
c94b43ab80 Template should be optional for output-mode 'replace'
Template is optional when writing to --output-file and --output-mode is
'replace'. This is useful in particular when user wants to directly
output to a known file format, for example json, yaml, in which
sourrounding comments will break linters or functionality of those
formats.

Signed-off-by: Khosrow Moossavi <khos2ow@gmail.com>
2021-03-22 14:25:51 -04:00
Tom Pansino
1168e12b20 Add support for pre-commit hooks
Signed-off-by: Tom Pansino <2768420+tpansino@users.noreply.github.com>

Add note on regenerating docs manually with pre-commit

Signed-off-by: Tom Pansino <2768420+tpansino@users.noreply.github.com>

Fix documentation line length

Signed-off-by: Tom Pansino <2768420+tpansino@users.noreply.github.com>

Fix pre-commit link

Signed-off-by: Tom Pansino <2768420+tpansino@users.noreply.github.com>

Add YAML three dashes

Signed-off-by: Tom Pansino <2768420+tpansino@users.noreply.github.com>

Use https protocol in pre-commit example

Signed-off-by: Tom Pansino <2768420+tpansino@users.noreply.github.com>

Add pre-commit system hook, and some comments

Signed-off-by: Tom Pansino <2768420+tpansino@users.noreply.github.com>

Sort how-to.md links

Signed-off-by: Tom Pansino <2768420+tpansino@users.noreply.github.com>

Revert "Sort how-to.md links"

This reverts commit e04fa9f4819278de53b869ebbc1a2a59fa662f6d.

Signed-off-by: Tom Pansino <2768420+tpansino@users.noreply.github.com>

Sort how-to.md links by order of first appearance

Signed-off-by: Tom Pansino <2768420+tpansino@users.noreply.github.com>

Add whitespace to .pre-commit-hooks.yaml

Signed-off-by: Tom Pansino <2768420+tpansino@users.noreply.github.com>

Fix pre-commit hooks -> config

Signed-off-by: Tom Pansino <2768420+tpansino@users.noreply.github.com>

Fix pre-commit example to use go hook

Signed-off-by: Tom Pansino <2768420+tpansino@users.noreply.github.com>
2021-03-17 18:45:38 -07:00
Khosrow Moossavi
eeee58ceda Update reference documentation
Signed-off-by: Khosrow Moossavi <khos2ow@gmail.com>
2021-03-16 09:54:45 -04:00
Khosrow Moossavi
2109520db0 Merge pull request #383 from si-c613/368-Add-Footer-Option
feat: Add support for footer docs (#368)
2021-03-15 14:56:10 -04:00
Simon Clifford
aa1e6bbf59 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>
2021-03-15 14:51:00 -04:00
Edgar R. Sandi
243fb27ca5 add mode resource or data source to generated docs
Signed-off-by: Edgar R. Sandi <edgar.r.sandi@gmail.com>
2021-03-15 12:40:31 -03:00
Khosrow Moossavi
7e489d2bbb Do not modify header lines and trailing whitespaces
This is going to preserve line-ending of extracted header text as they
are provided by users. In other words we are going to always assume the
header text is formatted in the "intended" way by users. So we're never
going to modify line-endings and won't append `<SPACE><SPACE>` at the
end of paragraph lines.

Signed-off-by: Khosrow Moossavi <khos2ow@gmail.com>
2021-03-13 13:43:03 -05:00
Khosrow Moossavi
d982399d36 Merge pull request #425 from khos2ow/output-file
Save generated content directly into a file
2021-03-09 16:42:53 -05:00
Khosrow Moossavi
a3bafd6018 Save generated content directly into a file
There are two modes for saving into file:

- inject: partially replace the target file with generated output
- replace: completely replace the target file with generated output

The output generated by formatters (markdown, asciidoc, etc) will be
inserted into a template before getting saved into the file. This
template can be customized with '--output-template' CLI flag or
corresponding item in '.terraform-docs.yml' config file. Its default
value is:

```
<!-- BEGIN_TF_DOCS -->
{{ .Content }}
<!-- END_TF_DOCS -->
```

This consists of three items, all of them are mandatory:

- begin comment
- content variable
- end comment

You may change the wording of comment as you wish, but the comment must
be present in the template.

Signed-off-by: Khosrow Moossavi <khos2ow@gmail.com>
2021-03-09 16:40:22 -05:00
Khosrow Moossavi
644ddc4477 Merge pull request #424 from andreswebs/docs
fix shellcheck warnings in git hook example
2021-03-09 14:04:27 -05:00
Edgar R. Sandi
8c05cb9b17 Add resource 'Name' to generated docs
Signed-off-by: Edgar R. Sandi <edgar.r.sandi@gmail.com>
2021-03-09 15:11:39 -03:00
andreswebs
9cdcbbe7f4 fix shellcheck warnings in git hook example
Signed-off-by: andreswebs <andreswebs@pm.me>
2021-03-08 22:30:37 -03:00
Khosrow Moossavi
ada745bbe4 Add developer-guide documentation
Signed-off-by: Khosrow Moossavi <khos2ow@gmail.com>
2021-03-04 19:33:34 -05:00
Khosrow Moossavi
780242b506 Add user-guide documentation
Signed-off-by: Khosrow Moossavi <khos2ow@gmail.com>
2021-03-04 18:17:49 -05:00