Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Terraform fmt adds spaces to commented here-docs, every run returns output to STDOUT #6524

Closed
u2mejc opened this issue May 6, 2016 · 3 comments · Fixed by hashicorp/hcl#166
Assignees
Labels

Comments

@u2mejc
Copy link
Contributor

u2mejc commented May 6, 2016

Terraform Version

Terraform v0.6.15

Affected Resource(s)

Any HCL object stanza (resource, module, variable, etc...)

Terraform Configuration Files

resource "provider" "resource" {
  /*
  SPACE_SENSITIVE_CODE = <<EOF
yaml code:
   foo: ""
   bar: ""
EOF
  */
}

Debug Output

Nada, fmt doesn't appear to support TF_LOG=debug nor trace. Should this be a separate issue? Would be nice to understand how a code block was evaluated.

Panic Output

n/a

Expected Behavior

Exit 0, without output to stdout. Not add spaces, and not send anything to stdout (since the command always returns exit 0, regardless of input).

Actual Behavior

Continues to add spaces to here doc, damaging whitespace sensitive code and breaking CI by always returning output to stdout.

$cat test.tf
resource "provider" "resource" {
  /*
  SPACE_SENSITIVE_CODE = <<EOF
yaml code:
  foo: ""
  bar: ""
EOF
  */
}
$ terraform fmt test.tf && cat test.tf
resource "provider" "resource" {
  /*
    SPACE_SENSITIVE_CODE = <<EOF
  yaml code:
     foo: ""
     bar: ""
  EOF
    */
}
$ terraform fmt test.tf && cat test.tf
test.tf
resource "provider" "resource" {
  /*
      SPACE_SENSITIVE_CODE = <<EOF
    yaml code:
       foo: ""
       bar: ""
    EOF
      */
}
$ terraform fmt test.tf && cat test.tf
test.tf
resource "provider" "resource" {
  /*
        SPACE_SENSITIVE_CODE = <<EOF
      yaml code:
         foo: ""
         bar: ""
      EOF
        */
}
$ terraform fmt test.tf && cat test.tf
test.tf
resource "provider" "resource" {
  /*
          SPACE_SENSITIVE_CODE = <<EOF
        yaml code:
           foo: ""
           bar: ""
        EOF
          */
}

Steps to Reproduce

Please list the steps required to reproduce the issue, for example:

  1. $ terraform fmt test.tf
@apparentlymart
Copy link
Contributor

Hi @u2mejc! Thanks for this report.

It looks like in your example the heredoc is actually inside a multi-line comment, and so go fmt is fiddling with the comment rather than the heredoc. I expect the parser doesn't even know there's a heredoc in there, because it'd just treat the comment as a single opaque stream of characters.

Issue #6375 describes another weird thing that fmt does with comments... maybe it's just trying to be a bit too "clever" when it comes to formatting comments, and it'd be better to treat their context as fixed and not try to reformat the content at all.

However, I certainly agree that it's a bug that iterative runs of fmt produce progressively more indentation! fmt should converge on a stable state, regardless of what that fixed state is.

Just as with that other issue, the change here would likely be in the hcl library itself rather than in Terraform, but I think we can keep this ticket to track the issue from Terraform's perspective.

@u2mejc u2mejc changed the title Terraform fmt adds spaces to here-docs, every run returns output to STDOUT Terraform fmt adds spaces to commented here-docs, every run returns output to STDOUT May 6, 2016
@u2mejc
Copy link
Contributor Author

u2mejc commented May 6, 2016

Thx Martin, and you're correct, it's commented here-docs specifically. I appended the title.

Related, do you think the hcl library should have a verbose option in terraform debug? Presently, if gives no output, even in trace.

@ghost
Copy link

ghost commented Apr 20, 2020

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@ghost ghost locked and limited conversation to collaborators Apr 20, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants