In VSCode, install the extension : Terraform (mauve.terraform) by Mikael Olenfalk
Then in your the settings.json, add the following config :
{
"[terraform]": {
"editor.formatOnSave": true
}
}
To find the settings.json you can :
- (Ctrl + Shift + P) settings … and select the entry
- Windows
%APPDATA%\Code\User\settings.json
- Windows WSL (remote)
$HOME/.vscode-server/data/Machine/settings.json
- Linux
$HOME/.config/Code/User/settings.json
- macOS
$HOME/Library/Application Support/Code/User/settings.json