vscode-terraform icon indicating copy to clipboard operation
vscode-terraform copied to clipboard

meta: Support for Terraform files other than .tf

Open danieldreier opened this issue 3 years ago • 6 comments

Depends on https://github.com/hashicorp/vscode-terraform/issues/638


Problem Statement

Terraform supports a number of different files for different purposes (aside from *.tf for infrastructure configuration):

The VS Code extension currently does not provide any support for the above files.

User Impact

Any users which use any of the above files would benefit from support.

It is likely that *.tfvars would have the highest impact of all - i.e. used by more users than the other files, but there is currently no data to back it up. It would make sense to just support all of the above formats.

Expected User Experience

Users will be provided with the same experience as for *.tf files today.

  • syntax highlighting
  • completion (for block types, labels, attribute names, value types etc.)
  • hover (for all of the above)
  • relevant diagnostics for invalid configs

Proposal

  • VS Code extension claims all of the above formats as supported and highlights them as HCL (per https://github.com/hashicorp/vscode-terraform/issues/638)
  • VS Code extension sends all of the above files to terraform-ls, each with relevant LanguageID
  • terraform-ls provides support for the relevant LanguageIDs:
    • *.tfvars: https://github.com/hashicorp/terraform-ls/issues/50
    • *.tfvars.json: https://github.com/hashicorp/terraform-ls/issues/519
    • .terraformrc / .terraform.rc / *.tfrc: https://github.com/hashicorp/terraform-ls/issues/497
    • *.tftpl: https://github.com/hashicorp/terraform-ls/issues/521
    • *.<backend-name>.tfbackend: https://github.com/hashicorp/terraform-ls/issues/518

danieldreier avatar May 18 '21 16:05 danieldreier

Any updates... seems like quite an easy win and import to have. Looking at my *.tftpl JSON file in black and white isn't very nice.

gruckion avatar Nov 09 '22 12:11 gruckion

It seems the extension is not supporting .tf.json files as well even though the language server seems to do so https://github.com/hashicorp/terraform-ls/issues/498

freeman avatar Jun 29 '23 12:06 freeman

I think there may be differences in opinions on what "support" really means.

As you pointed out, the language server does parse JSON files to provide to provide e.g. completion of references to configuration inside those JSON files. It does not however provide any code intelligence (completion, hover etc.) inside those JSON files.

As it turns out this level of support is not ideal - @dbanck points out some downsides in https://github.com/hashicorp/terraform-ls/issues/705 - so it's clear we'll have to make some changes in this area. That said I am still not sure that providing completion/hover etc. inside JSON files is what we really should be offering as the JSON format is primarily for machines to read, not humans, so I wouldn't expect humans to be hand-editing JSON files.

TL;DR @freeman Can you clarify what "not supporting" means to you?

radeksimko avatar Jul 04 '23 09:07 radeksimko

@radeksimko In my project I have .tf.json files containing data sources (not .tfvars.json) and I get no completion from the language server in VS Code when inside the .tf files.

I do not expect language server support in the JSON files (as in fact they are generated by scripts).

freeman avatar Jul 05 '23 15:07 freeman

@freeman That sounds like a bug - we should already support such a scenario, would you mind creating a separate bug report and attaching some more details, ideally with pieces of configuration, so we can reproduce and look into it, and hopefully get it fixed? 🙏🏻

radeksimko avatar Jul 05 '23 20:07 radeksimko

The current docs imply that using .tfbackend will "likely provide better editing experience". It would be great to be able to update the docs to remove the word 'likely' 😄

https://developer.hashicorp.com/terraform/language/settings/backends/configuration#file

flcdrg avatar Mar 19 '24 03:03 flcdrg