Commit Graph

628 Commits

Author SHA1 Message Date
Khosrow Moossavi
b0bf022e57 Merge pull request #573 from khos2ow/plugin-in-tree
Move plugin-sdk to in-tree in core repository
2021-10-05 19:10:22 -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
40f20c563e Merge pull request #572 from khos2ow/add-sprig
Add sprig functions to built-in template functions
2021-10-04 21:02:10 -04:00
Khosrow Moossavi
89648f769f Add sprig functions to built-in template functions
Signed-off-by: Khosrow Moossavi <khos2ow@gmail.com>
2021-10-04 20:58:54 -04:00
Khosrow Moossavi
30ea8d917a Merge pull request #559 from khos2ow/content-module
Make terraform.Module available in content
2021-10-04 20:07:59 -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
de684ce48c Add public ReadConfig function
If terraform-docs is being used as a library, `print.ReadConfig()` can
be used to dynamically read and load .terraform-docs.yml config file.

Example:

```go
config, err := print.ReadConfig(".", ".terraform-docs.yml")
if err != nil {
    ...
}
```

Signed-off-by: Khosrow Moossavi <khos2ow@gmail.com>
2021-10-04 15:14:50 -04:00
Khosrow Moossavi
ba42be1b27 Merge pull request #570 from khos2ow/recursive-override
Add recursive to config and enable partial config override
2021-09-30 18:56:24 -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
c9f466f220 Merge pull request #569 from khos2ow/extra-comments
Extract leading comments for resources and modules
2021-09-29 14:11:31 -04:00
Khosrow Moossavi
f3c92384a1 Extract leading comments for resources and modules
Signed-off-by: Khosrow Moossavi <khos2ow@gmail.com>
2021-09-29 13:55:50 -04:00
Khosrow Moossavi
5f00545aac Merge pull request #510 from khos2ow/public-packages
Move internal packages to public ones
2021-09-28 15:50:55 -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
Khosrow Moossavi
4f698fb177 Merge pull request #565 from poojitha-bikki/issue-552-dev
optionally process comments from tf files as description
2021-09-27 11:55:46 -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
Bryan Dady
519f25ee01 docs: fix typo in README and update configuration guide
* docs: typo in README

Adjust typo, and suggest possible readability improvement, in README.

* Fix typo in Examples

replace 2 instances of providrs with providers

Signed-off-by: Bryan Dady <bryan@subsplash.com>

* docs: 📝 Update README and user-guide/configuration.md

Incorporate suggestions from PR https://github.com/terraform-docs/terraform-docs/pull/564

Signed-off-by: Bryan Dady <bryan@subsplash.com>

* docs: 📝 Update guide/configuration.md

Incorporate suggestions from PR https://github.com/terraform-docs/terraform-docs/pull/564

Signed-off-by: Bryan Dady <bryan@dady.us>
Signed-off-by: Bryan Dady <bryan@subsplash.com>
2021-09-23 15:58:18 -04:00
Khosrow Moossavi
5cd2b8f702 Merge pull request #561 from khos2ow/update-docs
Overhaul README and docs improvements
2021-09-16 14:01:03 -04:00
Khosrow Moossavi
3d2b8788d6 Overhaul README and docs improvements
Signed-off-by: Khosrow Moossavi <khos2ow@gmail.com>
2021-09-16 13:49:38 -04:00
Khosrow Moossavi
3d84cad448 Merge pull request #558 from khos2ow/restructure-docs
Restructure documentations
2021-09-13 18:10:12 -04:00
Khosrow Moossavi
f33826c5df Cleanup documentations
Signed-off-by: Khosrow Moossavi <khos2ow@gmail.com>
2021-09-13 18:07:57 -04:00
Khosrow Moossavi
0ad14a3120 Restructure how-tos docs
Signed-off-by: Khosrow Moossavi <khos2ow@gmail.com>
2021-09-13 18:07:46 -04:00
Khosrow Moossavi
1ae5fd95ca Restructure configurations docs
Signed-off-by: Khosrow Moossavi <khos2ow@gmail.com>
2021-09-13 18:07:21 -04:00
Khosrow Moossavi
628f2c6ea9 Update Netlify config and build CI
Signed-off-by: Khosrow Moossavi <khos2ow@gmail.com>
2021-09-13 17:30:02 -04:00
Khosrow Moossavi
39b55d16d9 Merge pull request #556 from u5surf/issues-555
Skip read lines from empty file
2021-09-10 13:18:11 -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>
v0.15.0
2021-08-10 18:55:29 -04:00
Khosrow Moossavi
7cf36774d6 Merge pull request #548 from khos2ow/recursive
Generate submodules documents with '--resurcive' flag
2021-08-10 18:39:48 -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
45bf4f6713 Merge pull request #545 from khos2ow/deps/docker
Bump docker images (alpine and golang)
2021-07-28 20:12:03 -04:00
Khosrow Moossavi
dfd1256ba4 Bump golang to 1.16.6-alpine
Signed-off-by: Khosrow Moossavi <khos2ow@gmail.com>
2021-07-28 20:07:26 -04:00
Khosrow Moossavi
77bc7801b1 Bump alpine to 3.14.0
Signed-off-by: Khosrow Moossavi <khos2ow@gmail.com>
2021-07-28 20:05:33 -04:00
Khosrow Moossavi
15fd18bc73 Merge pull request #544 from khos2ow/indented-code-block
Properly format indented code blocks
2021-07-28 19:56:14 -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
5a4a4aa034 Merge pull request #543 from khos2ow/upgrade-dependencies
Upgrade go dependencies
2021-07-28 15:26:50 -04:00
Khosrow Moossavi
209ed6679e Upgrade go dependencies
Signed-off-by: Khosrow Moossavi <khos2ow@gmail.com>
2021-07-28 15:17:32 -04:00
Khosrow Moossavi
11d71ee13b Merge pull request #542 from khos2ow/packer
Add support for generating Packer document
2021-07-28 15:14:15 -04:00
Khosrow Moossavi
d004771860 Add support for generating Packer document
Packer config, since 1.7.0, prefers HCL2 which effectively makes us to
reuse the same binary for generating documentation for it with terraform-docs
as well. The missing part was that terraform-config-inspect did not
recognize `pkr.hcl` and `pkr.json` as valid formats, which this fixes that.

Signed-off-by: Khosrow Moossavi <khos2ow@gmail.com>
2021-07-28 12:48:37 -04:00
Khosrow Moossavi
c76658c766 Merge pull request #540 from khos2ow/config-folder
Attempt looking up config file in .config folder
2021-07-27 12:11:25 -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
59a9f4e943 Merge pull request #539 from Damans227/master
Add new example for MacOs Install docs
2021-07-26 19:41:31 -04:00
Daman
a4f8aca1b4 Undo changes made by the editor
Signed-off-by: Damans227 <Damans227@gmail.com>
2021-07-26 19:38:52 -04:00
Damans227
af68ca2f46 Add new example for MacOs Install docs
Signed-off-by: Damans227 <Damans227@gmail.com>
2021-07-26 18:56:13 -04:00
Khosrow Moossavi
64d3cae58a Merge pull request #537 from khos2ow/output-template-line-break
Process \n as line break in --output-template flag
2021-07-23 16:55:56 -04:00