Terraform Installation
Windows
Installation:
- Download Terraform: Visit Terraform's Download Page and download the Windows version (a .zip file).
- Extract the Executable: Extract the
terraform.exefile from the downloaded .zip file to a folder, e.g.,C:\Terraform. - 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 -vto check the installation.
Note:
- Ensure you have administrative privileges during installation.
Ubuntu/Linux
Installation:
- Update and Install:
- Open Terminal and run
sudo apt-get update && sudo apt-get install -y gnupg software-properties-common curl.
- Open Terminal and run
- Add the HashiCorp GPG key:
- Run
curl -fsSL https://apt.releases.hashicorp.com/gpg | sudo apt-key add -.
- Run
- Add the official HashiCorp Linux repository:
- Run
sudo apt-add-repository "deb [arch=amd64] https://apt.releases.hashicorp.com $(lsb_release -cs) main".
- Run
- Install Terraform:
- Run
sudo apt-get update && sudo apt-get install terraform.
- Run
Verification:
- Run
terraform -vin Terminal.
Note:
- Use
sudofor administrative privileges.
macOS
Installation (using Homebrew):
- Install Homebrew: If not installed, open Terminal and run
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)". - Install Terraform: Run
brew tap hashicorp/tapfollowed bybrew install hashicorp/tap/terraform.
Verification:
- Run
terraform -vin Terminal.
Note:
- Homebrew simplifies the installation process on macOS.
Configuration (Common for All OS):
- Create a Terraform Directory: Choose or create a new directory for your Terraform project.
- Initialize Terraform:
- Navigate to your Terraform directory in the terminal.
- Run
terraform initto 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 applyto apply the configuration.
Troubleshooting:
- If you encounter any issues, refer to the Terraform documentation or community forums for troubleshooting tips.