We need to choose the formatter that VS Code will use to be able to format the terraform code correctly. Therefore, search for the format in the Settings screen.Ĭheck on the Format On Save as shown in the above screen.īut this is not enough to format our terraform code on save. 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. Why Formatting Your Terraform Manually with terraform fmt is not enough? You can also subscribe to our newsletter below to not miss any updates from us. In this post, you will learn to auto format terraform code in Visual Studio Code on save.ĭon’t want to miss any posts from us? join us on our Facebook group, and follow us on Facebook, Twitter, LinkedIn, and Instagram. However, nothing beats the comfort of getting your terraform code formatted on save in autopilot mode. Terraform has a command called terraform fmt that can format your code well. Terraform being our Infrastructure as Code tools use similar best practices as code. And better readability rewards us with other perks like easier-to-maintain code. How to Auto Format Terraform Code in Visual Studio Code on Saveįormatting your code makes it easier to read and understand for yourself and for your fellow co-workers who will collaborate on it.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |