Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Trailing space on output.template start/end comments results in Error: value of '--output-template' is missing end comment #652

@ccampo133

Description

@ccampo133

Describe the bug

Specifying the output.template value as a YAML multiline block in .terraform-docs.yml string results in the error Error: value of '--output-template' is missing end comment, despite the end comment clearly existing.

See edit at the bottom for clarification. This appears to be caused by extra whitespace around these comments.

If you specify as a regular quoted string with linebreaks, it works as expected (no error).

How can we reproduce it?

Pretty simple to reproduce. Create the following files:

main.tf:

/**
 * Hello world!
 */
resource "null_resource" "foo" {}

.terraform-docs.yml:

formatter: "markdown"

output:
  file: "README.example.md"
  mode: inject
  # Using a block style string does not appear to work...
  #... however a string with linebreaks does (uncomment to test, and comment 
  # out the block template).
  #template: "<!-- BEGIN_TF_DOCS -->\n{{ .Content }}\n<!-- END_TF_DOCS -->"
  template: |-
    <!-- BEGIN_TF_DOCS -->
    {{ .Content }}
    <!-- END_TF_DOCS -->  

And you'll see the following error:

$ terraform-docs .
Error: value of '--output-template' is missing end comment

See my example repo: https://github.com/ccampo133/terraform-docs-template-comment-bug

EDIT 2022-12-13:

As identified by @ccq1994 in this comment, it appears to be caused by trailing whitespace after the <!--END_TF_DOCS --> comment. Looking further in the code at https://github.com/terraform-docs/terraform-docs/blob/master/print/config.go#L292-L293, the whitespace of these lines are intentionally trimmed anyway, however this happens after validation is performed. I opened #658 to address this.

Environment information

terraform-docs version v0.16.0 darwin/amd64
MacOS Monterey 12.6

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions