hashicorp / vscode-terraform

HashiCorp Terraform VSCode extension
https://marketplace.visualstudio.com/items?itemName=HashiCorp.terraform
Mozilla Public License 2.0
919 stars 178 forks source link

Hashicopr terraform and hcl version conflicting #1654

Open evertonspader-tomtom opened 9 months ago

evertonspader-tomtom commented 9 months ago

Extension Version

v2.29.1

VS Code Version

Version: 1.84.2 (Universal) Commit: 1a5daa3a0231a0fbba4f14db7ec463cf99d7768e Date: 2023-11-09T10:52:33.687Z (1 mo ago) Electron: 25.9.2 ElectronBuildId: 24603566 Chromium: 114.0.5735.289 Node.js: 18.15.0 V8: 11.4.183.29-electron.0 OS: Darwin arm64 23.1.0

Operating System

macOS Sonoma 14.1.1

Terraform Version

Terraform v1.6.2 on darwin_arm64

Steps to Reproduce

Create a terragrunt.hcl file with any unformatted configuration and save it.

Expected Behavior

*.hcl files should be formatted on save

Actual Behavior

Auto format not working

Terraform Configuration

No response

Project Structure

No response

Gist

No response

Anything Else?

I am posting here as it seems that vscode hcl is not very active.

I have both extensions terraform and hcl installed on VSCode and I would like both terraform and terragrunt files to be auto-formatted on save but *.hcl files don't work at all. This is my VSCode settings.

"files.associations": {
  "*.hcl": "hcl",
  "*.tf": "terraform",
},
"[hcl]": {
  "editor.tabSize": 2,
  "editor.defaultFormatter": "hashicorp.hcl",
  "editor.formatOnSave": true
},
"[terraform]": {
  "editor.tabSize": 2,
  "editor.defaultFormatter": "hashicorp.terraform",
  "editor.formatOnSave": true
},

Workarounds

No response

References

No response

Help Wanted

Community Note

jpogran commented 9 months ago

Hi @evertonspader-tomtom, the vscode-hcl extension does not provide a formatting feature for HCL files, so it will not be able to format any kind of HCL files. It only provides syntax highlighting, as described in the README. There is an existing issue asking for formatting support, which explains the complexity and reason it is not supported yet: https://github.com/hashicorp/vscode-hcl/issues/98

The vscode-terraform extension provides a formatter for that is already configured out of the box to format *.tf files. You do not need to set file associations inside your settings, as both the HashiCorp HCL and Terraform extensions automatically configure those at runtime.

Terragrunt files are a separate product, so you will have to look to product for formatting support. The vscode-hcl extension can provide syntax highlighting for any HCL compliant file, but product specific features like Terragrunt require specific support by those products.