Skip to content

Terraform: Introduction & Getting Started

Terraform is an open-source infrastructure as code (IaC) tool by HashiCorp for provisioning and managing cloud and on-premises resources declaratively.

Why Use Terraform?

  • Manage infrastructure as code across multiple providers
  • Declarative, version-controlled infrastructure
  • Large ecosystem of providers and modules

How Terraform Works

  • Uses HCL (HashiCorp Configuration Language) for configuration files
  • Providers enable support for different platforms (AWS, Azure, etc.)
  • State files track resource status

Quick Start Example

  1. Install Terraform:
    curl -fsSL https://apt.releases.hashicorp.com/gpg | sudo apt-key add -
    sudo apt-add-repository "deb [arch=amd64] https://apt.releases.hashicorp.com $(lsb_release -cs) main"
    sudo apt update && sudo apt install terraform
    terraform version
    
  2. Write a simple configuration (main.tf):
    terraform {
      required_providers {
        random = {
          source = "hashicorp/random"
        }
      }
    }
    
    provider "random" {}
    
    resource "random_pet" "name" {}
    
    output "pet_name" {
      value = random_pet.name.id
    }
    
  3. Initialize and apply:
    terraform init
    terraform apply
    

Learn More