<p>Currently, there is only one extension for Visual Studio Code which highlights Terragrunt - <a href="https://marketplace.visualstudio.com/items?itemName=4ops.terraform" rel="nofollow noreferrer">https://marketplace.visualstudio.com/items?itemName=4ops.terraform</a></p>
<p>It is better than nothing.</p>
<hr />
<p>You can also format Terragrunt configurations before git commit automatically using <a href="https://www.pre-commit.com/" rel="nofollow noreferrer">pre-commit</a> and <a href="https://github.com/terraform-aws-modules/meta/blob/master/.pre-commit-config.yaml" rel="nofollow noreferrer">such config</a>.</p>

CC BY-SA 4.0
2021-03-03T17:14:12.793Z
Thanks bro! Works to me, but was necessary delete my ~/.vscode/ probably some weird thing there.
Vader
CC BY-SA 4.0
2021-03-03T08:07:39.537Z
2021-03-03T08:07:39.537Z
Anton Babenko
<p>Just to point out that there is now an <a href="https://marketplace.visualstudio.com/items?itemName=HashiCorp.HCL" rel="nofollow noreferrer">official HashiCorp Visual Studio Code extension for HCL</a>.</p>
<p>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 <a href="https://github.com/hashicorp/vscode-terraform/issues/639" rel="nofollow noreferrer">this is the thread.</a>
More details in the official HashiCorp <a href="https://www.hashicorp.com/blog/announcing-the-hcl-extension-for-visual-studio-code-0-1" rel="nofollow noreferrer">blog post announcing the extension</a>.</p>
<p>Enjoy and happy coding.</p>

CC BY-SA 4.0
2023-08-12T17:07:35.097Z
That extension does not really support the terragrunt.hcl
Moulick
CC BY-SA 4.0
2023-04-10T20:20:50.573Z
2023-04-10T20:20:50.573Z
1vand1ng0
<p>Until an add-on will be available, you can run this:</p>
<p>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.</p>
<pre><code>terragrunt hclfmt
</code></pre>
<p>Or this, to format a sepcific file:</p>
<pre><code>terragrunt hclfmt --terragrunt-hclfmt-file /path/to/hcl/file
</code></pre>
<p><a href="https://terragrunt.gruntwork.io/docs/getting-started/configuration/" rel="noreferrer">https://terragrunt.gruntwork.io/docs/getting-started/configuration/</a></p>
<p><strong>Take it one step further:</strong></p>
<ol>
<li>Install Run on Save -
<a href="https://marketplace.visualstudio.com/items?itemName=emeraldwalk.RunOnSave" rel="noreferrer">https://marketplace.visualstudio.com/items?itemName=emeraldwalk.RunOnSave</a></li>
<li>Add the follwoing config to <em>settings.json</em></li>
</ol>
<pre class="lang-json prettyprint-override"><code>&quot;emeraldwalk.runonsave&quot;: {
    &quot;commands&quot;: [
        {
            &quot;match&quot;: &quot;\\.hcl$&quot;,
            &quot;cmd&quot;: &quot;terragrunt hclfmt --terragrunt-hclfmt-file ${file}&quot;
        }
    ]
}
</code></pre>
<p>Now every time you will save <code>.hcl</code> file, the <code>terragrunt hclfmt</code> command will run and reformat that file.</p>
<p>Note - if you have auto save enabled, it will run automatically every time you make a change to <code>.hcl</code> file.</p>

CC BY-SA 4.0
2022-06-15T13:05:52.677Z
2022-07-04T08:08:47.713Z
2022-07-04T08:08:47.713Z
shbedev
<p>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?</p>
<p>The official <a href="https://marketplace.visualstudio.com/items?itemName=HashiCorp.terraform" rel="nofollow noreferrer">Terraform from Hachicorp</a> not works, because I'm using Terragrunt Syntax.
I tried too the another called <a href="https://marketplace.visualstudio.com/items?itemName=wholroyd.HCL" rel="nofollow noreferrer">Hashicorp HCL</a>, but the bugs continues...</p>

<terraform><linting><terragrunt>
Terragrunt Linter
Vader
# Terragrunt Linter

(Asked by: username_0 on 2021-03-02)

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](https://marketplace.visualstudio.com/items?itemName=HashiCorp.terraform) not works, because I'm using Terragrunt Syntax.
I tried too the another called [Hashicorp HCL](https://marketplace.visualstudio.com/items?itemName=wholroyd.HCL), but the bugs continues...

**Tags:** terraform, linting, terragrunt


---

## 3 answers

### Answer by username_4 on 2022-06-15. Score: 6 | Accepted answer

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.


---

### Answer by username_1 on 2021-03-03. Score: 3

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](https://www.pre-commit.com/) and [such config](https://github.com/terraform-aws-modules/meta/blob/master/.pre-commit-config.yaml).

> **Comments:**
> **username_0**: Thanks bro! Works to me, but was necessary delete my ~/.vscode/ probably some weird thing there.  

---

### Answer by username_2 on 2023-04-10. Score: 0

Just to point out that there is now an [official HashiCorp Visual Studio Code extension for HCL](https://marketplace.visualstudio.com/items?itemName=HashiCorp.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.](https://github.com/hashicorp/vscode-terraform/issues/639)
More details in the official HashiCorp [blog post announcing the extension](https://www.hashicorp.com/blog/announcing-the-hcl-extension-for-visual-studio-code-0-1).

Enjoy and happy coding.

> **Comments:**
> **username_3**: That extension does not really support the terragrunt.hcl  

---

