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...

3 Answers 3


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


Take it one step further:

  1. Install Run on Save - https://marketplace.visualstudio.com/items?itemName=emeraldwalk.RunOnSave
  2. 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.


Currently, there is only one extension for Visual Studio Code which highlights Terragrunt - https://marketplace.visualstudio.com/items?itemName=4ops.terraform

It is better than nothing.

You can also format Terragrunt configurations before git commit automatically using pre-commit and such config.

  • 1
    Thanks bro! Works to me, but was necessary delete my ~/.vscode/ probably some weird thing there.
    – Vader
    Mar 3, 2021 at 17:14

Just to point out that there is now an official HashiCorp Visual Studio Code extension for HCL.

I was also looking for support for HCL syntax in Visual Studio Code and many extensions produced conflicts or were not further in development. Luckily I found the proper extension in a GitHub discussion about this same topic, if you are curious this is the thread. More details in the official HashiCorp blog post announcing the extension.

Enjoy and happy coding.

  • That extension does not really support the terragrunt.hcl
    – Moulick
    Aug 12, 2023 at 17:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.