-
Notifications
You must be signed in to change notification settings - Fork 131
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support variable files (*.tfvars
)
#50
Comments
Many clients treat plain HCL, Resolving this will therefore require changes in the affected plugins, so that they send the appropriate Before requesting changes in these clients though we should define and document some standard language IDs - and ideally publish them in the LSP spec too. Examples in the wild:
Then assuming that a client sends terraform-ls/internal/filesystem/types.go Lines 8 to 12 in 906c368
and then start treating terraform-ls/langserver/handlers/complete.go Lines 39 to 49 in 906c368
|
*.tfvars
*.tfvars
*.tfvars
)
Given a map of module variables, create the corresponding body schema with the corresponding variables as attribute schemas. Related to hashicorp/terraform-ls#50.
Given a map of module variables, create the corresponding body schema with the corresponding variables as attribute schemas. Related to hashicorp/terraform-ls#50.
Given a map of module variables, create the corresponding body schema with the corresponding variables as attribute schemas. Related to hashicorp/terraform-ls#50.
So that we can use the language server for "tfvars" files. Related to #50
For any subscribers and future readers of this (closed) issue: The server will support variable files from the upcoming release. However it is still up to each individual language client to make updates to send such files to the server and do so with the correct LanguageID ( Relatedly the Terraform VS Code extension is yet to gain that functionality. |
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. |
Depends on:
type
) #490Current Version
Use-cases
Many users declare variables in a dedicated file, i.e.
*.tfvars
as per https://www.terraform.io/docs/language/values/variables.html#variable-definitions-tfvars-filesUsers would benefit from the same level of support they get for Terraform configurations (
*.tf
) for*.tfvars
files too.Completion
Assuming there is a
*.tf
file with the following declarationsthen in an empty configuration, completion would bring up names of these declared variables with their type & description, i.e.
Then further completion would be available for each variable value, depending on its type, e.g. for a more complex variable type, such as object
the internal attributes of the object would be completed
Hover
If user was to hover over a variable name, e.g.
availability_zone_names
in the above config they would be presented with a popup with details about the field - i.e. its type and descriptionSemantic Tokens
All valid (known) variable names which are declared via
variable
blocks would be reported as attribute tokens and compatible expressions would be highlighted if present, for example:i.e.
docker_ports
andinternal
would be reported as attribute, and80
as number.Diagnostics Reporting
Any duplicates or mismatch variable types would be reported as diagnostics, similar to how HCL syntax errors are reported today. For example the following config
would result in the following diagnostic being published:
Duplicate variables will be reported automatically upon saving of any file within a module for auto-loaded files, i.e.
terraform.tfvars
&*.auto.tfvars
, and duplicates will also be reported within the context of a single*.tfvars
file upon saving that file.Proposal
module.Variable{ Type cty.Type; Description string }
toterraform-schema/module
: https://github.com/hashicorp/terraform-schema/blob/main/module/meta.gohashicorp/terraform-schema
->earlydecoder
to also collect and return variables asmap[string]module.Variable
as part of*module.Meta
: https://github.com/hashicorp/terraform-schema/blob/main/earlydecoder/decoder.goVariables
field tostate.ModuleMetadata
:terraform-ls/internal/state/module.go
Lines 15 to 19 in 92a2a2c
Variables
are also persisted to state by modifyingModuleStore.UpdateMetadata()
ParseVariables
for parsingterraform.tfvars
or*.auto.tfvars
(similar toParseConfiguration
). It may also be helpful to renameParseConfiguration
toParseModuleConfiguration
.map[string]cty.Value
initially as that will be helpful for Show interpolated expression values on hover #495 but we don't really need to do persist anything at allstate.Module
- e.g. asVariableDiagnostics map[string]hcl.Diagnostics
. We could also consider separating diagnostics for the auto-loaded tfvars files from "standalone" ones as the auto-loaded diags should be always presented for any open file within a module, but standalone only when that standalone file is open.SchemaForVariables(map[string]module.Variable) *schema.BodySchema
toterraform-schema/schema
LanguageID
in all relevant RPC methods and utilizeSchemaForVariables
where needed, e.g.textDocument/didOpen
textDocument/didSave
textDocument/didChange
textDocument/completion
textDocument/hover
textDocument/semanticTokens
textDocument/documentLink
(basically to be ignored as there's typically no systematically linkable content)textDocument/formatting
the same way as it is implemented for*.tf
(viaterraform fmt
)textDocument/publishDiagnostics
The text was updated successfully, but these errors were encountered: