Up to now there was only one way to enable recursive execution and that
was with `--recursive` CLI flag. This enables the same behavior but
within config file (i.e. `.terraform-docs.yml`)
Example:
```yaml
recursive:
enabled: false
path: modules
```
Signed-off-by: Khosrow Moossavi <khos2ow@gmail.com>
Considering the file strucutre below of main module and its submodules,
now it is possible to generate documentation for them main and all its
submodules in one execution, with `--recursive` flag.
Note that generating documentation recursively is allowed only with
`--output-file` set.
Path to find submodules can be configured with `--recursive-path`
(defaults to `modules`).
Each submodule can also have their own `.terraform-docs.yml` confi file,
to override configuration from root module.
```
.
├── README.md
├── main.tf
├── modules
│ └── my-sub-module
│ ├── README.md
│ ├── main.tf
│ ├── variables.tf
│ └── versions.tf
├── outputs.tf
├── variables.tf
└── versions.tf
```
Signed-off-by: Khosrow Moossavi <khos2ow@gmail.com>
New flag, `--lockfile`, is added to control whether ignore reading
.terraform.lock.hcl file in an attempt to extract the exact version of
provider being used or not. Default is true.
If set to true, exact version of provider available in lock file at the
time of execution will be extracted. If set to false, the version in .tf
file will be used (either exact, or a constrained version: >=, ~>, ...)
Signed-off-by: Khosrow Moossavi <khos2ow@gmail.com>
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>
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>
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>
In v0.13.0 flags `--sort-by-required` and `--sort-by-type` have been
deprecated in favor of `--sort-by required` and `--sort-by type`
respectively. And they are completely being removed now (two releases
after original announcement)
Signed-off-by: Khosrow Moossavi <khos2ow@gmail.com>
As part of this normalization the following is made sure:
- leading `v` is shown in `-v, --version` and `version` command
- commit hash is shown in `-v, --version` and `version` command
- build date is removed
- version core (without pre-release) is used for constraint comparison
Signed-off-by: Khosrow Moossavi <khos2ow@gmail.com>
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>
`--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>
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>
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>
This is a small change that prints any errors that surface when
executing the cli (i.e., `cmd.Execute()`) to stderr rather than
stdout.
When redirecting streams, its useful to keep errors separated from
program output so that in the case of an error the message won't be
redirected and is still surfaced. This issue came up for me when
using this terraform-docs in a script, where I encountered an error:
$ terraform-docs markdown path/not/to/mod > outfile
zsh: exit 1 terraform-docs markdown path/not/to/mod > outfile
When I ran the above command in my script an error was generated
because the path was incorrect, however the error message wasn't
printed to my console and the outfile was filled with the error
message. The change here modifies the cli's output to instead show:
$ terraform-docs markdown path/not/to/mod > outfile
Error: Failed to read module directory: Module directory path/not/to/mod does not exist or cannot be read.
zsh: exit 1 terraform-docs markdown path/not/to/mod > outfile
and the outfile is empty.
Signed-off-by: Anthony O'Brien <anthony@bearonis.com>
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>
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>
Two new flags are added: '--default bool' and '--type bool' to
control the visibility of Default and Type columns and section
respectively in Markdown and AsciiDoc.
Signed-off-by: Khosrow Moossavi <khos2ow@gmail.com>
In v0.10.0 flags '--no-XXX' have been deprecated in favor of their
counterparts in the format of '--X=false' (e.g. --no-header and
--header=false). And they are completely being removed now (two releases
after original announcement)
Signed-off-by: Khosrow Moossavi <khos2ow@gmail.com>
BREAKING CHANGE: - Following flags have been deprecated and will be
removed in the following releases:
- Flag `--no-color` has been deprecated, use `--color=false` instead
- Flag `--no-escape` has been deprecated, use `--escape=false` instead
- Flag `--no-header` has been deprecated, use `--hide header` instead
- Flag `--no-inputs` has been deprecated, use `--hide inputs` instead
- Flag `--no-outputs` has been deprecated, use `--hide outputs` instead
- Flag `--no-providers` has been deprecated, use `--hide providers` instead
- Flag `--no-requirements` has been deprecated, use `--hide requirements` instead
- Flag `--no-required` has been deprecated, use `--required=false` instead
- Flag `--no-sensitive` has been deprecated, use `--sensitive=false` instead
- Flag `--no-sort` has been deprecated, use `--sort=false` instead
* Implement AsciiDoc renderer
* Add missing tests to maintain expected code coverage
* Keep alphabetical order
* Refactor indent function (accept char argument and make homogeneous for both MD and Adoc renderers)
* Force asciidoc syntax in every table column
* Remove extra NL before code blocks and add autowidth tables
* Move char argument after settings in indent function
* Implement new factory function for asciidoc renderer
* Update asciidoc table docs
* Return empty indentation if no indent scpecified
* Prevent adding a trailing whitespace in table rows
* Change asciidoc alias to match file extension
* Update docs
* --no-header should stop terraform-docs from reading the main.tf file
Our projects do not have that file. Even with `--no-header`, terraform-docs crashes
* Add tests for empty configs in every format
+ Add a ShowHeader attribute in Options
+ Check for that option in loadHeader
* Allow hiding the "Sensitive" column in markdown
Use case: for projects where all outputs are expected to not be sensitive, it adds noise
* Document the new --no-sensitive option
* Fixed tests, they were written on a previous branch
* Fix tests following merge with master
* Update internal/format/document.go
Co-Authored-By: Khosrow Moossavi <khos2ow@gmail.com>
Co-authored-by: Khosrow Moossavi <khos2ow@gmail.com>