10

I'm hoping there is something to pick up when I have misspelled variables and comments to save me some time when I'm checking my code and reduce the potential for any errors.

I normally use IntelliJ IDE for Terraform on a MAC but also have VS code set up that I can use.

Is there a plugin for either I could use or even a different tool? I imaging variable might be difficult to lint due as I use underscores to separate words in my variable names so the tool would need to know to treat underscores as white space for linting purposes.

doug
  • 523
  • 2
  • 6
  • 14
  • 1
    Have you tried the Hashicorp Terraform plugin for VSCode? https://marketplace.visualstudio.com/items?itemName=HashiCorp.terraform – Bruce Becker Nov 30 '20 at 16:39

4 Answers4

11

terraform fmt

The terraform fmt command is used to rewrite Terraform configuration files to a canonical format and style.

mikequentel
  • 516
  • 3
  • 9
  • 1
    I already use that. – doug Dec 06 '20 at 21:34
  • Thanks anyway though.

    I'm after something to spell check for me.

    I use terraform fmt to formate run terraform plan to check it should run.

    But for spelling, I currently do git compare with branch then look through each bit I changed and copy all my comments and variable names I'm not 100% sure about to word and change any seportors for spaces then see if anything gets highlighted. It's just really not a time-efficient process for that part of it.

    – doug Dec 06 '20 at 21:46
  • @doug it might be easier using an IDE that has spell check (or a plugin thereof). – mikequentel Dec 09 '20 at 21:00
  • The issue I had when I last tried that in VS code was the spell check plugin I used thought all the resources were misspelled as it couldn't pick out words separated by underscores.

    So I need it to treat - . and _ as if they were spaces so it can tell if the words separated by them are spelled correctly.

    – doug Dec 11 '20 at 08:06
  • 1
    Sorry but this is not linting, this is putting something in canonical format as stated but it is not a linter – krystan honour Jul 13 '21 at 10:39
5

The tools that we have include in our Terraform pipelines to check code quality and best practises are;

  1. Tflint
  2. TFSec
  3. Checkov

This way any issues get highlighted early at the MR stage.

1

VSCode has a Terraform Linter "l2fprod.terraform-fork" Have NOT tried it. Did a simple search terra + lint. HTH DrewBai

DrewBai
  • 11
  • 1
1

You can use tflint project. It has lot of plugins for cloud providers. https://github.com/terraform-linters/tflint