Docs / Cloud & DevOps / Infrastructure as Code with Terraform Basics

Infrastructure as Code with Terraform Basics

By Admin · Feb 25, 2026 · Updated Apr 23, 2026 · 27 views · 1 min read

What is Terraform?

Terraform by HashiCorp lets you define infrastructure in code files. Instead of clicking through web dashboards, you write declarative configuration that can be version-controlled, reviewed, and reproduced.

Installation

wget https://releases.hashicorp.com/terraform/1.7.0/terraform_1.7.0_linux_amd64.zip
unzip terraform_*.zip
sudo mv terraform /usr/local/bin/
terraform version

Basic Structure

A Terraform project typically has these files:

  • main.tf — resource definitions
  • variables.tf — input variables
  • outputs.tf — output values
  • terraform.tfvars — variable values (don't commit secrets)

Example Configuration

# main.tf
terraform {
  required_providers {
    local = {
      source = "hashicorp/local"
    }
  }
}

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

Workflow

# Initialize (download providers)
terraform init

# Preview changes
terraform plan

# Apply changes
terraform apply

# Destroy resources
terraform destroy

State Management

Terraform tracks resource state in terraform.tfstate. For team use, store state remotely:

  • AWS S3 + DynamoDB for locking
  • Terraform Cloud (free tier available)
  • GitLab-managed state

Key Concepts

  • Resources — infrastructure objects (servers, networks, DNS records)
  • Providers — plugins for each cloud/service
  • Modules — reusable groups of resources
  • State — Terraform's record of what it manages

Was this article helpful?