


Navigate to File -> Preference-> Settings as shown below screenshot. Step 3: Configure Terraform Auto Format in VS Code Click on Install from the detail screen or list screen and the extension gets installed. Once the Hashicorp Terraform appears, select it to see the details as seen above. You will see the list of popular extensions and a search bar as shown below where you can search for an extension. You can also use a shortcut Ctrl+Shift+X to open the Extensions. Open VS Code and click on the Extensions icon from the activity bar on the side of the VScode. And that’s why we’ll install this extension first. Hashicorp Terraform extension provides you with a formatter that formats your code with terraform fmt automatically. Step 2: Install HashiCorp Terraform Extention in VS Code Once, VS Code is installed, move to step 2 and we will be adding an extension. If not, just follow this official page to install it on your system. If you already have Visual Studio Code or VS Code installed in your system then move to the next step. Validate Format on Save Step 1: Install Visual Studio Code.Write some Terraform Code or Import Existing.Configure Terraform Auto Format in VS Code.Install HashiCorp Terraform Extention in VS Code.I am breaking down the steps and making it as simple as possible. Steps to Auto Format Terraform Code in Visual Studio Code on Save Your terraform code will be formatted automatically. However, what if you forget to run terraform fmt every time you write new terraform code? You will commit your file in version control and your terraform code will stay easier to read and maintain until you decide to change that.Īnd the best way to change that is to enable auto-format on save so that you don’t need to worry about it. Open your terraform project in a terminal. If you are not a very frequent user of terraform, it’s okay to just run the terraform fmt command and it formats your terraform file correctly.

Subscribe Why Formatting Your Terraform Manually with terraform fmt is not enough?
