hashicorp / vscode-terraform

HashiCorp Terraform VSCode extension
https://marketplace.visualstudio.com/items?itemName=HashiCorp.terraform
Mozilla Public License 2.0
911 stars 180 forks source link

Terraform 0.12 linting also breaks formatting? #172

Closed johnnyplaydrums closed 5 years ago

johnnyplaydrums commented 5 years ago

Hello! First off, thanks for the awesome extension 😄. I just started using terraform 0.12, and I noticed that the linter is complaining about some of the new syntax. I was just going to ignore it, but then I realized that formatting stopped working as well due to the improper syntax. In tf files using terraform 0.11 syntax, linting and formatting works fine. But on 0.12 files, the formatter doesn't format until I revert to 0.11 syntax (making the linter happy). Is it the linter that's blocking formatting? Can I disable the linter? Or what's the best way around this? Thank you!

johnnyplaydrums commented 5 years ago

This actually has nothing to do with 0.12 syntax, I'm just wondering how to get the formatter to working when the linter is complaining. If that's not possible, how can I disable the linter? Thank you

mauve commented 5 years ago

Formatting doesn't work if you have syntax errors, are you sure that you have no errors? Please post a screenshot?

johnnyplaydrums commented 5 years ago

Yes, the linter says I have errors because 0.12 syntax isn't supported right? So I was wondering if there was a way to get the formatter to continuing working while the linter is complaining. If not, can I disable the linter?

mauve commented 5 years ago

Linting is only done on-demand if you manually invoke the command terraform.lint (Terraform: Lint). Can you please post a screenshot of your problems view?

johnnyplaydrums commented 5 years ago

When I say linting, I'm referring to the red underline that happens when there is improper syntax. This appears after every keystroke and after every save. If the syntax is incorrect and the red line appears, formatting does not happen on save. In the below picture, I would expect formatting to correct the spacing of the =. Once I fix the below bracket and save, formatting aligns the =. Is there a way to get formatting to still work even with improper syntax? If not, is there a way to disable the feature that prevents formatting on save from working when there is a syntax error?

Screen Shot 2019-04-24 at 9 29 42 PM
mauve commented 5 years ago

Formatting is performed by calling 'terraform fmt', terraform only formats files it can parse without errors.

Sent from my iPhone

On 25. Apr 2019, at 03:33, John Spencer notifications@github.com wrote:

When I say linting, I'm referring to the red underline that happens when there is improper syntax. This appears after every keystroke and after every save. If the syntax is incorrect and the red line appears, formatting does not happen on save. In the below picture, I would expect formatting to correct the spacing of the =. Once I fix the below bracket and save, formatting aligns the =. Is there a way to get formatting to still work even with improper syntax? If not, is there a way to disable the feature that prevents formatting on save from working when there is a syntax error?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or mute the thread.

johnnyplaydrums commented 5 years ago

Ah duh, makes sense, sorry I didn't check that before asking. I guess my question now is, can I get this extension to work with terraform 0.12 syntax? I have 0.12 installed locally, and it's able to parse and format this correct when I call terraform fmt from the command line. But in vs code, there is a parsing error due to 0.12 syntax, and there format doesn't work. Anyway around that? In the example below, vs code won't align the = due to parsing 0.12 syntax, but when I run terraform fmt from the command line it works.

Screen Shot 2019-04-25 at 10 14 40 AM

mauve commented 5 years ago

Can you check in the output tab (under Terraform) which terraform binary is picked up by the vscode-plugin?

johnnyplaydrums commented 5 years ago

Ok thank you for the help! I followed the errors I was seeing in the console and fixed it - it didn't find the terraform executable because I installed through asdf. Putting a .tool-versions in ~/ fixed it. Now formatting is working but the 0.12 syntax is still underlined in red. Anything else I can do to fix that? The vs code console is not showing any errors.

Screen Shot 2019-04-25 at 10 39 14 AM

mauve commented 5 years ago

that is because the internal syntax parser does not support HCL2, sadly there are no plans to support it any time soon.

ggPeti commented 5 years ago

You don't have to support Terraform 0.12 - but then you should not call the plugin "Terraform". Or at least leave the issue open so other people can see that it's an ongoing thing.

dhdersch commented 5 years ago

There is an open issue for it, and it seems like some folks have started to look into it.

mauve commented 5 years ago

@ggPeti the plugin existed before Terraform 0.12 was released, feel free to contribute to the plugin if it is not to your liking

ggPeti commented 5 years ago

This has nothing to do with my liking. A plugin that doesn't support Terraform's current official language is not a Terraform plugin.

mauve commented 5 years ago

@ggPeti maybe you can ask for your money back?