vscode-terraform
vscode-terraform copied to clipboard
meta: Support for Terraform files other than .tf
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):
-
Variable definitions (
*.tfvars
/*.tfvars.json
) - Test files (
*.tftest
/*.tftest.json
) - https://github.com/hashicorp/terraform/pull/33454/files#diff-c0da14d97b20324424a945e29250f498d2338bf97f8b19f159d39445c877c82aR15 -
Terraform CLI configuration (
.terraformrc
/.terraform.rc
/*.tfrc
) - Templates, i.e. files processed via
templatefile
function (*.tftpl
) -
backend file configuration, i.e. file accepted in
terraform init -backend-config=HERE
(*.<BACKEND-NAME>.tfbackend
)
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 relevantLanguageID
-
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
-
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.
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
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 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 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? 🙏🏻
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