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 based on mismatching schema #563

Closed
rchl opened this issue Jun 22, 2021 · 3 comments
Closed

Provide diagnostics based on mismatching schema #563

rchl opened this issue Jun 22, 2021 · 3 comments

Comments

@rchl
Copy link

rchl commented Jun 22, 2021

Current Version

0.18.1

Use-cases

Getting the server to validate the terraform files and highlight invalid code

Attempted Solutions

Proposal

Ideally would see a diagnostic for data.terraform_remote_state, for example, if data.terraform_remote_state is not defined anywhere.

variable "service_host" {
  type = string
}

module "app" {
  source = "[email protected]:remote_repo.git"
  name   = local.fqan

  image = "${local.ecr_image_base_url}:${var.jenkins_app_version}"

  service_listeners = [
    {
      hosts = [var.service_host]
      listener = data.terraform_remote_state.workspaces.outputs.alb_main_public_https_listener_arn
    }
  ]
}

Related LSP methods

textDocument/publishDiagnostics - https://microsoft.github.io/language-server-protocol/specification#textDocument_publishDiagnostics

References

@rchl rchl added the enhancement New feature or request label Jun 22, 2021
@radeksimko radeksimko changed the title Support diagnostics (validating modules) Provide diagnostics for invalid references Jun 22, 2021
@radeksimko radeksimko changed the title Provide diagnostics for invalid references Provide diagnostics based on mismatching schema Jun 22, 2021
@radeksimko
Copy link
Member

Just to add some context here, we do provide diagnostics for invalid HCL syntax, such as

resource "" "" # missing curly brace
}

and all other diagnostics would be provided by the custom validate command, but that comes at a cost since validate has to reach to providers to do the provider-side validation and other things, so I agree that we should provide some early validation as part of LS, based on the schema and enable such validation by default on-type.

@radeksimko
Copy link
Member

A basic initial version of schema-based validation was implemented in #1368 and released as part of v0.32.0.

The example shown above with terraform_remote_state is a particularly complex one as it involves a module (i.e. we need to somehow figure out the variables/inputs and their types) and a terraform_remote_state data source which at least partially relies on data in the state. I think we could enable the validation of data.terraform_remote_state.___ part as part of #1364.

The remaining segments after outputs will be difficult to validate because they represent data inside of a state file, i.e. we need access to the data in the state. This is a problem in itself we have not yet solved and I'm not sure it will have a simple or quick solution. Bear in mind state files are often stored remotely and require auth and aren't necessarily small either so there's plenty of UX implications to consider. Either way we track this more broadly under hashicorp/vscode-terraform#734 (it's under vscode-terraform but that's only because it's one place for "meta" issues not because it's VS Code specific problem).

There are other issues which track various incremental improvements and bugs under the diagnostics label. If there is any particular enhancement or bug we don't track yet I'd encourage you to file it as a new issue.

With all that in mind I'm going to close this one.

Copy link

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.
If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 15, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants