Files
terraform-docs/format/doc.go
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

58 lines
1.5 KiB
Go

/*
Copyright 2021 The terraform-docs Authors.
Licensed under the MIT license (the "License"); you may not
use this file except in compliance with the License.
You may obtain a copy of the License at the LICENSE file in
the root directory of this source tree.
*/
// Package format provides different, out of the box supported, output format types.
//
// Usage
//
// A specific format can be instantiated either with `format.New()` function or
// directly calling its function (e.g. `NewMarkdownTable`, etc)
//
// config := print.DefaultConfig()
// config.Formatter = "markdown table"
//
// formatter, err := format.New(config)
// if err != nil {
// return err
// }
//
// err := formatter.Generate(tfmodule)
// if err != nil {
// return err
// }
//
// output, err := formatter.Render"")
// if err != nil {
// return err
// }
//
// Note: if you don't intend to provide additional template for the generated
// content, or the target format doesn't provide templating (e.g. json, yaml,
// xml, or toml) you can use `Content()` function instead of `Render)`. Note
// that `Content()` returns all the sections combined with predefined order.
//
// output := formatter.Content()
//
// Supported formats are:
//
// • `NewAsciidocDocument`
// • `NewAsciidocTable`
// • `NewJSON`
// • `NewMarkdownDocument`
// • `NewMarkdownTable`
// • `NewPretty`
// • `NewTfvarsHCL`
// • `NewTfvarsJSON`
// • `NewTOML`
// • `NewXML`
// • `NewYAML`
//
package format