⚙️ Pre-requisites and Installation Guide for Terraform on Windows & Linux (with Best Security Practices)

Terraform is one of the most widely used Infrastructure as Code (IaC) tools in DevOps. Before you start provisioning resources, you need to install Terraform correctly on your system.

In this blog, we’ll cover:

  • ✅ Pre-requisites before installation

  • ✅ How to install Terraform on Windows and Linux

  • ✅ Best security practices for installation

  • ✅ How to check if Terraform is installed successfully


🔹 Pre-requisites for Terraform Installation

Before installing Terraform, make sure you have:

  1. Admin/Root Access

    • On Windows → Run as Administrator if using Chocolatey or editing PATH.

    • On Linuxsudo privileges.

  2. Supported OS & Architecture

    • Windows 10/11 (64-bit recommended)

    • Linux distributions (Ubuntu, CentOS, RHEL, etc.)

  3. Package Manager (Optional but Recommended)

    • Windows: Chocolatey or Scoop

    • Linux: apt (Debian/Ubuntu), yum/dnf (CentOS/RHEL), or Homebrew for Linux

  4. Network Access

    • Terraform downloads provider plugins from HashiCorp registry, so ensure firewall/proxy allows HTTPS connections.

🔹 Installation on Windows

Option 1: Manual Installation

  1. Download Terraform from → HashiCorp Downloads.

  2. Extract the .zip file.

  3. Move terraform.exe to:

     C:\Program Files\Terraform
    
  4. Add the folder to System PATH:

    • Search → Environment Variables → Edit System Variables → Add:

        C:\Program Files\Terraform
      
  5. Restart PowerShell/Command Prompt.


If you have Chocolatey installed:

choco install terraform -y

Update later:

choco upgrade terraform -y

Verify Installation

terraform -version

🔹 Installation on Linux

Step 1: Update Packages

sudo apt update && sudo apt upgrade -y   # Ubuntu/Debian

Step 2: Install Required Dependencies

sudo apt install -y gnupg software-properties-common curl unzip

Step 3: Add HashiCorp GPG Key & Repository

curl -fsSL https://apt.releases.hashicorp.com/gpg | sudo apt-key add -
sudo apt-add-repository "deb [arch=amd64] https://apt.releases.hashicorp.com $(lsb_release -cs) main"

Step 4: Install Terraform

sudo apt update && sudo apt install terraform -y

For CentOS/RHEL:

sudo yum install -y yum-utils
sudo yum-config-manager --add-repo https://rpm.releases.hashicorp.com/RHEL/hashicorp.repo
sudo yum -y install terraform

Verify Installation

terraform -version

🔹 Best Security Practices for Installing Terraform

  1. Download Only from Official Sources

    • Use HashiCorp’s official site or package repositories.

    • Avoid third-party binaries.

  2. Verify Binary Checksum

    • Each Terraform release provides a checksum file. Example:

        sha256sum terraform_x.x.x_linux_amd64.zip
      
    • Compare with HashiCorp’s published SHA256 checksum.

  3. Use Least Privilege Principle

    • Do not run Terraform with root/admin unless required.

    • Use restricted AWS IAM roles/policies when connecting Terraform to AWS.

  4. Secure State Files

    • Terraform keeps a terraform.tfstate file containing sensitive info.

    • Store it securely in remote backends (e.g., S3 with DynamoDB lock, or HashiCorp Consul).

    • Never commit state files to GitHub.

  5. Keep Terraform Updated

    • Regularly update Terraform to patch vulnerabilities.

🔹 How to Check if Terraform is Installed

Run:

terraform -version

Output (example):

Terraform v1.9.2
on linux_amd64

Run help command to verify available commands:

terraform --help

📌 Conclusion

Terraform installation is simple but following best practices ensures that your system and infrastructure remain secure.

  • ✅ Installed Terraform on Windows & Linux

  • ✅ Added Terraform to PATH

  • ✅ Verified installation

  • ✅ Covered security best practices

With Terraform ready, you can now move on to provisioning your first AWS EC2 instance or other cloud infrastructure. 🚀


👉 Next, I’ll write about provisioning EC2 with Terraform (Day 23) in detail, including hands-on code and interview questions. Stay tuned!

#Terraform #DevOps #AWS #InfrastructureAsCode #Security #Cloud

0
Subscribe to my newsletter

Read articles from Tathagat Gaikwad directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Tathagat Gaikwad
Tathagat Gaikwad