Commit Graph

211 Commits

Author SHA1 Message Date
Khosrow Moossavi
5cfb2f2615 Bump golangci-lint to 1.55.2 and fix issues
Signed-off-by: Khosrow Moossavi <khos2ow@gmail.com>
2023-12-19 12:51:04 -05:00
Khosrow Moossavi
b37d2dcc0f Bump version to v0.17.0-alpha
Signed-off-by: Khosrow Moossavi <khos2ow@gmail.com>
2023-12-18 21:37:21 -05:00
Yutaro Suzuki
090efce37a Run make fmt
Signed-off-by: Yutaro Suzuki <yutaro.suzuki@cloudys.dev>
2023-06-30 04:33:06 +09:00
Khosrow Moossavi
f09375367d Bump golangci-lint to 1.47.2 and fix issues
Signed-off-by: Khosrow Moossavi <khos2ow@gmail.com>
2022-07-26 18:47:40 -04:00
Khosrow Moossavi
a74d0f4c49 Bump version to v1.0.0-alpha 2021-11-11 15:17:58 -05:00
Khosrow Moossavi
1f686b1bb3 Release version v0.16.0
Signed-off-by: Khosrow Moossavi <khos2ow@gmail.com>
2021-10-05 19:16:17 -04:00
Khosrow Moossavi
4a9ffe7c33 Move plugin-sdk to in-tree in core repository
Moving terraform-docs/plugin-sdk standalone module to in-tree, because
maintaining both of them, specifically if anything needs to be added to
Config, or terraform will required dual effort on both repository. As
such now everything is consolidated under one repository. Example usage
for plugin developer after this move is as follow:

```go
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"
)

func main() {
	plugin.Serve(&plugin.ServeOpts{
		Name:    "template",
		Version: "0.1.0",
		Printer: printer,
	})
}

//go:embed sections.tmpl
var tplCustom []byte

// Print the custom format template. You have all the flexibility to generate
// the output however you choose to.
func printer(config *print.Config, module *terraform.Module) (string, error) {
	tpl := template.New(config,
		&template.Item{Name: "custom", Text: string(tplCustom)},
	)

	rendered, err := tpl.Render("custom", module)
	if err != nil {
		return "", err
	}

	return rendered, nil
}
```

Signed-off-by: Khosrow Moossavi <khos2ow@gmail.com>
2021-10-05 18:54:49 -04:00
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
Khosrow Moossavi
6f97f6767e Add abitlity to partially override config from submodules
In the original implementation, when a submodule provided its
configuration it would completely override any config was provided by
its parent module. However with this approach the child module's
configuration will merge into its parent config and override any item
defined by both.

Example:

```
$ cat .terraform-docs.yml
formatter: markdown table
recursive:
  enabled: true
sections:
  show:
    - header
    - inputs
    - outputs
output:
  file: README.md
  mode: inject
settings:
  default: true
  required: true
  type: true

$ cat modules/module-b/.terraform-docs.yml
formatter: yaml
sections:
  show:
    - providers
settings:
  default: false
  escape: false
```

The computed values for module-b configuration will be:

```
formatter: yaml
recursive:
  enabled: true
sections:
  show:
    - providers
output:
  file: README.md
  mode: inject
settings:
  default: false
  escape: false
  required: true
  type: true
```

Signed-off-by: Khosrow Moossavi <khos2ow@gmail.com>
2021-09-30 18:53:13 -04:00
Khosrow Moossavi
54dc0f5a7c Add recursive config to .terraform-docs.yml file
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>
2021-09-30 15:53:22 -04:00
Khosrow Moossavi
bb109711a1 Deprecate Settings and Options in favor of Config
Signed-off-by: Khosrow Moossavi <khos2ow@gmail.com>
2021-09-28 15:47:27 -04:00
Khosrow Moossavi
d2fe2b1b29 Move print package from internal to public
Signed-off-by: Khosrow Moossavi <khos2ow@gmail.com>
2021-09-28 15:04:07 -04:00
Khosrow Moossavi
90942f73b8 Move format package from internal to public
Signed-off-by: Khosrow Moossavi <khos2ow@gmail.com>
2021-09-28 14:43:26 -04:00
Khosrow Moossavi
ca8f8333d4 Move template package from internal to public
Signed-off-by: Khosrow Moossavi <khos2ow@gmail.com>
2021-09-28 14:18:05 -04:00
Khosrow Moossavi
b3ff51475c Move template package from internal to public
Signed-off-by: Khosrow Moossavi <khos2ow@gmail.com>
2021-09-28 14:03:19 -04:00
Poojitha Bikki
045707beee feat: Add new flag 'read-comments' to optionally process comments as description
fixes issue #552

- process description from comments

Signed-off-by: Poojitha Bikki <50849668+poojitha-bikki@users.noreply.github.com>

- fix module tests

Signed-off-by: Poojitha Bikki <50849668+poojitha-bikki@users.noreply.github.com>

- optionally read comments for output vars description

Signed-off-by: Poojitha Bikki <50849668+poojitha-bikki@users.noreply.github.com>

- set default to true

Signed-off-by: Poojitha Bikki <50849668+poojitha-bikki@users.noreply.github.com>

- run make docs

Signed-off-by: Poojitha Bikki <50849668+poojitha-bikki@users.noreply.github.com>

- change option name

Signed-off-by: Poojitha Bikki <50849668+poojitha-bikki@users.noreply.github.com>

- add option in doc generator; make docs

Signed-off-by: Poojitha Bikki <50849668+poojitha-bikki@users.noreply.github.com>

- add config 'ReadComments'

Signed-off-by: Poojitha Bikki <50849668+poojitha-bikki@users.noreply.github.com>

- Fix alphabetic order for 'ReadComments' setting

Signed-off-by: Poojitha Bikki <50849668+poojitha-bikki@users.noreply.github.com>

- add read-comments in docs

Signed-off-by: Poojitha Bikki <50849668+poojitha-bikki@users.noreply.github.com>

- add test for readcomments option

Signed-off-by: Poojitha Bikki <50849668+poojitha-bikki@users.noreply.github.com>

- update 'read-comments' flag description

Co-authored-by: Khosrow Moossavi <khos2ow@gmail.com>
Signed-off-by: Poojitha Bikki <50849668+poojitha-bikki@users.noreply.github.com>
2021-09-24 18:04:39 -05:00
Khosrow Moossavi
1ae5fd95ca Restructure configurations docs
Signed-off-by: Khosrow Moossavi <khos2ow@gmail.com>
2021-09-13 18:07:21 -04:00
yugo-horie
5a1210b96c Skip read lines from empty file
Signed-off-by: yugo-horie <u5.horie@gmail.com>
2021-09-10 08:38:53 +09:00
Nassos Kat
f61375077e Add 'HideEmpy' section bool flag
* Add 'HideEmpy' section to Settings

Signed-off-by: akatsadimas <nkatsadim@gmail.com>

* Address review comments

fixed linting and docs, moved HideEmpty to Settings struct

Signed-off-by: akatsadimas <nkatsadim@gmail.com>

* Address review comment

document hideempty configuration option

Signed-off-by: akatsadimas <nkatsadim@gmail.com>

* Address review comments - improve docs

Signed-off-by: akatsadimas <nkatsadim@gmail.com>
2021-08-31 17:17:16 -04:00
Khosrow Moossavi
c901b89355 Bump version to v0.16.0-alpha
Signed-off-by: Khosrow Moossavi <khos2ow@gmail.com>
2021-08-11 16:21:44 -04:00
Khosrow Moossavi
f3b6eab8a8 Release version v0.15.0
Signed-off-by: Khosrow Moossavi <khos2ow@gmail.com>
2021-08-10 18:55:29 -04:00
Khosrow Moossavi
1450ee9a10 Generate submodules documents with '--resurcive' flag
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>
2021-08-10 18:22:40 -04:00
Khosrow Moossavi
c14edafbf0 Properly format indented code blocks
If a code block (surrounded by triple backticks) are indented, in other
words the code block is placed inside ordered or unordered list, the
closing backticks of codeblock should honor the original indentation
properly.

Signed-off-by: Khosrow Moossavi <khos2ow@gmail.com>
2021-07-28 19:48:51 -04:00
Khosrow Moossavi
f46a48b46b Attempt looking up config file in .config folder
The updated order of trying to look up for .terraform-docs.yml config
file, now, is:

1. root of module directory
2. `.config/` folder at root of module directory
3. current directory
4. `.config/` folder at current directory
5. `$HOME/.tfdocs.d/`

Signed-off-by: Khosrow Moossavi <khos2ow@gmail.com>
2021-07-26 20:22:39 -04:00
Khosrow Moossavi
490644ebd8 Increase test coverage for Config
Signed-off-by: Khosrow Moossavi <khos2ow@gmail.com>
2021-07-23 16:50:49 -04:00
Khosrow Moossavi
ab05309463 Process \n as line break in --output-template flag
When passing `--output-template` as CLI flag, `\n` is not processed as
line break rather than literal strings, which caused a misleading error
of "value of '--output-template' should contain at least 3 lines".

Signed-off-by: Khosrow Moossavi <khos2ow@gmail.com>
2021-07-23 12:21:09 -04:00
Khosrow Moossavi
5256426650 Ignore extracting versions from terraform.lock.hcl
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>
2021-07-22 19:48:39 -04:00
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
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
258f4603fb Remove deprecated '--sort-by-XXX' flags
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>
2021-06-02 13:00:38 -04:00
Khosrow Moossavi
b4ebd5b791 Bump version to v0.15.0-alpha
Signed-off-by: Khosrow Moossavi <khos2ow@gmail.com>
2021-06-01 17:34:23 -04: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
30b429dc83 Fix base template not found on Windows
Path separator of embed.FS is always a forward slash, even on Windows.

Signed-off-by: Khosrow Moossavi <khos2ow@gmail.com>
2021-06-01 16:46:10 -04:00
Khosrow Moossavi
54317f7e00 Bump version to v0.15.0-alpha
Signed-off-by: Khosrow Moossavi <khos2ow@gmail.com>
2021-05-31 14:41:53 -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
57cf3dbd1f Extract provider version from .terraform.lock.hcl
If .terraform.lock.hcl exists in module path, try to extract the exact
provider version being used as opposed to provided constraints.

Signed-off-by: Khosrow Moossavi <khos2ow@gmail.com>
2021-05-31 13:31:51 -04:00
Khosrow Moossavi
6820b4c2ce Normalize version to prevent malformed error
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>
2021-05-26 13:22:30 -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
Lokker
90ccb84e5e Add missing Resource.Mode to plugin-sdk (#493)
* add fix for #492.

Signed-off-by: Sergey Yakovlev <syakovlev@dalet.com>

* add additional comparisons to test for #492.

Signed-off-by: Sergey Yakovlev <syakovlev@dalet.com>

Co-authored-by: Sergey Yakovlev <syakovlev@dalet.com>
2021-05-03 10:22:08 -04:00
Khosrow Moossavi
4397facaff Validate license header on files on CI
Signed-off-by: Khosrow Moossavi <khos2ow@gmail.com>
2021-04-30 20:09:12 -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
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
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