← Back to Blog
DEVOPS

What Is Infrastructure as Code? Terraform & Automation Guide

F. Çağrı BilgehanFebruary 13, 202610 min read
iacterraforminfrastructureautomation

What Is Infrastructure as Code (IaC)?

Are you setting up servers manually? Is every environment configured differently? Infrastructure as Code lets you define your infrastructure in code files, version-control it, and deploy it repeatably with a single command.

What Is IaC?

Infrastructure as Code is the practice of managing servers, networks, and databases through code files rather than manual processes. Instead of clicking through consoles, you write declarative code.

Traditional: Console → Click → Configure → "I forgot how I did it"
IaC:         Write code → Git push → CI/CD → Automated setup

Why IaC?

  1. Repeatability — Deploy identical infrastructure across dev, staging, and production
  2. Version control — Track infrastructure changes with Git
  3. Speed — New environments in minutes, not days
  4. Consistency — Eliminate "snowflake server" drift

Declarative vs Imperative

| Approach | Description | Examples | |----------|-------------|---------| | Declarative | Define "what I want" | Terraform, CloudFormation | | Imperative | Write "how to do it" | Bash scripts, Ansible |

Terraform Example

provider "google" {
  project = "my-project"
  region  = "europe-west1"
}

resource "google_cloud_run_service" "app" {
  name     = "my-app"
  location = "europe-west1"

  template {
    spec {
      containers {
        image = "gcr.io/my-project/my-app:latest"
        resources {
          limits = {
            memory = "512Mi"
            cpu    = "1"
          }
        }
      }
    }
  }
}

output "url" {
  value = google_cloud_run_service.app.status[0].url
}
terraform init      # Download providers
terraform plan      # Preview changes
terraform apply     # Apply changes
terraform destroy   # Tear down everything

IaC Tools Compared

| Tool | Language | Cloud | Approach | |------|----------|-------|----------| | Terraform | HCL | Multi-cloud | Declarative | | Pulumi | TypeScript/Python | Multi-cloud | Programmatic | | CloudFormation | YAML/JSON | AWS only | Declarative | | Ansible | YAML | Any | Imperative | | CDK | TypeScript/Python | AWS/GCP | Programmatic |

Best Practices

  1. Use remote state — Local state files don't work for teams
  2. Create modules — Modularize repeating infrastructure
  3. Separate environments — Separate state for dev/staging/prod
  4. Review plan output — Always read terraform plan before applying
  5. Detect drift — Identify manual changes with regular plans
  6. Manage secrets properly — Use Vault or Secret Manager, not state files

Conclusion

IaC is a cornerstone of modern DevOps. Managing infrastructure as code brings repeatability, consistency, and speed. Even small projects benefit — you'll see the difference on your next deployment.

Learn IaC and DevOps practices on the LabLudus platform.

Related Posts

IaC Nedir?

Infrastructure as Code nedir ve neden kullanılır?

DevOps Nedir?

DevOps nedir ve neden önemlidir?