Vscode-terraform: Please add support for formatting .tfvars files

Created on 29 Jun 2020  路  4Comments  路  Source: hashicorp/vscode-terraform

The old version of the Terraform extension formatted .tfvars files so why doesn't the new version? Please restore this feature.

Thanks

bug syntax

Most helpful comment

In the meantime, you can configure the file association in VS Code for all *.tfvars to Terraform. Even if syntax is not the same, the formatting works as I expect in most cases.

See Language Identifiers for more info.

All 4 comments

@radeksimko do you know if this is a limitation in the LS currently or something where the extension is just not sending it?

Correct, this is a temporary limitation on the LS side where the extension intentionally isn't sending tfvars files to it (yet), because:

  1. it doesn't know how to handle it (e.g. figure out the right context in which to provide completion)
  2. standardize and document the languageId which tfvars should be sent as

Most of the work is tracked under https://github.com/hashicorp/terraform-ls/issues/50 - i.e. I'd love to support it at some point.

I am fairly sure the old extension was interpreting tfvars the same way as tf (most other community extensions do), which is wrong because the syntax is not the same.

Before we support it on the server side though there's some work to do on client side too.

The extension should be treating tfvars differently during syntax highlighting. e.g. I don't think tfvars supports interpolation, function calls, provider/resource/data blocks etc. so these things should not be highlighted there as it gives the user false impression that it is supported. And neither does plain HCL support any of this, which seems to be still highlighted the same way too, giving the same false impression.

In the meantime, you can configure the file association in VS Code for all *.tfvars to Terraform. Even if syntax is not the same, the formatting works as I expect in most cases.

See Language Identifiers for more info.

If anyone is wondering how to write this in your settings.json - something like this:

"files.associations": {
    "*.tfvars": "terraform"
},
Was this page helpful?
0 / 5 - 0 ratings

Related issues

jacobisaliveandwell picture jacobisaliveandwell  路  3Comments

sugarraysam picture sugarraysam  路  4Comments

okgolove picture okgolove  路  4Comments

mdschweda picture mdschweda  路  3Comments

avinashkavi447 picture avinashkavi447  路  7Comments