Want to Terraform using Visual Studio Code on Linux but have a Windows 10 machine? Follow these easy steps to quickly get your environment up in running.
Step 1: Install Visual Studio Code - https://code.visualstudio.com/download
Step 2: Install Windows Subsystem on your Windows 10 Machine. I tend to lean towards Ubuntu, however there are several distros to choose from. This article will walk you through installing the Windows Subsystem for Linux - https://docs.microsoft.com/en-us/windows/wsl/install-win10#install-the-windows-subsystem-for-linux
Once the subsystem is installed please ensure its updated.
sudo apt-get update sudo apt-get upgrade
Step 3: Install Visual Studio Code Terraform Extension which will allow you to have intelli-sense and support for the different Terraform file types..
Step 4: Will walk you through how to download, extract and install Terraform on the Linux Sub-System using the terminal.
sudo apt-get install unzip
wget <terraform_url> -O terraform.zip; unzip terraform.zip; sudo mv terraform /usr/local/bin; rm terraform.zip;example:
wget https://releases.hashicorp.com/terraform/0.11.13/terraform_0.11.13_linux_amd64.zip -O terraform.zip; unzip terraform.zip; sudo mv terraform /usr/local/bin; rm terraform.zip;
terraform -v
Step 5: Terraform can authenticate a few different ways. For this example we will use Azure CLI, which needs to be installed on the linux sub-system. Steps to install on several different distros can be found here. If you installed Ubuntu in Step 2 then you can following these steps.
Verify that Azure CLI was installed correctly by running the following:
az -v
Step 6: Log in to Azure CLI for your target environment by running the below command. If successful it should launch a browser window.
az login
Enter your credentials in the browser window and walk through the MFA process (if enabled). Once
you sign in your browser window should look like...
The Azure CLI window should now say your logged in and will automatically list all subscriptions you have access.
Run the following command to show all subscriptions.
az account list -o table
Locate the subscription that you want to target and copy the subscription guid to your clipboard. Run the following command to set the subscription as your active account.
az account set -s <subscription_guid>; az account show -o table
Now that we have completed the below steps we are ready to move onto working with Terraform in Visual Studio Code.
Working with Terraform... In this example we will deploy a simple Resource Group from Visual Studio Code leveraging Terraform and Azure CLI on the Linux Sub-system.
resource "azurerm_resource_group" "rg" { name = "rg_test" location = "West US" tags = { environment = "Terraform Test RG" } }Your vs-code window should look like this:
Based on the code Terraform knows that we need the azurerm provider and automatically downloads it.
terraform plan
terraform apply
az group list --query "[?name=='rg_test']"
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.