Open socketbox opened 3 months ago
Hi @socketbox,
The fmt
command is designed to reformat valid hcl
, otherwise it cannot parse and tokenize the source to complete that task. While the required change in the source here appears mostly cosmetic to us, the parser is looking for the newline to signify the end of the block declaration and finds an unexpected character before the block is complete.
I don't think we'd ever want fmt
to use a different parser, since divergence there could lead to other bugs, but perhaps it would be possible to implement some method allowing fmt
to be more lenient in its parsing and accept and fix common mistakes. The fmt
command is also guaranteed to transform the source with no change to the structures in that source, and altering syntax in this way changes that guarantee somewhat.
My guess is that the most likely improvement here would be for a better error output to help pinpoint the mistake, rather than creating a new fmt
command to handle it.
Terraform Version
Terraform Configuration Files
Debug Output
https://gist.github.com/socketbox/f079c37e0219673706e3a8e54b4c4915
Expected Behavior
The file should be formatted, adding a line break as necessary.
Actual Behavior
terraform fmt
errors out and won't even run because of the very formatting that it should fix.Steps to Reproduce
terraform fmt
Additional Context
I've read the comments in the issue I link to (#23223) and I think that the justification given for not dealing with "vertical whitespace" isn't very sound.
References
#23223