-
Notifications
You must be signed in to change notification settings - Fork 9.6k
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" doesn't format correctly in presence of here-docs #21434
Comments
Can confirm this is affecting our code base after migration to 0.12.0. All files with here-docs are not formatted after the here-doc when running |
just wanted to mention that this appears to have been discussed before but the issue was closed with no resolution |
In the mean time i've just put the heredocs at the bottom of the file as locals and referenced them above, because the formatter only breaks after the terminator |
would be nice to have any option to tell |
I'm seeing a similar issue with heredoc formatting, except the formatter will indent all lines after Every subsequent heredoc will indent the text after it by another 4 spaces. This is leading to big ugly diffs after running
|
Adding additional heredocs causes the formatting to change further. Eventually it will wrap back around to the correct formatting, which I think is hilarious. It appears the pattern is:
|
Same issue here. In presence of here-docs equal signs are not aligned. This causes our CI/CD pipeline to fail when running As a workaround, putting all here-docs at the end of the file in |
Can confirm this issue is still present in 0.12.2 and that 0.11.14 works correctly. |
This still happens in 0.12.3 |
this bug has been open a for a while, hope it is not too hard to fix. I thought that with 3 patch versions it would be safe to try to upgrade, but got bit by this. after running |
@camerondavison, I was able to work around this by using locals which probably made the code more readable anyhow. Maybe that will help? |
@querry43, can you clarify how you worked around it with locals? Edit: Answered up here #21434 (comment) |
Not sure that makes sense for me. Im using terraform to provision datadog monitoring and it would be best to have the multiline message in the monitor rather than having to find the local for the message for every monitor. |
There's apparently a fix in hashicorp/hcl2#107, this would need to get merged first and then backported into Terraform. |
@luhn , it is a fairly specific case. The HEREDOC was breaking because of a ${function call} in it. Pulling that out into a local appeared to make the problem go away.
|
You must be talking about a different issue. The issue in question occurs regardless of the contents of the heredoc. (OP's example just has "5" as the contents of the heredoc.) |
Any update on this one? It's quite annoying to have to put all HEREDOCs at the bottom as locals. |
Fixed upstream: hashicorp/hcl2#107 |
I tried upgrading HCL to incorporate the ☝️ mentioned fix, but it doesn't fix the issue described here, and it looks as though some further investigation is needed. |
Damn, thanks for trying, @pselle! I feel compelled to mention, in receipt of so much ❤️ , that the mentioned fix is due to @nozaq, and I claim no credit! One other thing to note in addition to the 'locals at the bottom' workaround, this prompted me to discover I also replaced some command heredocs with |
Oh nice, I did not know about aws_iam_policy_document, that would indeed help with most of my heredocs. |
Hi, just notified of this thread! I've tried cases described here with the current master which already has my PR merged. Is there specific example working incorrectly? I'm happy to dig into it further :) Case 1 (Original Post)Input
Output
Case 2(@luhn's post)Input
Output
|
Thanks for your work, @nozaq! It does look like the indentation problems are fixed with your PR, but the equals sign alignment remains an issue. |
@luhn Thanks for the clarification! |
Waiting for TokenCHeredoc never ends since scanTokens() does not produce TokenNewlines inside heredocs. Related Issue: hashicorp/terraform#21434
The fix was merged into upstream now :) |
This is going to make a lot of folks (including me) very very happy. 🕺 I've had to write special scripts to Would you be willing to consider releasing a point release just for this instead of the regular cadence? |
@shantanugadgil We are not planning to release outside of the our flow, this will go out with the next Terraform release. |
This was released in 0.12.6: https://github.com/hashicorp/terraform/blob/master/CHANGELOG.md#0126-july-31-2019 |
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. |
Terraform Version
Terraform Configuration Files
Expected Behavior
I expect
terraform fmt
to reformat and align the code like this:Actual Behavior
Instead, the
=
signs are not aligned correctly:Steps to Reproduce
Create a Terraform file with the content above and run
terraform fmt
.Additional Context
If I remove the here-doc variable, this formats the file as expected, and like Terraform < 0.12.0 used to do.
The text was updated successfully, but these errors were encountered: