Terraform
14%
Course progress
1 of 14 topics done
Keep going, you are close!
2 topics in a row
1 of 14 topics done
LessonΒ·2 of 14

Installation

N/A14 lessons
1

Installation

πŸ› οΈ Terraform Installation Guide

Terraform InstallationSetupLinuxConfigurationLevelDuration

πŸ“‹ Overview

🎯 Install Terraform on Linux Systems

This guide walks you through installing Terraform on both RHEL-based and Debian-based Linux distributions with step-by-step instructions.

πŸ” What This Guide Covers

  • 🐧 Debian-Based Installation - Ubuntu, Debian
  • πŸ”΄ RHEL-Based Installation - CentOS, AlmaLinux, Rocky Linux
  • πŸ“¦ Repository Setup - Configure package repositories
  • πŸ”‘ GPG Key Setup - Verify package signatures
  • βœ… Verification - Verify successful installation
  • πŸ”§ Configuration - Initial setup
  • πŸ“š Troubleshooting - Common installation issues

🐧 Debian-Based Linux Installation

Debian InstallationUbuntu/Debian

This guide covers the steps to install Terraform on Ubuntu and other Debian-based systems.

πŸ“‹ Prerequisites

Before installing Terraform, ensure your system has the required packages:

  • gnupg: GPG key management
  • software-properties-common: Repository management
  • curl: Download files

Step 1️⃣: Update System and Install Dependencies

Run the following command to update your system and install necessary packages:

bash
sudo apt-get update && sudo apt-get install -y gnupg software-properties-common curl

Step 2️⃣: Add HashiCorp's GPG Key

Add the GPG key to verify package authenticity:

bash
curl -fsSL https://apt.releases.hashicorp.com/gpg | sudo apt-key add -

Step 3️⃣: Add HashiCorp Repository

Add the HashiCorp Linux repository:

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

Step 4️⃣: Update and Install Terraform

Update the package index and install Terraform:

bash
sudo apt-get update && sudo apt-get install -y terraform

Step 5️⃣: Verify Installation

Verify that Terraform installed correctly:

bash
terraform -version

Expected Output:

text
Terraform v1.5.0
on linux_amd64

πŸ”΄ RHEL-Based Linux Installation

RHEL InstallationCentOS/AlmaLinux/Rocky

This guide covers installation on CentOS, AlmaLinux, Rocky Linux, and other RHEL-based systems.

πŸ“‹ Prerequisites

Ensure your system has the required packages:

  • yum-utils: YUM utilities
  • gnupg: GPG key management
  • curl: Download files

Step 1️⃣: Install Dependencies

bash
sudo yum install -y yum-utils gnupg curl

Step 2️⃣: Add HashiCorp Repository

Add the HashiCorp YUM repository:

bash
sudo yum-config-manager --add-repo https://rpm.releases.hashicorp.com/RHEL/hashicorp.repo

Step 3️⃣: Install Terraform

Install Terraform from the repository:

bash
sudo yum install -y terraform

Step 4️⃣: Verify Installation

Verify that Terraform installed correctly:

bash
terraform -version

πŸͺŸ Windows Installation

Windows InstallationWindows Setup

Option 1: Using Chocolatey

powershell
choco install terraform

Option 2: Manual Download

  1. Download from terraform.io/downloads
  2. Extract the ZIP file
  3. Add to PATH environment variable
  4. Verify installation:
powershell
terraform -version

🍎 macOS Installation

macOS InstallationmacOS Setup

Using Homebrew

bash
brew tap hashicorp/tap
brew install hashicorp/tap/terraform

Verify Installation

bash
terraform -version

πŸ“š Terraform Commands Overview

CommandsCLI Tools

Get Help

bash
# General help
terraform -help

# Help for specific command
terraform init -help
terraform plan -help
terraform apply -help

Common Commands

CommandPurpose
terraform initInitialize working directory
terraform planCreate execution plan
terraform applyApply changes to infrastructure
terraform destroyDestroy infrastructure
terraform validateValidate configuration
terraform fmtFormat configuration files
terraform stateManage state

βœ… Verification Checklist

VerificationTesting

After installation, verify everything is working:

bash
# Check version
terraform -version

# Check available commands
terraform -help

# Verify binary location
which terraform

# Check Terraform configuration
terraform version

Expected Output

bash
$ terraform -version
Terraform v1.5.0
on linux_amd64

$ terraform -help
Usage: terraform [-version] [-help] <command> [args]

The available commands for execution are listed below.
The most common, useful commands are shown first, followed by
less common or more advanced commands.

πŸ”§ Initial Configuration

ConfigurationSetup

Create Your First Terraform Configuration

Create a directory for your Terraform project:

bash
mkdir terraform-project
cd terraform-project

Create a basic configuration file:

bash
cat > main.tf << EOF
terraform {
  required_version = ">= 1.0"
  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = "~> 5.0"
    }
  }
}

provider "aws" {
  region = "us-east-1"
}

resource "aws_instance" "example" {
  ami           = "ami-0c55b159cbfafe1f0"
  instance_type = "t2.micro"

  tags = {
    Name = "example-instance"
  }
}
EOF

Initialize Terraform

bash
terraform init

This will:

  • Download provider plugins
  • Create .terraform directory
  • Initialize state management

πŸ› οΈ Troubleshooting

TroubleshootingIssues

Issue: Command not found

Solution:

bash
# Check if Terraform is in PATH
echo $PATH

# Add to PATH if needed
export PATH=$PATH:/usr/local/bin

Issue: GPG key verification failed

Solution:

bash
# Re-add GPG key
curl -fsSL https://apt.releases.hashicorp.com/gpg | sudo apt-key add -

# Update package list
sudo apt-get update

Issue: Permission denied

Solution:

bash
# Make binary executable
chmod +x terraform

# Or reinstall with proper permissions
sudo apt-get install --reinstall terraform

βœ… Best Practices

Best PracticesStandards
  • Keep Updated: Regularly update Terraform to latest version
  • Use Version Pinning: Pin provider versions in configuration
  • Verify Signatures: Always verify GPG signatures
  • Use Package Managers: Install via package managers when possible
  • Document Setup: Document your installation process
  • Test Installation: Test with simple configuration
  • Backup Configuration: Backup your Terraform files
  • Security: Keep credentials secure

πŸ”— Navigation

Navigation

⬅️ Previous: Terraform Architecture

πŸ“ Current Location: Terraform Installation (You are here)

➑️ Next Step: Configuration

πŸ—ΊοΈ Full Path: Introduction β†’ Architecture β†’ Installation β†’ Configuration


πŸ“š Additional Resources

ResourcesDocumentation

Terraform Installation Complete

πŸŽ‰ Excellent! Terraform Installation Complete! πŸŽ‰

➑️ Continue to Configuration