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

decoder: Introduce ValidateFilePerSchema() #57

Closed
radeksimko opened this issue Jun 22, 2021 · 3 comments · Fixed by #293
Closed

decoder: Introduce ValidateFilePerSchema() #57

radeksimko opened this issue Jun 22, 2021 · 3 comments · Fixed by #293
Assignees
Labels
enhancement New feature or request

Comments

@radeksimko
Copy link
Member

radeksimko commented Jun 22, 2021

As mentioned in hashicorp/terraform-ls#563 it would be helpful for users to have on-type and/or on-save diagnostics based on the schema.

In Terraform specifically this can be achieved via terraform validate, but that comes with a trade-off in the form of loading all plugins and gRPC chattery with all of them to validate the whole configuration.

While the decoder will never be able to run ValidateFuncs declared within providers, it has most of the other context in the form of schema and so it can do most of the early validation on its own.

Known High-Value Use Cases

Before doing anything beyond the basics above in Terraform specifically we may want to address hashicorp/vscode-terraform#715 + hashicorp/terraform-ls#193 to generally be sure the schema can represent the reality accurately and we can avoid publishing false diagnostics just because we don't have accurate schema.

Proposal

  • Introduce a Validate method in the hcl-lang decoder package that iterates over the module files
func (d *PathDecoder) Validate(ctx context.Context) (hcl.Diagnostics, error)
  • Introduce a ValidateFile method in the hcl-lang decoder package
func (d *PathDecoder) validateFile(ctx context.Context, f *hcl.File) (hcl.Diagnostics, error)
  • Obtain the file contents and schema from the PathDecoder
  • Only validate HCL files (not JSON)
  • Introduce a helper (skeleton) method for validating the file against the schema
func (d *PathDecoder) validateBodyPerSchema(ctx context.Context, body *hclsyntax.Body, bodySchema *schema.BodySchema) (hcl.Diagnostics, error)
  • Introduce a helper (skeleton) method that validates references (based on targets and origins)
  • Add test files

Part of hashicorp/vscode-terraform#720

@radeksimko

This comment was marked as duplicate.

@radeksimko

This comment was marked as duplicate.

@radeksimko
Copy link
Member Author

Nitpick: I think the second method being proposed should probably be called validateBodyPerSchema given that the argument is no longer a whole file, but just AST body.

func (d *PathDecoder) validateBodyPerSchema(ctx context.Context, body *hclsyntax.Body, bodySchema *schema.BodySchema) (hcl.Diagnostics, error)

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

Successfully merging a pull request may close this issue.

2 participants