Giter VIP home page Giter VIP logo

terraform-docs's Introduction

terraform-docs

Build Status GoDoc Go Report Card Codecov Report License Latest release

terraform-docs-teaser

What is terraform-docs

A utility to generate documentation from Terraform modules in various output formats.

Installation

macOS users can install using Homebrew:

brew install terraform-docs

or

brew install terraform-docs/tap/terraform-docs

Windows users can install using Scoop:

scoop bucket add terraform-docs https://github.com/terraform-docs/scoop-bucket
scoop install terraform-docs

or Chocolatey:

choco install terraform-docs

Stable binaries are also available on the releases page. To install, download the binary for your platform from "Assets" and place this into your $PATH:

curl -Lo ./terraform-docs.tar.gz https://github.com/terraform-docs/terraform-docs/releases/download/v0.17.0/terraform-docs-v0.17.0-$(uname)-amd64.tar.gz
tar -xzf terraform-docs.tar.gz
chmod +x terraform-docs
mv terraform-docs /usr/local/bin/terraform-docs

NOTE: Windows releases are in ZIP format.

The latest version can be installed using go install or go get:

# go1.17+
go install github.com/terraform-docs/[email protected]
# go1.16
GO111MODULE="on" go get github.com/terraform-docs/[email protected]

NOTE: please use the latest Go to do this, minimum go1.16 is required.

This will put terraform-docs in $(go env GOPATH)/bin. If you encounter the error terraform-docs: command not found after installation then you may need to either add that directory to your $PATH as shown here or do a manual installation by cloning the repo and run make build from the repository which will put terraform-docs in:

$(go env GOPATH)/src/github.com/terraform-docs/terraform-docs/bin/$(uname | tr '[:upper:]' '[:lower:]')-amd64/terraform-docs

Usage

Running the binary directly

To run and generate documentation into README within a directory:

terraform-docs markdown table --output-file README.md --output-mode inject /path/to/module

Check output configuration for more details and examples.

Using docker

terraform-docs can be run as a container by mounting a directory with .tf files in it and run the following command:

docker run --rm --volume "$(pwd):/terraform-docs" -u $(id -u) quay.io/terraform-docs/terraform-docs:0.17.0 markdown /terraform-docs

If output.file is not enabled for this module, generated output can be redirected back to a file:

docker run --rm --volume "$(pwd):/terraform-docs" -u $(id -u) quay.io/terraform-docs/terraform-docs:0.17.0 markdown /terraform-docs > doc.md

NOTE: Docker tag latest refers to latest stable released version and edge refers to HEAD of master at any given point in time.

Using GitHub Actions

To use terraform-docs GitHub Action, configure a YAML workflow file (e.g. .github/workflows/documentation.yml) with the following:

name: Generate terraform docs
on:
  - pull_request

jobs:
  docs:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v3
      with:
        ref: ${{ github.event.pull_request.head.ref }}

    - name: Render terraform docs and push changes back to PR
      uses: terraform-docs/gh-actions@main
      with:
        working-dir: .
        output-file: README.md
        output-method: inject
        git-push: "true"

Read more about terraform-docs GitHub Action and its configuration and examples.

pre-commit hook

With pre-commit, you can ensure your Terraform module documentation is kept up-to-date each time you make a commit.

First install pre-commit and then create or update a .pre-commit-config.yaml in the root of your Git repo with at least the following content:

repos:
  - repo: https://github.com/terraform-docs/terraform-docs
    rev: "v0.17.0"
    hooks:
      - id: terraform-docs-go
        args: ["markdown", "table", "--output-file", "README.md", "./mymodule/path"]

Then run:

pre-commit install
pre-commit install-hooks

Further changes to your module's .tf files will cause an update to documentation when you make a commit.

Configuration

terraform-docs can be configured with a yaml file. The default name of this file is .terraform-docs.yml and the path order for locating it 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/
formatter: "" # this is required

version: ""

header-from: main.tf
footer-from: ""

recursive:
  enabled: false
  path: modules

sections:
  hide: []
  show: []

content: ""

output:
  file: ""
  mode: inject
  template: |-
    <!-- BEGIN_TF_DOCS -->
    {{ .Content }}
    <!-- END_TF_DOCS -->

output-values:
  enabled: false
  from: ""

sort:
  enabled: true
  by: name

settings:
  anchor: true
  color: true
  default: true
  description: false
  escape: true
  hide-empty: false
  html: true
  indent: 2
  lockfile: true
  read-comments: true
  required: true
  sensitive: true
  type: true

Content Template

Generated content can be customized further away with content in configuration. If the content is empty the default order of sections is used.

Compatible formatters for customized content are asciidoc and markdown. content will be ignored for other formatters.

content is a Go template with following additional variables:

  • {{ .Header }}
  • {{ .Footer }}
  • {{ .Inputs }}
  • {{ .Modules }}
  • {{ .Outputs }}
  • {{ .Providers }}
  • {{ .Requirements }}
  • {{ .Resources }}

and following functions:

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

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.

Note that sections visibility (i.e. sections.show and sections.hide) takes precedence over the content.

Additionally there's also one extra special variable avaialble to the content:

  • {{ .Module }}

As opposed to the other variables mentioned above, which are generated sections based on a selected formatter, the {{ .Module }} variable is just a struct representing a Terraform module.

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

  include any relative files

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

  {{ .Inputs }}

  # Examples

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

  ## Resources

  {{ range .Module.Resources }}
  - {{ .GetMode }}.{{ .Spec }} ({{ .Position.Filename }}#{{ .Position.Line }})
  {{- end }}

Build on top of terraform-docs

terraform-docs primary use-case is to be utilized as a standalone binary, but some parts of it is also available publicly and can be imported in your project as a library.

import (
    "github.com/terraform-docs/terraform-docs/format"
    "github.com/terraform-docs/terraform-docs/print"
    "github.com/terraform-docs/terraform-docs/terraform"
)

// buildTerraformDocs for module root `path` and provided content `tmpl`.
func buildTerraformDocs(path string, tmpl string) (string, error) {
    config := print.DefaultConfig()
    config.ModuleRoot = path // module root path (can be relative or absolute)

    module, err := terraform.LoadWithOptions(config)
    if err != nil {
        return "", err
    }

    // Generate in Markdown Table format
    formatter := format.NewMarkdownTable(config)

    if err := formatter.Generate(module); 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()`.
    // // `Content()` returns all the sections combined with predefined order.
    // return formatter.Content(), nil

    return formatter.Render(tmpl)
}

Plugin

Generated output can be heavily customized with content, but if using that is not enough for your use-case, you can write your own plugin.

In order to install a plugin the following steps are needed:

  • download the plugin and place it in ~/.tfdocs.d/plugins (or ./.tfdocs.d/plugins)
  • make sure the plugin file name is tfdocs-format-<NAME>
  • modify formatter of .terraform-docs.yml file to be <NAME>

Important notes:

  • if the plugin file name is different than the example above, terraform-docs won't be able to to pick it up nor register it properly
  • you can only use plugin thorough .terraform-docs.yml file and it cannot be used with CLI arguments

To create a new plugin create a new repository called tfdocs-format-<NAME> with following main.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:    "<NAME>",
        Version: "0.1.0",
        Printer: printerFunc,
    })
}

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

// printerFunc the function being executed by the plugin client.
func printerFunc(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
}

Please refer to tfdocs-format-template for more details. You can create a new repository from it by clicking on Use this template button.

Documentation

Visit our website for all documentation.

Community

  • Discuss terraform-docs on Slack

License

MIT License - Copyright (c) 2021 The terraform-docs Authors.

terraform-docs's People

Contributors

aaronsteers avatar adamjohnson01 avatar aurelian-shuttleworth avatar damans227 avatar dependabot-preview[bot] avatar dependabot[bot] avatar edgarsandi avatar eppo avatar fatmcgav avatar jacobwgillespie avatar jbussdieker-mulesoft avatar khos2ow avatar metmajer avatar moatra avatar pbikki avatar pujan14 avatar rdelcampog avatar rickhlx avatar ryanking avatar s-urbaniak avatar sergei-ivanov avatar simonc-613 avatar sjauld avatar tbriot avatar tf-docs-bot avatar x-guardian avatar x4e-jonas avatar xortim avatar yields avatar yutaro1985 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

terraform-docs's Issues

Output new lines in value not supported

Terraform supports using newlines in output value interpolation, e.g.:

output "instance_info" {
  description = "Instance information map, providing instance name and IP address"
  value = "${zipmap(
    openstack_compute_instance_v2.instance.*.name, 
    openstack_networking_port_v2.instance_port.*.all_fixed_ips.0
  )}"
}

However this code causes terraform-docs to fail with:

$ terraform-docs md ./outputs.tf
illegal
2017/04/06 09:13:35 At 4:44: illegal char

Putting the value on a single line correctly generates docs:

output "instance_info" {
  description = "Instance information map, providing instance name and IP address"
  value = "${zipmap(openstack_compute_instance_v2.instance.*.name, openstack_networking_port_v2.instance_port.*.all_fixed_ips.0)}"
}

Resulting docs

Outputs

Name Description
instance_info Instance information map, providing instance name and IP address

example subcommand

$ terraform-docs example ecs-cluster

module "example" {
  source = "github.com/segmentio/stack/ecs-cluster
  foo       = "baz"
  baz      = "..."
}

terraform-docs --version output (dev build) #86

Prerequisites

Put an x into the box that applies:

  • This issue describes a bug.
  • This issue describes a feature request.

For more information, see the Contributing Guidelines.

Description

This is a follow up to #86 . As it is not possible to reopen an issue.

Execution of terraform-docs --version on Linux only outputs dev if it was installed using the given go get command.

Actual Behavior

Output:

# terraform-docs --version
dev

Do you have long logs to share? Please go to https://ghostbin.com and insert the link here.

Expected Behavior

Expected output is more than just dev. E.g. a string including a build date. "Old" dev builds might be used to e.g. create bug reports without being able to refer to the installed version.

dev (build dd-mm-yyyy HH:mm)

Replication Case

Tell us which steps to take to replicate your problem.

  1. go get -v github.com/segmentio/terraform-docs
  2. terraform-docs --version

Version

You can get this information via terraform-docs --version.
dev
Whichever dev build it might be.

linux 386 executable outputs windows style newlines

I've got all those ^M style newlines at the end of all my lines when I generate a table. This didn't happen when I used it on osx, but it's happening for the linux-386 build at least.

Running in an alpine 3.6 container v0.3.0

default in input is broken with heredoc

in repo https://github.com/BWITS/tf_aws_api_gateway_method I try to export the README with terraform-docs, but it is broken with heredoc

https://github.com/BWITS/tf_aws_api_gateway_method/blob/master/variables.tf#L48-L52

variable "integration_error_template" {
+   default = <<EOF
+ #set ($errorMessageObj = $util.parseJson($input.path('$.errorMessage')) {
+   "message" : "$errorMessageObj.message"
+ }
+ EOF
}

What I get, which should be in one line.

+| integration_error_template | # Velocity template used to deliver errors to response. Assumes all responses uses the same error template. | `#set ($errorMessageObj
+  "message" : "$errorMessageObj.message"
+}
+` | no |

Seems the problem has been fixed by #13, but not sure why I still have this issue.

Add support for a YAML renderer

Prerequisites

Put an x into the box that applies:

  • This issue describes a bug.
  • This issue describes a feature request.

For more information, see the Contributing Guidelines.

Description

We would like to add support for an additional YAML renderer.

Add option to enable/disable colored output with the Pretty printer

Prerequisites

Put an x into the box that applies:

  • This issue describes a bug.
  • This issue describes a feature request.

For more information, see the Contributing Guidelines.

Description

Currently, the pretty printer in internal/pkg/pretty generates colored output on stdout by default. We would like to have the user enable colors explicitly using --with-colors (otherwise print no colors).

v0.4.0 release for windows is not recognized as executable

Prerequisites

Put an x into the box that applies:

  • This issue describes a bug.
  • This issue describes a feature request.

For more information, see the Contributing Guidelines.

Description

The windows 0.4.0 release is not recognized as an executable.

Actual Behavior

I downloaded the latest windows release and am unable to run the binary on my windows machine.

Expected Behavior

I want to be able to install terraform-docs on my windows machine.

Replication Case

Tell us which steps to take to replicate your problem.

  1. Download 0.4.0 windows release to a windows machine
  2. Execution of the download is prohibited

ux

should pretty print docs, almost like go doc.

$ tf-docs ./module # view
$ tf-docs json ./module # json
$ tf-docs md ./module # markdown

In-place update generated documents in file

Prerequisites

Put an x into the box that applies:

  • This issue describes a bug.
  • This issue describes a feature request.

For more information, see the Contributing Guidelines.

Description

One of the main use-cases of terraform-docs as a tool is to generate Terraform configuration and update README.md file. I've managed to achieve this with a heavily hacked target in Makefile using sed and awk in conjunction of this tool to in-place update the content of README.

This is to open up discussion / brainstorming around the subject to see if it makes sense to include that as a built-in functionality of this tool. Something like --update-file FILE which adds following content:

<!-- Terraform Document Begin -->
...
generated output of terraform-doc [json|markdown|md] ...
...
<!-- Terraform Document End -->

where:

  • if Begin and End tokens don't exist in FILE, generates above snippet and appends it at the end of FILE
  • if Begin and End tokens exist in FILE, replace the inner content between the tokens with newly generated document

Version

You can get this information via terraform-docs --version.

Terraform-docs version is incorrect

when installing 0.2.0 with brew or downloading the binary the version command responds with the incorrect version

jacopo@moka:~ โ‡’ brew install terraform-docs
==> Downloading https://homebrew.bintray.com/bottles/terraform-docs-0.2.0.sierra.bottle.tar.gz
Already downloaded: /Users/jacopo/Library/Caches/Homebrew/terraform-docs-0.2.0.sierra.bottle.tar.gz
==> Pouring terraform-docs-0.2.0.sierra.bottle.tar.gz
๐Ÿบ  /usr/local/Cellar/terraform-docs/0.2.0: 6 files, 2.8MB
jacopo@moka:~ โ‡’  terraform-docs --version
v0.1.0

terraform-docs --version does not provide proper output

Prerequisites

Put an x into the box that applies:

  • This issue describes a bug.
  • This issue describes a feature request.

For more information, see the Contributing Guidelines.

Description

Execution of terraform-docs --version on Linux only outputs dev.

Actual Behavior

Output:

]# terraform-docs --version
dev

Do you have long logs to share? Please go to https://ghostbin.com and insert the link here.

Expected Behavior

Expected output would be the applicable release.

v0.5.0

Replication Case

Tell us which steps to take to replicate your problem.

  1. go get -v github.com/segmentio/terraform-docs
  2. terraform-docs --version

Version

You can get this information via terraform-docs --version.
dev

feature request: structured 'examples' section

Prerequisites

  • This issue describes a bug.
  • This issue describes a feature request.

Description

When building documentation for a module (where, generally, the only HCL files are limited and in the root dir), it'd be nice to have some form of structured 'examples' section. I'm currently putting them in a comment header at the top of main.tf, which causes it to get generated into the docs, but it'd be nice if thy could come from examples/ or somewhere like that. For instance, this file structure:

  examples/hello.tf
  examples/minimal.tf

Might result in the following being added just below the header of the generated docs:

## examples
### hello
(contents of hello.tf, automagically indented for markdown)
### minimal
(contents of minimal, automagically indented for markdown)

Unify behavior of empty Default among different print types

Prerequisites

Put an x into the box that applies:

  • This issue describes a bug.
  • This issue describes a feature request.

For more information, see the Contributing Guidelines.

Description

Following up a discussion in #81 the behavior of empty Default needs to be unified between different print types. Considering:

  • json: technically can be remained as empty since empty JSON attributed is meaningful
  • markdown
    • one of the following for table
      • Default: -
      • Default: n/a
      • Default: ""
      • Default cannot be hidden because some row of the table might still have values
    • one of the following for document
      • Default: -
      • Default: n/a
      • Default: ""
      • hide Default altogether
        • Required Inputs's value can be hidden all the times
        • Optional Inputs's value can be hidden as well for consistency.

Homebrew support

Hi, thanks for useful tool. Would you please consider porting it to Homebrew systems also?

Best regards,

Add support for an XML renderer

Prerequisites

Put an x into the box that applies:

  • This issue describes a bug.
  • This issue describes a feature request.

For more information, see the Contributing Guidelines.

Description

We would like to add support for an additional XML renderer. If you are interested in making a contribution, please provide suggestions on the intended XML format here. The resulting pull request will need to contain an XML schema to support output validation.

Add support for controlling the indentation level of headers when rendering Markdown

Prerequisites

Put an x into the box that applies:

  • This issue describes a bug.
  • This issue describes a feature request.

For more information, see the Contributing Guidelines.

Description

We would like to have the possibility to use an option --indent to control the indentation level of Markdown headers produced by the Markdown renderer. Currently, headers such as Inputs and Outputs are statically prefixed with ##, which means an indentation level of 2(which should remain the default).

Why important? People make use of pre-commit hooks to automatically inject the terraform-docs generated documentation into their project's README.md. Since our document may be inserted at a lower level, have control over the indentation level of Markdown headers would create cleaner looking documents.

Not Showing Comments

Hey,
I downloaded terraform-docs for Windows and executed your example file. Unfortunatly it is not showing the comment section. This is my command and the output.

terraform-docs md moddocutest\

{
"Comment": "",
"Inputs": [
{
"Name": "amis",
"Description": "",
"Default": {
"Type": "map",
"Literal": ""
}
},
{
"Name": "security_group_ids",
"Description": "",
"Default": {
"Type": "string",
"Literal": "sg-a, sg-b"
}
},
{
"Name": "subnet_ids",
"Description": "a comma-separated list of subnet IDs",
"Default": null
}
],
"Outputs": [
{
"Name": "vpc_id",
"Description": "The VPC ID.\n"
}
]
}

Is there anything I can try/check why it isn't working? Additionally I really like the idea of the project. Thank you.

Generate Section for locals

Prerequisites

Put an x into the box that applies:

  • This issue describes a bug.
  • This issue describes a feature request.

For more information, see the Contributing Guidelines.

Description

Sometimes devs decide to use locals instead of variable (usually for module input) and it would be nice to have that locals section automatically created by terraform-docs.

Actual Behavior

Generates only Inputs and Outputs.

/**
 * This module has a variable and an output.  This text here will be output before any inputs or outputs!
 */

variable "subnet_ids" { 
  description = "a comma-separated list of subnet IDs"
} 

// The VPC ID.
output "vpc_id" { 
  value = "vpc-5c1f55fd"
} 

locals { 
  aws_region = "us-east-1"
} 

terraform-docs md main.tf

This module has a variable and an output. This text here will be output before any inputs or outputs!

Inputs

Name Description Type Default Required
subnet_ids a comma-separated list of subnet IDs string - yes

Outputs

Name Description
vpc_id The VPC ID.

Expected Behavior

Hoping to see a locals section.

This module has a variable and an output. This text here will be output before any inputs or outputs!

Inputs

Name Description Type Default Required
subnet_ids a comma-separated list of subnet IDs string - yes

Outputs

Name Description
vpc_id The VPC ID.

Locals

Name Value
aws_region us-east-1

Version

You can get this information via terraform-docs --version.

Brew Installed Version

terraform-docs --version

dev

Downloaded from Releases

./terraform-docs-v0.4.5-darwin-amd64 --version

0.4.5

Terraform 0.12 support

Prerequisites

Put an x into the box that applies:

  • This issue describes a bug.
  • This issue describes a feature request.

For more information, see the Contributing Guidelines.

Description

Terraform 0.12 allows for some new syntax. I am working with 0.12 now so I can be ready for it when it's released. It would be nice to generate documentation for it.

Actual Behavior

$ terraform-docs variables.tf
2018/12/10 07:19:36 At 3:10: Unknown token: 3:10 IDENT object
$ cat variables.tf
variable zone {
  description = "aws_route53_zone zone object in which to create records"
  type = object({
    id = string
  })
}

variable recordsets {
  description = "list of objects with name=string, type=string, ttl=number and records=list(string) fields"
  type = list(object({
    name    = string
    type    = string
    ttl     = number
    records = list(string)
  }))
}

Expected Behavior

terraform-docs can document terraform 0.12 modules.

Replication Case

Tell us which steps to take to replicate your problem.

  1. Create a terraform file with object types and/or unquoted variables.
  2. run terraform-docs on it
  3. wallow in disappointment

Version

dev
(installed via go get 2018-12-10)

"invalid syntax" error when output name is not quoted

Prerequisites

  • This issue describes a bug.
  • This issue describes a feature request.

Description

I get invalid syntax error when output name is not quoted in tf file.

> terraform-docs md .\foobar\outputs.tf
2018/09/25 18:53:54 invalid syntax

Replication Case

Create output.tf where output names are not quoted.

  • Example, no quotes around disk_size:
output disk_size {
  value  = "${var.disk_size}"
}

Version

0.4.0, windows-amd64

Notes

Affects variables too.

feature request - modules

I understand this tool is useful to generate README for terraform modules, but I'd like to use it to generate README for any terraform projects, which I found the tool missed the feature to collect the module resources.

Use your example,

  module "foo" {
     source = "github.com/foo/baz"
     subnet_ids = "${join(",", subnet.*.id)}"
   }

Can we include modules as:

## Modules

| Name | Description | Source | 
|------|-------------|:-----:|
| foo |  | github.com/foo/baz |

HCL missing

# chussenot @ macbook-air in ~/Sites [13:00:58]
$ go get github.com/segmentio/terraform-docs
# github.com/segmentio/terraform-docs
../go/src/github.com/segmentio/terraform-docs/main.go:61: undefined: hcl.ParseBytes

Unify behavior of empty Description among different print types

Prerequisites

Put an x into the box that applies:

  • This issue describes a bug.
  • This issue describes a feature request.

For more information, see the Contributing Guidelines.

Description

Following up a discussion in #81 the behavior of empty Description needs to be unified between different print types. Considering:

  • json: technically can be remained as empty since empty JSON attribute is meaningful
  • markdown: one of the following for both table and document
    • Description: -
    • Description: n/a
    • Description: ""
    • hide Description altogether

heredoc not terminated

Prerequisites

Put an x into the box that applies:

  • This issue describes a bug.
  • This issue describes a feature request.

Description

Using configuration below, I get 2019/02/07 18:48:52 At 4:2: heredoc not terminated error

locals {
  no_newline = <<EOF
foobarEOF
}

The source is hcl library:

I'm using terraform v0.11.11 and it's able to parse this configuration.

Version

0.6.0

Feature request: sort by required / optional

It would be really nice if there was a flag to sort the inputs by required vs optional vars so that these sit at the top of my markdown table.

I'm a Go n00b but I might have a hack at doing this some time.

Show extra information for outputs that are maps

Prerequisites

  • This issue describes a bug.
  • This issue describes a feature request.

Description

I frequently make use of Terraform outputs that are maps. Wrapping your outputs in maps is especially useful for 'chaining' outputs (module -> plan -> state), and makes for a setup where a change in module output (adding/removing) doesn't require one to update all implementation plans where that module is used.

For instance, I have the following output, for a Terraform module:

# Module outputs that are strings
output "outputs" {
  value = {
    env_name            = "${var.env_name}"
    aws_region          = "${var.aws_region}"
    zone_count          = "${var.zone_count}"
    vpc_id              = "${aws_vpc.default.id}"
    vpc_cidr_block      = "${aws_vpc.default.cidr_block}"
    internet_gateway_id = "${aws_internet_gateway.default.id}"
    private_route_table = "${aws_route_table.private.id}"
    data_route_table    = "${aws_route_table.data.id}"
    nat_gateway_eip     = "${aws_nat_gateway.default.public_ip}"
  }
}

As it is currently, terraform-docs will only show the name and description for an output, so:

Name Description
outputs Module outputs that are strings

It would be nice if it would show the keys as well, and possibly the type (if you use a map of lists vs a map of strings). The output could look like this:

Name Key Type Description
outputs map Module outputs that are strings
env_name string
aws_region string
zone_count string
vpc_id string
...
outputs_list map Module outputs that are lists
data_subnet_cidr_blocks list
data_subnet_ids list

feature request: include inline docs in markdown output

I have been using terraform-docs a little bit recently, and I really like it. I am not sure how to address the following desire. I would like to generate docs for my modules which have some explanation and other details before the input/output (API) info the tool currently renders.

With tf-docs as it is now, I would need to combine the output from the tool with a snippet from a doc file, into a new .md that is actually used as the final doc. That would require developer interaction each time the module is updated. I would rather be able to rely on CI tooling to "run tf-docs" to generate the module docs, and I think that would be possible if tf-docs were to support either extracting these types of snippets from the .tf files, or having a .tpl that is used as a prefix to the existing output from tf-docs. Maybe this is already possible and I Just overlooked it?

Thoughts?

Name column not generated if variable names are not 'strings'

When a variable is defined as following:

variable name {
  description = "The name of the thing"
  type        = "string"
}

The output generated is:

## Inputs

| Name | Description | Default | Required |
|------|-------------|:-----:|:-----:|
|  | The name of the thing | - | yes |

Support handling of inputs provided via CLI

Prerequisites

Put an x into the box that applies:

  • This issue describes a bug.
  • This issue describes a feature request.

For more information, see the Contributing Guidelines.

Description

We want to integrate a clean handling of arbitrary data provided to the application through the CLI.

Wrong required field when `default` is an object

Hey,

I have following variable defined

variable "amis" {
  default = {
    "us-east-1" = "ami-8f7687e2"
    "us-west-1" = "ami-bb473cdb"
    "us-west-2" = "ami-84b44de4"
    "eu-west-1" = "ami-4e6ffe3d"
    "eu-central-1" = "ami-b0cc23df"
    "ap-northeast-1" = "ami-095dbf68"
    "ap-southeast-1" = "ami-cf03d2ac"
    "ap-southeast-2" = "ami-697a540a"
  }
}

terraform-docs thinks that this variable is required.

Support here document syntax

As mentioned in the Configuration Syntax documentation, multiline strings can be formatted using here document syntax, but as of v0.0.2, variable descriptions using here document syntax are rendered as blank values.

input

variable "foo" {
  description = <<EOD
This is foo's description.
EOD

  default = "bar"

expected output

var.foo ("bar")
This is foo's description

actual output

var.foo ("bar")
-

input variable for list not showing

Noticed that if the default value of a variable is list, it doesnt show the value.

e.g

variable "instance_type" {
  description = "Instance types to be launched"
  type        = "list"
  default     =  ["c5.large"]
}

What the doc generates is below

Name Description Type Default Required
instance_type Instance types to be launched by the spot compute environment list <list> no

Thanks

output description not being generated

The description for outputs are not being generated on version 0.1.0

output "asg-blue-name" {
  description = "Name of Blue autoscaling group."
  value = "${aws_autoscaling_group.app-asg-blue.name}"
}



| Name | Description |
|------|-------------|
| asg-blue-name |  |
| asg-green-name |  |

Comment Field Blank

Prerequisites

Put an x into the box that applies:

  • This issue describes a bug.
  • This issue describes a feature request.

For more information, see the Contributing Guidelines.

Description

While trying out the example from the README.md, the Comment field is not getting populated.

"Comment": "",

Actual Behavior

./terraform-docs-v0.4.0-darwin-amd64 --version

0.4.0

cat _example

/**
 * This module has a variable and an output.  This text here will be output before any inputs or outputs!
 */

variable "subnet_ids" {
  description = "a comma-separated list of subnet IDs"
}

// The VPC ID.
output "vpc_id" {
  value = "vpc-5c1f55fd"
}

./terraform-docs-v0.4.0-darwin-amd64 json _example

{
  "Comment": "",
  "Inputs": [
    {
      "Name": "subnet_ids",
      "Description": "a comma-separated list of subnet IDs",
      "Default": null,
      "Type": "string"
    }
  ],
  "Outputs": [
    {
      "Name": "vpc_id",
      "Description": "The VPC ID."
    }
  ]
}

Expected Behavior

{
  "Comment": "This module has a variable and an output.  This text here will be output before any inputs or outputs!\n",
  "Inputs": [
    {
      "Name": "subnet_ids",
      "Description": "a comma-separated list of subnet IDs",
      "Default": ""
    }
  ],
  "Outputs": [
    {
      "Name": "vpc_id",
      "Description": "The VPC ID.\n"
    }
  ]
}

Version

./terraform-docs-v0.4.0-darwin-amd64 --version

0.4.0

module doc

Pick up the module doc from main.tf or doc.tf if it exists.

Integrate 'gofmt' and 'goimports' into Makefile

Prerequisites

Put an x into the box that applies:

  • This issue describes a bug.
  • This issue describes a feature request.

For more information, see the Contributing Guidelines.

Description

Integrating gofmt and goimports into the Makefile helps contributors code formatting and package imports automated.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.