Don't miss out on new posts! Sign up! Also, visit the VHT Forums!

Install Terraform DevOps Beginners Guide

Getting started with DevOps is a great way to introduce yourself to the more modern way of controlling infrastructure as code with tools that treat building infrastructure by its definition in infrastructure code. In this way, you can provision infrastructure in a declarative way to define what the infrastructure should look like, and then the tools make the infrastructure “look” like the code. Terraform is one such tool that allows DevOps engineers to build out complex infrastructure as code.

Introduction to Terraform and Its Role in DevOps

Terraform, a tool by HashiCorp, allows developers and operations teams to define, provision, and manage various cloud services and on-premises infrastructure like VMware vSphere, using simple, declarative syntax. To begin, we need to look at the process of installing Terraform. Terraform is support for installation in many operating systems, including mac OS. We will consider how to do this in both Windows and Linux.

Preparing to Install Terraform on Windows

First, let’s understand how we install Terraform on Windows. You can use the GUI, or you can use the lesser-known winget command. I prefer the winget approach as it is less cumbersome and automatically pulls the binary from the package repository, but let’s look at both.

Understanding the Terraform Executable File for Windows

Before you install Terraform on a Windows machine, it’s crucial to comprehend the nature of the Terraform executable file. Terraform is distributed as a single binary, so you don’t need a complex installation process. You simply need to download the correct version of the Terraform binary for your system.

Step-by-Step Guide to Installing Terraform on Windows

To install Terraform on Windows, follow these steps:

  1. Download the appropriate Terraform zip file from HashiCorp’s official repository.
  2. Extract the Terraform executable file from the downloaded zip file.
  3. Place the extracted file in a suitable directory, like C:\Terraform.
  4. Add the Terraform directory to your system environment variables to make Terraform commands accessible from the command prompt.

To download the appropriate Terraform ZIP file from here: HashiCorp Developer. Choose the appropriate architecture for your Windows machine. Hashicorp distributes Terraform repository downloads in the ZIP format. The download defaults to the latest Terraform version.

Download the latest version of terraform
Download the latest version of terraform

Once you have the ZIP file, extract the ZIP file to reveal the EXE file.

Extract the terraform executable
Extract the terraform executable

You will then need to copy this to the directory in which you want to house Terraform. This is important as we will want to add a Path variable to reference the Terraform location so we don’t have to change the directory each time to run Terraform.

Copy the terraform install to the target folder location
Copy the terraform install to the target folder location

Launch the sysdm.cpl tool and navigate to Advanced > Environment variables > System variables > PATH

Set your path environment variable to the terraform install location
Set your path environment variable to the terraform install location

Once you have the PATH variable updated, you will need to relaunch your PowerShell or command prompt so the new variable takes effect. Then, you should be able to check to see if the terraform command is found:

terraform --version
Check the terraform version information to confirm the installation
Check the terraform version information to confirm the installation

Install Terraform on Windows using Winget

Many do not know, if you are using Windows installing Terraform can be accomplished using a very “linux like” experience installing Terraform on Windows using the winget command. Winget is a fantastic command line tool to install and update software in Windows 11, and it is native to the operating system.

Using winget it automatically installs the terraform package, using the extracted terraform file, and sets up the tool accordingly. One thing about this approach as well is you don’t have to install the environment variable to allow the terraform executable to be referenced properly.

You can see the terraform packages available for installation with winget using the command:

winget search terraform
Search for terraform using winget
Search for terraform using winget

To install Terraform using winget, we can use the below command:

winget install Hashicorp.Terraform
Install terraform using winget
Install terraform using winget

After installation, you can check the version of Terraform and that it has been installed correctly, using the command:

terraform --version
Check the terraform version from the command line
Check the terraform version from the command line

Install Terraform on Linux Systems

Installing Terraform on a Linux system requires a different approach to the installation process, but it is one that most are familiar with if you have worked with Linux from the command line.

Terraform Installation on Debian and Ubuntu

  1. Add the official HashiCorp Linux repository to your package repositories using sudo apt-add-repository.
  2. Update your package list with sudo apt-get update.
  3. Install Terraform using sudo apt install terraform.

The above steps for Debian and Ubuntu can be accomplished using the following:

wget -O- | sudo gpg --dearmor -o /usr/share/keyrings/hashicorp-archive-keyring.gpg

echo "deb [signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/hashicorp.list

sudo apt update && sudo apt install terraform

Pulling down the GPG key.

Download the gpg key to install terraform
Download the gpg key to install terraform

Adding the repository via the GPG key.

Add the terraform install repository
Add the terraform install repository

Below is running the command to install Terraform in Ubuntu Linux.

Installing terraform in ubuntu linux
Installing terraform in ubuntu linux

Installing Terraform on Red Hat, Fedora, and CentOS

For RPM-based Linux distributions, such as Red Hat, Fedora, and CentOS, you can use dnf or yum package managers. The process involves adding the HashiCorp repository and then installing Terraform.

For CentOS and RHEL:

sudo yum install -y yum-utils

sudo yum-config-manager --add-repo

sudo yum -y install terraform

For Fedora:

sudo dnf install -y dnf-plugins-core

sudo dnf config-manager --add-repo

sudo dnf -y install terraform

Verifying Your Terraform Installation

After installation, like Windows, you can run terraform –version to see the installed version. This step ensures that the Terraform executable is correctly placed and that your path environment variable is properly set.

Terraform version command on linux
Terraform version command on linux

The shift to Immutable Infrastructure

Terraform allows you to make a shift towards immutable infrastructure. What does this mean? It is where changes are made by replacing entire configurations rather than modifying or upgrading existing infrastructure, as we have done with legacy systems in years past.

Terraform and Cloud Providers

Terraform supports most of the major cloud providers like AWS, Azure Cloud, and Oracle Cloud. This allows for integration and management of cloud infrastructure across different platforms. So, no matter which cloud or multi-clouds are used, Terraform can be at the center of your DevOps strategy.

Advanced Terraform Features for DevOps

Terraform also provides many capabilities and features for advanced DevOps practices.

Utilizing Terraform for Complex Infrastructure Management

It uses a declarative syntax and pluggable modules. It allows the management of complex, multi-tier infrastructure in code.

Terraform in automation and orchestration

With Terraform, you can define infrastructure in machine-readable definition files, enabling automation of deployment and scaling processes. This helps to reduce manual tasks and processes and the potential for human error. It also opens up the possibility of using Terraform and infrastructure as code in Gitops processes using a CI/CD pipeline.

Wrapping up and Next Steps in Your Terraform and DevOps Journey

If you are starting your DevOps journey, installing Terraform on Windows or Linux systems, is a crucial first step in starting to learn about infrastructure as code. In the parts of this series to follow, we will delve deeper into using Terraform. We will look at provisioners, and some beginner projects to get started. After that, we will look at advanced infrastructure management and best practices in Terraform configuration and deployment.

Brandon Lee

Brandon Lee is the Senior Writer, Engineer and owner at and has over two decades of experience in Information Technology. Having worked for numerous Fortune 500 companies as well as in various industries, Brandon has extensive experience in various IT segments and is a strong advocate for open source technologies. Brandon holds many industry certifications, loves the outdoors and spending time with family.

Related Articles

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.