VSCode and terragrunt
Is there a recommended way to get get formatting for terragrunt enabled on vscode? I am trying to use a custom formatter, but this seems to cause some odd issues where on file save, the contents of the file vs the editor are different. Here is the snippet from settings: ``` "[hcl]": { "editor.defaultFormatter": "jkillian.custom-local-formatters", }, "customLocalFormatters.formatters": [ { "command": "terragrunt hclfmt -", "languages": ["hcl"] } ], ``` Error I get randomly when using this: ``` Failed to save 'terragrunt.hcl': The content of the file is newer. Please compare your version with the file contents or overwrite the content of the file with your changes. ``` --- <ins datetime="2024-01-29T20:25:06Z"> <p><a href="https://support.gruntwork.io/hc/requests/110728">Tracked in ticket #110728</a></p> </ins>
Hi, yes, now `terragrunt hclfmt` formats all files even before visual code save file, in my projects I use workaround script `format.sh` which save stdin to a temporary file, run formatting on it and read it back: ``` #!/bin/bash temp_file=$(mktemp) # save input to a temp file cat > "$temp_file" # format single file terragrunt hclfmt --terragrunt-hclfmt-file "$temp_file" # print rendered file cat "$temp_file" # clean temporary file rm -f "$temp_file" ``` Configuration in `settings.json`: ``` { "editor.formatOnSave": true, "[hcl]": { "editor.defaultFormatter": "jkillian.custom-local-formatters", }, "customLocalFormatters.formatters": [ { "command": "./format.sh", "languages": [ "hcl" ] } ] } ```