Skip to content
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

Provide diagnostics and quick fixes for invalid configuration #720

Open
radeksimko opened this issue Aug 6, 2021 · 2 comments
Open

Provide diagnostics and quick fixes for invalid configuration #720

radeksimko opened this issue Aug 6, 2021 · 2 comments
Assignees
Labels

Comments

@radeksimko
Copy link
Member

radeksimko commented Aug 6, 2021

Problem Statement

User today already receives diagnostics for invalid HCL syntax, such as missing curly braces, double quotes etc.
User can also trigger the terraform validate command which displays any validation warnings and errors in the form of diagnostics.

terraform validate is usually an expensive operation providing rich validation as defined by provider developers, therefore unsuitable to run as the user types.

User would benefit from a lighter and "cheaper" validation based on provider schema that strikes the balance between the two.

User would also benefit from being able to "quick fix" violations semi-automatically via contextual code actions.

Expected User Experience

Users will be presented with diagnostics the same way that validate or HCL diagnostics are presented:

Screenshot 2021-08-06 at 12 16 31

but these diagnostics will be based on the violation of the (static) schema, for example

  • (unknown) references referring to targets that do not exist - e.g. var.example for no corresponding variable "example" block
  • literals of incorrect types - e.g. number_field = "string"
  • missing required attribute
  • missing required blocks (with set minimum instances of block)
  • too many blocks (with set maximum instances of block)
  • duplicate attributes
  • extraneous block labels - e.g. variable "one" "two" {
  • missing block labels - e.g. variable {}
  • deprecated attributes/blocks

and based on knowledge of mistakes users have made in the past which Terraform CLI already returns, for example

  • required_providers in root instead of enclosed within terraform block
  • likely typos detected via levenshtein distance (e.g. requred_providers)

All such diagnostics will be presented immediately as the user types.

Proposal

Must haves:

Nice to haves:

Prototype

terraform-ls: https://github.com/hashicorp/terraform-ls/compare/poc-earlyvalidation
ignore the command and code action related changes

hcl-lang: https://github.com/hashicorp/hcl-lang/compare/poc-earlyvalidation

Notes / Postponed ideas

@glennsarti
Copy link
Contributor

I ran into this today. Inline tf validate would be so so so so so helpful. Manually running on every save is horrible.

Also the invalidation of the errors is a bit hit and miss.

therefore unsuitable to run as the user types.

I could also argue, why not let users decide what is suitable for them and what is not.

@radeksimko
Copy link
Member Author

radeksimko commented Sep 9, 2022

Manually running on every save is horrible.

Can you be a bit more specific about what part of it is horrible? It's not clear to me whether you're talking about terraform.experimentalFeatures.validateOnSave or literally running terraform validate from the terminal or via the command palette. Have you tried the experimental feature?

Also the invalidation of the errors is a bit hit and miss.

Can you expand on this a bit more and explain how it is relevant to the original issue outlined above?


I'd like to also point out that the intentions outlined in this issue are not to fully re-implement or further deepen integration with the validate command. Instead the intention is to re-implement certain parts of it. Specifically the parts which don't depend on the plugins, which is where the majority of the performance hit (and also UX hurdles) comes from.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants