Terraform Installation
Terraform Installation
Terraform is HashiCorpβs Infrastructure as Code (IaC) tool that youβll use throughout HackerOps labs to provision and manage cloud resources.
Info
Pre-configured VMs: Terraform is already installed on the HackerOps Ubuntu VMs. Skip this guide if using the pre-configured environment.
What is Terraform?
Terraform allows you to:
- Define infrastructure as code using HCL (HashiCorp Configuration Language)
- Manage multiple cloud providers (AWS, Azure, DigitalOcean) from one tool
- Version control your infrastructure like any other code
- Plan and preview changes before applying them
Official Documentation: Terraform Installation Guide
Installation Methods
Using HashiCorp Repository (Recommended):
# Update system and install prerequisitessudo apt-get update && sudo apt-get install -y gnupg software-properties-common curl
# Add HashiCorp GPG keycurl -fsSL https://apt.releases.hashicorp.com/gpg | sudo apt-key add -
# Add HashiCorp repositorysudo apt-add-repository "deb [arch=amd64] https://apt.releases.hashicorp.com $(lsb_release -cs) main"
# Install Terraformsudo apt-get update && sudo apt-get install terraform
# Verify installationterraform --version
Alternative - Direct Download:
- Visit Terraform Downloads
- Download the Linux binary
- Unzip and move to
/usr/local/bin/
- Make executable:
chmod +x /usr/local/bin/terraform
Using Homebrew (Recommended):
# Install HashiCorp tapbrew tap hashicorp/tap
# Install Terraformbrew install hashicorp/tap/terraform
# Verify installationterraform --version
Alternative - Direct Download:
- Visit Terraform Downloads
- Download the macOS binary
- Unzip and move to
/usr/local/bin/
- Make executable:
chmod +x /usr/local/bin/terraform
Using Chocolatey (Recommended):
# Install Terraformchoco install terraform
# Verify installationterraform --version
Alternative - Direct Download:
- Visit Terraform Downloads
- Download Windows binary
- Extract to a folder (e.g.,
C:\terraform
) - Add the folder to your system PATH
Alternative - Using Winget:
# Install via Windows Package Managerwinget install Hashicorp.Terraform
Caution
Note: Package managers may not always have the latest version. For the most recent release, download directly from HashiCorpβs website.
Verify Installation
After installation, verify Terraform is working:
# Check versionterraform --version
# Should output something like:# Terraform v1.6.0
Basic Usage Test
Test your installation with a simple configuration:
-
Create Test Directory - Run
mkdir terraform-test && cd terraform-test
to create a dedicated test workspace -
Create Configuration File - Create a basic Terraform configuration:
Terminal window cat > main.tf << EOFterraform {required_version = ">= 1.0"}output "hello_world" {value = "Hello, HackerOps!"}EOF -
Initialize Terraform - Run
terraform init
to initialize the working directory -
Plan and Apply - Execute
terraform plan
to see the execution plan, thenterraform apply
and type βyesβ when prompted
Tip
Success! If you see βHello, HackerOps!β in the output, Terraform is properly installed and ready for the labs.
Next Steps
With Terraform installed:
- Set up Ansible - Complement Terraform with configuration management
- Configure cloud providers - Set up AWS, Azure, and DigitalOcean credentials
- Start Lab 1 - Deploy your first infrastructure
Troubleshooting
Command not found:
- Restart your terminal after installation
- Verify Terraform is in your system PATH
- Try reinstalling using a different method
Permission errors:
- Use
sudo
for Linux package installations - Run PowerShell as Administrator on Windows
- Check file permissions:
chmod +x terraform
if installing manually