Skip to main content

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

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:

Terminal window
# Check version
terraform --version
# Should output something like:
# Terraform v1.6.0

Basic Usage Test

Test your installation with a simple configuration:

  1. Create Test Directory - Run mkdir terraform-test && cd terraform-test to create a dedicated test workspace

  2. Create Configuration File - Create a basic Terraform configuration:

    Terminal window
    cat > main.tf << EOF
    terraform {
    required_version = ">= 1.0"
    }
    output "hello_world" {
    value = "Hello, HackerOps!"
    }
    EOF
  3. Initialize Terraform - Run terraform init to initialize the working directory

  4. Plan and Apply - Execute terraform plan to see the execution plan, then terraform 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:

  1. Set up Ansible - Complement Terraform with configuration management
  2. Configure cloud providers - Set up AWS, Azure, and DigitalOcean credentials
  3. 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