Vscode-terraform: [tracking issue] tflint

Created on 5 Jun 2020  路  11Comments  路  Source: hashicorp/vscode-terraform

v2 temporarily dropped tflint support
this ticket is meant to track progress on that

enhancement

Most helpful comment

@radeksimko I think this is a must have. I had to go back to IntelliJ, you cannot write fast efficient TF code without proper linting.

All 11 comments

I am not that familiar with tflint myself, but we could implement this via the language server as part of https://github.com/hashicorp/terraform-ls/issues/27 which would have the benefit of providing more contextual hints in the code (like highlighting the offending sequence of characters), but I'm not sure if tflint does actually return the warnings/errors with some machine-readable context (in the form of code range).

Alternatively we could just execute tflint from the client and display the output just associated with the file.

The other question is whether the extension should also manage installation/upgrade of tflint. I suppose initially doesn't need to, but long-term should?

@radeksimko not sure who this will work on v2
previously it was used by the old (current?) version by having it installed on the host and formating and testing the code

for clarification here is the project https://github.com/terraform-linters/tflint
maybe @wata727 can provide some insight?

TFLint can also run as an LSP server compliant with the Language Server Protocol v3.14.0 so that it can be integrated with any editor. Here is a sample of simple VS Code integration: https://github.com/terraform-linters/vscode-tflint-lsc/blob/764822b9864db5bb96db5592242692b29509a0bd/src/extension.ts

The language server supports textDocumet/publishDiagnostics notifications and can notify you of warnings based on change events.

I'm not sure how it would be preferable to implement it, but it would be a good start to support hooks that can add any language server to this extension. In my opinion, TFLint is not an official HashiCorp project, so I think it's best to provide it as a customization feature and not support installations or upgrades.

TFLint is not an official HashiCorp project, so I think it's best to provide it as a customization feature and not support installations or upgrades.

Agreed, I think if we integrate tflint in some way it would be opt-in, but the "opt-in" could in theory be just having tflint installed and available in $PATH?

As for the integration, I would think the easiest interface to work with would be just plain shell execution with decent machine-readable (JSON) output, similar to terraform validate -json. Is that something tflint can provide?

tflint --format json should work! Reported issues have an associated hcl.Range.

@wata727 @bendrucker happy to have some higher bandwidth chats about tighter integration here, feel free to reach out to me at [email protected] and we can add you to our internal Slack or something.

All that being said, definitely want to add these integration points for additional diagnostic sources and already outputting the ranges seems like it should be a good hook.

This is to confirm i cannot make tflint working in VSCode even though it is in $PATH and/or hard-coded in settings.json:
"terraform.lintPath": "/usr/local/bin/tflint"

Error message:
command 'terraform.lint' not found

My setup:

VSCode:
  Version: 1.38.1
  Commit: b37e54c98e1a74ba89e03073e5a3761284e3ffb0
  Date: 2019-09-11T13:30:08.229Z
  Electron: 4.2.10
  Chrome: 69.0.3497.128
  Node.js: 10.11.0
  V8: 6.9.427.31-electron.0
  OS: Linux x64 4.18.0-80.11.2.el8_0.x86_64

HashiCorp Terraform 
  Version: 0.12.9

HashiCorp Terraform for VSCode
  Version: 1.4.1

TFLint
  Version: 0.18.0

tflint --format json should work! Reported issues have an associated hcl.Range.

I'm curious how you use that. I have the vscode terraform plugin installed and flint is installed with brew. If I make typo like var.thisismissing into a .tf file, it will not be detected:

data "aws_s3_bucket" "default" {
  bucket = format("%s-default-%s", var.thisismissing, var.environment)
}

$ tflint --format json
{"issues":[],"errors":[]}

IntelliJ's Terraform plugin will detect the missing variable.

Just to clarify this issue is discussing the _plan_ of implementing the integration.

i.e. tflint is not _yet_ integrated with the VSCode extension or the language server.

@radeksimko I think this is a must have. I had to go back to IntelliJ, you cannot write fast efficient TF code without proper linting.

Any news about this? I'm using tflint for cloud specific linting/rule check, for example to lint Azure VM sizes and naming conventions. Is such functionality possible with native tools?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

avinashkavi447 picture avinashkavi447  路  7Comments

meysholdt picture meysholdt  路  5Comments

vazkarvishal picture vazkarvishal  路  5Comments

kagarlickij picture kagarlickij  路  5Comments

okgolove picture okgolove  路  4Comments