Getting started with Terraform and Azure: Overview and Setup

Getting started with Terraform and Azure: Overview and Setup

If you landed here, I assume you know what Terraform is and why to use it.  If that’s not the case, check out the monolog on my video below that covers those topics.  This post, however, is dedicated to the steps required to prepare a Windows 10 computer for Terraform.  The steps are similar if using Windows 11.  The most significant difference is the start menu is in the center bottom of your screen.

There are three components required before using Terraform with Azure.  You need, well, Terraform, the Azure Command Line Interface (CLI), and an editor.  The example here will use VSCode for the editor because it’s free and works very well. 

As already stated, Windows 10 is used to configure the environment.  Don’t feel left out if you are not using Windows.  The steps are similar for Linux and macOS. 

Let’s get started with Terraform.

Terraform

First, download Terraform from the link below. Then, select the version that matches your system.

https://www.terraform.io/downloads.html

Terraform comes as a single executable.  It’s not packaged as an installable file.  We need to extract the file and move it to a folder on the computer.

Create a folder at the root of the C:\ drive called Terraform.

Terraform Folder

Next, go to System Environment Variables on the system. 

Go to System Properties and Environmental Variables.

System Properties

Find Path under System Variables.  Select that and click Edit.

Environment Variables

Click New.

Add C:\Terraform.

Edit Environment Variable

Click OK to exit out of system properties.

Adding that directory to the path statement will allow us to run the terraform command from any directory on the system without specifying C:\Terraform.

Next, let’s go back to downloads, right-click on Terraform and extract.

Extract Terraform to the C:\Terraform directory.

Extract Terraform

Next, open a command prompt and type terraform version.  You should see something like the image below.  That indicates Terraform is installed.  Close the command prompt, and let’s move on.

Test Terraform

If the command doesn’t work, verify the path statement is entered correctly, and the terraform.exe file is in the correct directory.

Azure CLI

Next, let’s install the Azure CLI.  Use the Azure CLI to connect to and deploy resources in Azure.  Go to the download link below.  Notice there are options for macOS and Linux on the left side of the page for those so inclined.

https://docs.microsoft.com/en-us/cli/azure/install-azure-cli-windows?tabs=azure-cli

Download the MSI installer and run once finished downloading. 

Azure CLI Setup

You will need to agree to the terms and can click next to keep the default settings. 

Once finished, open a new command prompt, and type “az version”.  You should get a response similar to below. 

That indicates the Azure CLI is installed. Close the command prompt, and let’s move to the next step.

VSCode

Like before, we need to download a file.  The VSCode installer is found at the link below.

https://code.visualstudio.com/Download

Download the version that corresponds to your system.  For windows, use the User Installer if you don’t have admin access to the computer.

Once downloaded, run the installer.  Accept the terms and click through the default settings. 

Install VSCode

Launch VSCode once finished.

VSCode is installed, but we’re not finished yet.  Go to Extensions on the left side of the screen.

VSCode Extensions

From here, we’ll install three extensions.  An extension adds functionality to VSCode.  It adds features such as advanced language support, autocomplete, and other features that make VSCode easier to use.

The first one we’ll install is “Azure CLI tools”, search for and install that extension.

Azure CLI Tools

Next, search for and install the HashiCorp Terraform extension.  Look for the one by HashiCorp

Terraform Extension

Next, search for “Bracket Pair Colorizer”.  Install version 2.  Bracket Pair Colorizer is optional but helpful for formatting with complex files.

Bracket Pair Colorizer Extension

Test the Environment

There are a couple more steps before we finish. First, go to Terminal, New Terminal.

VSCode Terminal

Enter “Terraform Version”.  You should see the same output as before, similar to the image below.

Do the same for the command “az version”.

Version Test

Once that’s in place, we are ready to get started with Terraform.  The next video on the Terraform workflow and creating a deployment can be found here: https://www.ciraltos.com/terraform-workflow-with-azure-write-plan-and-apply/

Leave a Comment

Your email address will not be published. Required fields are marked *

December 2024
M T W T F S S
 1
2345678
9101112131415
16171819202122
23242526272829
3031  
Scroll to Top