Configuring your Environment for Terraform Development
Published: 2019-04-26 00:48:37

---
title: Configuring your Environment for Terraform Development
published: true
description: 
tags: 
---

<!-- wp:paragraph -->
<p>So I've been doing a lot of work with a set of open source tools lately, specifically <a href="https://www.terraform.io/">TerraForm</a> and <a href="https://www.packer.io/">Packer</a>.
  TerraForm at its core is a method of implementing truly Infrastructure
 as Code, and does so by providing a simple function style language 
where you can create basic implementations for the cloud, and then 
leverage resource providers to deploy.  These resource providers allow 
you to deploy to variety of cloud platforms (the full list can be found <a href="https://www.terraform.io/docs/providers/">here</a>).
  It also provides robust support for debugging, targeting, and supports
 a desired state configuration approach that makes it much easier to 
maintain your environments in the cloud.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Now that being said, like most open source tools, it can require some  configuration for your local development environment and I wanted to  put this post together to describe it.  Below are the steps to  configuring your environment.</p>
<!-- /wp:paragraph -->

<!-- wp:heading {"level":3} -->
<h3>Step 1:  Install Windows SubSystem on your Windows 10 Machine</h3>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>To start with, you will need to be able to leverage bash as part of 
the Linux Subsystem.  You can enable this on a Windows 10 machine, by 
following the steps outlined in this guide:</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p><a href="https://docs.microsoft.com/en-us/windows/wsl/install-win10">https://docs.microsoft.com/en-us/windows/wsl/install-win10</a></p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Once you’ve completed this step, you will be able to move forward with VS Code and the other components required.</p>
<!-- /wp:paragraph -->

<!-- wp:heading {"level":3} -->
<h3>Step 2:  Install VS Code and Terraform Plugins</h3>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>For this guide we recommend VS Code as your editor, VS code works on a
 variety of operating systems, and is a very light-weight code editor.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>You can download VS Code from this link:</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p><a href="https://code.visualstudio.com/download">https://code.visualstudio.com/download</a></p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Once you’ve downloaded and installed VS code, we need to install the <a href="https://marketplace.visualstudio.com/items?itemName=ms-azuretools.vscode-azureterraform">VS Code Extension for Terraform</a>.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Then click “Install” and “Reload” when completed.  This will allow  you to have intelli-sense and support for the different terraform file  types.</p>
<!-- /wp:paragraph -->

<!-- wp:heading {"level":3} -->
<h3>Step 3:  Opening Terminal</h3>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>You can then perform the remaining steps from the VS Code 
application.  Go to the “View” menu and select “integrated terminal”.  
You will see the terminal appear at the bottom:</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>By default, the terminal is set to “powershell”, type in “Bash” to  switch to Bash Scripting.   You can default your shell following this  guidance - <a href="https://code.visualstudio.com/docs/editor/integrated-terminal#_configuration">https://code.visualstudio.com/docs/editor/integrated-terminal#_configuration</a></p>
<!-- /wp:paragraph -->

<!-- wp:heading {"level":3} -->
<h3>Step 4:            Install Unzip on Subsystem</h3>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>Run the following command to install “unzip” on your linux subsystem, this will be required to unzip both terraform and packer.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p><em>sudo apt-get install unzip</em></p>
<!-- /wp:paragraph -->

<!-- wp:heading {"level":3} -->
<h3>Step 5:            Install TerraForm</h3>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>You will need to execute the following commands to download and 
install Terraform, we need to start by getting the latest version of 
terraform.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Go to this link:</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p><a href="https://www.terraform.io/downloads.html">https://www.terraform.io/downloads.html</a></p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>And copy the link for the appropriate version of the binaries for TerraForm.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Go back to VS Code, and enter the following command: <code>wget {url for terraform}</code> Then Run the following commands in sequence: <code>unzip {terraform.zip file name}</code> <code>sudo mv terraform /usr/local/bin/terraform</code> <code>rm {terraform.zip file name}</code> Confirm the installation by typing the following command: <code>terraform --version</code></p>
<!-- /wp:paragraph -->

<!-- wp:heading {"level":3} -->
<h3>Step 6:            Install Packer</h3>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>To start with, we need to get the most recent version of packer.  Go 
to the following Url, and copy the url of the appropriate version.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p><a href="https://www.packer.io/downloads.html">https://www.packer.io/downloads.html</a></p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Go back to VS Code and execute the following commands: </p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p><code>wget {packer url}</code> </p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p><code>unzip {packer.zip file name}</code> </p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p><code>sudo mv packer /usr/local/bin/packer</code> </p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p><code>rm {packer.zip file name}</code></p>
<!-- /wp:paragraph -->

<!-- wp:heading {"level":3} -->
<h3>Step 7:            Install Azure CLI 2.0</h3>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>Go back to VS Code again, and download / install azure CLI.  To do so, execute the steps and commands found here:</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p><a href="https://docs.microsoft.com/en-us/cli/azure/install-azure-cli-apt?view=azure-cli-latest">https://docs.microsoft.com/en-us/cli/azure/install-azure-cli-apt?view=azure-cli-latest</a></p>
<!-- /wp:paragraph -->

<!-- wp:heading {"level":3} -->
<h3>Step 8:            Authenticating against Azure</h3>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>Once this is done you are in a place where you can run terraform 
projects, but before you do, you need to authenticate against Azure.  
This can be done by running the following commands in the bash terminal 
(see link below):</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p><a href="https://docs.microsoft.com/en-us/azure/azure-government/documentation-government-get-started-connect-with-cli">https://docs.microsoft.com/en-us/azure/azure-government/documentation-government-get-started-connect-with-cli</a></p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Once that is completed, you will be authenticated against Azure and 
will be able to update the documentation for the various environments.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p><strong>NOTE:  Your authentication token will expire, should you get a message about an expired token, enter the command, to refresh:</strong> </p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p><code>az account get-access-token</code> </p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Token lifetimes can be described here - <a href="https://docs.microsoft.com/en-us/azure/active-directory/develop/active-directory-token-and-claims#access-tokens">https://docs.microsoft.com/en-us/azure/active-directory/develop/active-directory-token-and-claims#access-tokens</a></p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>After that you are ready to use Terraform on your local machine.  </p>
<!-- /wp:paragraph -->