Configuring Terraform on Windows 10 Linux Sub-System
Published Apr 09 2019 01:26 PM 76.6K Views

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 -


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 -


Once the subsystem is installed please ensure its updated. 

  1. Click Start
  2. Search for Ubuntu (or your installed distro) and open
  3. Run the following commands to make sure Ubuntu is 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..

  1. Open
  2. Click Install
  3. Reload VScode window

Step 4: Will walk you through how to download, extract and install Terraform on the Linux Sub-System using the terminal.

  1. Open Ubuntu application (or your installed distro)
  2. Run the following command which will install unzip (its my preference to extract files)
    sudo apt-get install unzip
  3. Navigate to the Terraform download page and grab the most recent download URL.
  4. Using the above URL, run the following commands which will download, unzip, move the binary to users bin.
    wget <terraform_url> -O;
    sudo mv terraform /usr/local/bin;
    wget -O; 
    sudo mv terraform /usr/local/bin; 
  5. Run the following command to verify terraform is installed.
    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.


  1. Launch Visual Studio Code.
  2. Go to the Terminal menu and select New Terminal which will launch a terminal at the bottom. By default, the terminal is set to powershell, type bash to switch the terminal to bash shell.  You can make this permanent by modify a few settings in Visual Studio Code.
    *Take note that your terminal path should now show the path from the Linux sub-system to your folder or current directory on your windows machine.  Just because your using bash doesn't mean your code needs to reside in the Linux sub-system, although it can.  It is my preference to have my code in a windows directory tied to a Git repo.


  3. Create a folder on your computer called Terraform Example (note the path).
  4. From Visual Studio Code, open the folder from File > Open Folder.   You will need to reopen the terminal window and switch to bash (step 2 from above).
  5. Create a file inside of the folder with a name of
  6. Paste the following TCL code in the
    resource "azurerm_resource_group" "rg" {
      name     = "rg_test"
      location = "West US"
      tags = {
        environment = "Terraform Test RG"
    Your vs-code window should look like this:


  7. Run a terraform init from the terminal which will prepare Terraform in this directory.

    Based on the code Terraform knows that we need the azurerm provider and automatically downloads it.

  8. Lets run our first plan to see what changes Terraform has pending.
    terraform plan
    As we can see the only pending change is the resource group called rg_test.
  9. Now that we have evaluated the plan we can run a apply.
    terraform apply
  10. When prompted type yes to apply the the changes shown.


  11. Run this command to show the resource group which was just created or open the portal to validate.
    az group list --query "[?name=='rg_test']"





Version history
Last update:
‎Sep 25 2019 10:46 AM
Updated by: