Skip to main content

Terraform Installation

Windows

Installation:

  1. Download Terraform: Visit Terraform's Download Page and download the Windows version (a .zip file).
  2. Extract the Executable: Extract the terraform.exe file from the downloaded .zip file to a folder, e.g., C:\Terraform.
  3. Update System Path:
    • Right-click on 'This PC' > 'Properties' > 'Advanced system settings'.
    • Click 'Environment Variables', then under 'System Variables', find and select 'Path', and click 'Edit'.
    • Add the path to the Terraform folder (e.g., C:\Terraform).
    • Click 'OK' to close all dialogs.

Verification:

  • Open Command Prompt and run terraform -v to check the installation.

Note:

  • Ensure you have administrative privileges during installation.

Ubuntu/Linux

Installation:

  1. Update and Install:
    • Open Terminal and run sudo apt-get update && sudo apt-get install -y gnupg software-properties-common curl.
  2. Add the HashiCorp GPG key:
    • Run curl -fsSL https://apt.releases.hashicorp.com/gpg | sudo apt-key add -.
  3. Add the official HashiCorp Linux repository:
    • Run sudo apt-add-repository "deb [arch=amd64] https://apt.releases.hashicorp.com $(lsb_release -cs) main".
  4. Install Terraform:
    • Run sudo apt-get update && sudo apt-get install terraform.

Verification:

  • Run terraform -v in Terminal.

Note:

  • Use sudo for administrative privileges.

macOS

Installation (using Homebrew):

  1. Install Homebrew: If not installed, open Terminal and run /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)".
  2. Install Terraform: Run brew tap hashicorp/tap followed by brew install hashicorp/tap/terraform.

Verification:

  • Run terraform -v in Terminal.

Note:

  • Homebrew simplifies the installation process on macOS.

Configuration (Common for All OS):

  1. Create a Terraform Directory: Choose or create a new directory for your Terraform project.
  2. Initialize Terraform:
    • Navigate to your Terraform directory in the terminal.
    • Run terraform init to initialize the directory.

Running Your First Terraform Command:

  • Create a basic Terraform configuration file (e.g., main.tf) in your directory.
  • Write a simple configuration, for example:
    terraform {
    required_providers {
    aws = {
    source = "hashicorp/aws"
    version = "~> 3.0"
    }
    }
    }

    provider "aws" {
    region = "us-west-2"
    }
  • Run terraform apply to apply the configuration.

Troubleshooting: