DEV Community

Alex Spinov
Alex Spinov

Posted on

Terraform Has a Free API — Infrastructure as Code That Actually Works

Terraform: The Industry Standard for Infrastructure as Code

Terraform by HashiCorp manages cloud infrastructure through code. AWS, Azure, GCP, Kubernetes, DNS, monitoring — 4000+ providers, one tool, one language (HCL).

Why Terraform

  • Declarative — describe what you want, not how to get there
  • Plan before apply — see changes before they happen
  • State management — tracks real infrastructure
  • Modules — reusable infrastructure components
  • 4000+ providers — literally everything

The Free CLI API

# Initialize project
terraform init

# Preview changes
terraform plan

# Apply changes
terraform apply -auto-approve

# Show current state
terraform show

# Destroy infrastructure
terraform destroy

# Import existing resource
terraform import aws_instance.web i-1234567890

# Format code
terraform fmt

# Validate config
terraform validate
Enter fullscreen mode Exit fullscreen mode

HCL Examples

# AWS EC2 instance
resource "aws_instance" "web" {
  ami           = "ami-0c55b159cbfafe1f0"
  instance_type = "t3.micro"

  tags = {
    Name = "web-server"
    Env  = "production"
  }
}

# Kubernetes deployment
resource "kubernetes_deployment" "app" {
  metadata {
    name = "my-app"
  }
  spec {
    replicas = 3
    selector {
      match_labels = { app = "my-app" }
    }
    template {
      metadata {
        labels = { app = "my-app" }
      }
      spec {
        container {
          image = "my-app:v1"
          name  = "my-app"
          port {
            container_port = 8080
          }
        }
      }
    }
  }
}

# Variables
variable "region" {
  default = "us-east-1"
}

# Outputs
output "instance_ip" {
  value = aws_instance.web.public_ip
}
Enter fullscreen mode Exit fullscreen mode

Modules

module "vpc" {
  source  = "terraform-aws-modules/vpc/aws"
  version = "5.0.0"

  name = "my-vpc"
  cidr = "10.0.0.0/16"
  azs  = ["us-east-1a", "us-east-1b"]
  private_subnets = ["10.0.1.0/24", "10.0.2.0/24"]
  public_subnets  = ["10.0.101.0/24", "10.0.102.0/24"]
}
Enter fullscreen mode Exit fullscreen mode

Real-World Use Case

A startup managed AWS manually — 3 engineers, 2 days to set up a new environment. Terraform modules: one command creates VPC + EKS + RDS + monitoring. New environment in 15 minutes. Infrastructure changes reviewed in PR like code.

Quick Start

brew install terraform
terraform init
terraform plan
Enter fullscreen mode Exit fullscreen mode

Resources


Need automated infrastructure data? Check out my tools on Apify or email spinov001@gmail.com for custom IaC solutions.

Top comments (0)