The Easiest Way to Run Terraform in Visual Studio Code

Terraform is code for creating, modifying, and deleting infrastructure on the cloud. The terraform code can be dry run in the Visual Studio Code editor (VSC) before you apply it to the cloud environment such as AWS/AZURE/GC.

Dry run of Terraform codes

#1 Install Terraform

Download the terraform for Windows from the download link. Copy the terraform.exe to the C drive folder (create a folder) C:\Terraform, and set the .exe file path in Environment variables.

Install Terraform

# 2 Install Visual studio code editor

The steps to install it are explained in my previous post. Follow the same.

#3 Install the extension for Visual studio code

Go to the download link and install it and open the same in the VSC.

Terraform extension for Visual Studio Code

#4 Verify Terraform installation

Open the VSC editor and terraform file folder. Consequently, it initiates Terraform environment. To check for terraform installation, open the command prompt (cmd) and issue the below command:

Terraform version

#5 Open Visual Studio Code editor

Open the VSC editor and terraform file (extension is .tf). And click on the Terminal button, and start issuing the below commands:

terraform init
terraform plan
Visual Studio Code editor

And, if there are no errors, run the below command, which applies changes to the cloud environment.

terraform apply

To sum up, these steps are helpful to do a dry run on your terraform code.

Related

Author: Srini

Experienced software developer. Skills in Development, Coding, Testing and Debugging. Good Data analytic skills (Data Warehousing and BI). Also skills in Mainframe.