Hi all,
I'm building Terraform from master and ran into a regression. It looks like HEREDOC strings aren't parsed correctly when the terminal is followed by a space.
Minimal test case:
resource "whatever" "whatever" {
userdata = <<EOF
test
EOF
}
(NB. the last EOF is following by a space).
Running terraform plan against this gives me:
Error loading config: Error parsing /Users/bspaans/src/workspace/terraform/test.tf: At 6:1: heredoc not terminated
This used to work because our code is littered with it (apparently).
Thanks,
Bart
For reference I built e10d7740b393452d379a885cac66d0dea56bba84, although I'm guessing this has to do with the HCL update.
Hi @bspaans, thanks for the report!
Looks like these whitespace followed heredoc terminators snuck in thanks to a bug in the old HCL parser.
I took a quick look at whether we should reproduce the original behavior, but reviewing a few other heredoc implementations, the consistent behavior I found was that the heredoc terminates only when a line contains the terminator with no trailing space.
So while I'm sorry that we caused you trouble, I think its probably better for us to preserve the current behavior than to try to emulate the old bug in the new parser.
I'm going to close this issue, but feel free to follow up if you'd like to discuss further! :+1:
Hi @phinze, thanks for your quick reply. The change on our side was easy enough so it's not a big issue. I had a quick look at the HCL source and it'd make the code a bit convoluted so I understand the decision. Thanks for looking into it.
Cheers,
Bart
It'd be nice to have a saner error message on this. Just spent half an hour pulling my hair out at what appeared to be valid heredocs (to those of us that haven't reviewed multiple heredoc implementations anyways). Removing the trailing space fixed it.
@joestump that seems like a great idea! Would you mind opening a fresh issue for that? Comments on closed issues are easy to miss and lose track of, so I worry that if we just leave this here it will be forgotten.
I just wanted to add a comment here for posterity.
Had a similar issue, and ended up here. If the close of your heredoc is the last line in your file it will throw this error. Adding an empty line at the end of the file fixes.
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.
Most helpful comment
I just wanted to add a comment here for posterity.
Had a similar issue, and ended up here. If the close of your heredoc is the last line in your file it will throw this error. Adding an empty line at the end of the file fixes.