Mahmoud Al-HabashOpen to new projects
  • WorkWork
  • ServicesServices
  • LabLab
  • WritingWriting
  • ContactContact
Amman--:--عربي
Writing/DevOps & cloud

Terraform: Infrastructure as Code for Cloud Resources

Manage cloud infrastructure declaratively with Terraform — provision servers, databases, and networks with version-controlled code.

22 February 20261 min readDevOps & cloudاقرأ بالعربية

On this page

  1. Why Infrastructure as Code?
  2. Basic AWS Example
  3. Terraform Workflow
  4. State Management

Terraform by HashiCorp is the leading Infrastructure as Code (IaC) tool, supporting over 3,000 providers including AWS, Azure, GCP, and DigitalOcean. Instead of clicking through cloud consoles, you declare your desired infrastructure in HCL files.

Why Infrastructure as Code?

  • Reproducibility — identical staging and production environments
  • Version control — review infrastructure changes in pull requests
  • Automation — no manual clicking, no missed steps
  • Documentation — your code IS the documentation

Basic AWS Example

hcl
terraform {
  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = "~> 5.0"
    }
  }
}

provider "aws" {
  region = "us-east-1"
}

resource "aws_instance" "web" {
  ami           = "ami-0c55b159cbfafe1f0"
  instance_type = "t3.micro"
  tags = {
    Name        = "web-server"
    Environment = "production"
  }
}

resource "aws_db_instance" "database" {
  allocated_storage    = 20
  engine               = "mysql"
  engine_version       = "8.0"
  instance_class       = "db.t3.micro"
  db_name              = "myapp"
  username             = var.db_username
  password             = var.db_password
  skip_final_snapshot  = true
}

Terraform Workflow

bash
terraform init    # Initialize providers
terraform plan    # Preview changes
terraform apply   # Apply changes
terraform destroy # Destroy all resources

State Management

Terraform tracks resources in a state file. For teams, store state remotely:

hcl
terraform {
  backend "s3" {
    bucket = "my-terraform-state"
    key    = "prod/terraform.tfstate"
    region = "us-east-1"
  }
}

Terraform turns infrastructure from a manual process into a code-review-friendly, automated workflow.

All articles

Keep reading

  • Docker for Developers: From Zero to Containerized Applications28 February 20261 min read
  • CI/CD Pipelines with GitHub Actions: Automate Everything22 February 20261 min read
  • Clean Code Principles: Write Code That Humans Can Read22 February 20261 min read