HiveBrain v1.2.0
Get Started
← Back to all entries
patternterraformMinor

Terragrunt Linter

Submitted by: @import:stackexchange-devops··
0
Viewed 0 times
linterterragruntstackoverflow

Problem

I'm having troubles using HCL files at VSCode. When I open the HCL file the indentations are messy. So I fix it and close the file, when I open again...messy again...
Someone know a add-ons to works with HCL files?

The official Terraform from Hachicorp not works, because I'm using Terragrunt Syntax.
I tried too the another called Hashicorp HCL, but the bugs continues...

Solution

Until an add-on will be available, you can run this:

This will recursively search the current working directory for any folders that contain Terragrunt configuration files and run the equivalent of terraform fmt on them.

terragrunt hclfmt


Or this, to format a sepcific file:

terragrunt hclfmt --terragrunt-hclfmt-file /path/to/hcl/file


https://terragrunt.gruntwork.io/docs/getting-started/configuration/

Take it one step further:

  • Install Run on Save -


https://marketplace.visualstudio.com/items?itemName=emeraldwalk.RunOnSave

  • Add the follwoing config to settings.json



"emeraldwalk.runonsave": {
"commands": [
{
"match": "\\.hcl$",
"cmd": "terragrunt hclfmt --terragrunt-hclfmt-file ${file}"
}
]
}


Now every time you will save .hcl file, the terragrunt hclfmt command will run and reformat that file.

Note - if you have auto save enabled, it will run automatically every time you make a change to .hcl file.

Code Snippets

terragrunt hclfmt
terragrunt hclfmt --terragrunt-hclfmt-file /path/to/hcl/file

Context

StackExchange DevOps Q#13466, answer score: 4

Revisions (0)

No revisions yet.