Terraform Fundamentals - Installing Terraform on any OS
Learn how to install Terraform on any OS, test it with the CLI, and pin specific versions to ensure stability across red team infrastructure deployments.
Let’s walk through how to install Terraform across different operating systems—Linux, macOS, and Windows—using either package managers or manual methods. I will also show you how to test your installation and control the version you’re using.
Follow my journey of 100 Days of Red Team on WhatsApp, Telegram or Discord.
What is Terraform (Technically)?
In previous posts, I covered Terraform at a conceptual level. Now, I will describe Terraform in technical terms.
Terraform is a lightweight CLI tool built in Go. It’s distributed as a single static binary, that means no runtime, no dependencies. This makes it:
Easy to install
Easy to move between systems
Great for scripting and automation
Whether you’re building a C2 redirector in AWS or automating infrastructure as part of a larger op, having Terraform installed correctly and version-controlled correctly is the first step to building out reliable, repeatable infrastructure for your operations.
For more comprehensive installation instructions please visit the official Terraform installation guide.
Option 1: Installing via package managers
Using the system’s package manager helps you install Terraform quickly and update it easily when needed.
Linux (APT - Ubuntu/Debian/Kali)
HashiCorp (Terraform's creator) provides an official APT repo. Here’s how to install:
sudo apt-get update && sudo apt-get install -y gnupg software-properties-common curl
curl -fsSL https://apt.releases.hashicorp.com/gpg | sudo gpg --dearmor -o /usr/share/keyrings/hashicorp-archive-keyring.gpg
echo "deb [signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] https://apt.releases.hashicorp.com $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/hashicorp.list
sudo apt update && sudo apt install terraform
macOS (Homebrew)
If you’re on a Mac and use Homebrew (highly recommended):
brew tap hashicorp/tap
brew install hashicorp/tap/terraform
Windows (Chocolatey or Scoop)
You can use either Chocolatey or Scoop on Windows to install Terraform:
choco install terraform
OR
scoop install terraform
Both will place the binary in your system’s PATH, so it’s accessible from any shell.
Option 2: Manual installation (All platforms)
If you prefer total control of the installation process or want to install a very specific version, follow the steps below:
Go to terraform.io/downloads
Download the
.zip
for your OS and architectureExtract and move the binary to a folder that’s in your system PATH
This method is great for version isolation or portable builds.
Confirm Terraform is working
After installation, test the CLI:
terraform version
You should see output like:
Terraform v1.7.5
on linux_amd64
If so, Terraform is correctly installed and ready to go.
How Terraform versions work (and why you should care)
Terraform updates frequently, sometimes introducing breaking changes. Using different versions across your team, CI/CD pipeline, or during an engagement can result in:
Incompatible modules
Unexpected behaviors
Failed deployments
To maintain consistency, you should always pin the Terraform version used in a project.
How to pin the version (safely & correctly)
Terraform lets you define a required version inside the configuration directory—specifically in a .tf
file.
Most teams do this inside main.tf
or a versions.tf
file for clarity.
Here’s what you need to add:
terraform {
required_version = "~> 1.7.0"
}
The ~>
symbol allows the patch version to be greater than 0
but requires the major and minor versions (1.7
) to match the version that the configuration specifies. Terraform will error if you attempt to use this configuration with a more recent version than 1.7.x
, because of this required_version
setting.
This guarantees consistent execution across systems and also helps in preventing bugs caused by breaking changes in future versions.
You can be even more specific if needed:
terraform {
required_version = "= 1.7.5"
}
You can also enforce provider versions in the same block. We'll cover that when working with providers in later posts.
TL;DR
This post covered installing Terraform on Linux, macOS, and Windows using package managers or manual methods. I also covered how to verify your install with terraform version and how to pin a specific version in your project to avoid compatibility issues—critical for consistency in red team operations.
Follow my journey of 100 Days of Red Team on WhatsApp, Telegram or Discord.