Initial Setup

Get Terraform installed and create your first infrastructure. This guide walks you through installation and provisioning your first resources.

🎯 What You’ll Accomplish

By the end of this tutorial, you’ll have:

  • βœ… Terraform installed and verified
  • βœ… Your first Terraform configuration
  • βœ… Infrastructure provisioned and destroyed

πŸ“‹ Prerequisites

  • Windows, macOS, or Linux
  • Cloud account (AWS, Azure, or GCP) for deployment examples
  • Basic command line familiarity

πŸ’Ύ Step 1: Install Terraform

macOS

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

Linux

wget -O- https://apt.releases.hashicorp.com/gpg | sudo gpg --dearmor -o /usr/share/keyrings/hashicorp-archive-keyring.gpg
echo "deb [signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] https://apt.releases.hashicorp.com $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/hashicorp.list
sudo apt update && sudo apt install terraform

Windows

choco install terraform

Verify Installation

terraform --version

πŸš€ Step 2: Create Your First Configuration

Create main.tf:

terraform {
  required_providers {
    local = {
      source  = "hashicorp/local"
      version = "~> 2.0"
    }
  }
}

resource "local_file" "hello" {
  content  = "Hello, Terraform!"
  filename = "${path.module}/hello.txt"
}

output "file_content" {
  value = local_file.hello.content
}

πŸ“Š Step 3: Initialize and Apply

terraform init
terraform plan
terraform apply

Type yes when prompted.

Check the created file:

cat hello.txt

🧹 Step 4: Destroy Infrastructure

terraform destroy

Type yes when prompted.

βœ… Verification Checklist

Before moving forward, verify:

  • terraform --version shows Terraform installed
  • terraform init completes successfully
  • terraform apply creates resources
  • terraform destroy removes resources

πŸŽ‰ You’re Done!

You’ve successfully installed Terraform and provisioned your first infrastructure.

πŸ“š What’s Next?

Quick learner: Terraform Quick Start

Code-first learner: Terraform By Example

Last updated