DEV Community

Alex Spinov
Alex Spinov

Posted on

Terraform Has a Free API: Infrastructure as Code That Manages Everything

Why Terraform

Terraform by HashiCorp is THE infrastructure-as-code tool. Define cloud resources in HCL, plan changes before applying, and track state. Supports 3,000+ providers — AWS, GCP, Azure, Kubernetes, GitHub, and more.

Install

brew install terraform
Enter fullscreen mode Exit fullscreen mode

Create AWS Resources

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_s3_bucket" "data" {
  bucket = "my-data-bucket"
}
Enter fullscreen mode Exit fullscreen mode

Workflow

terraform init      # Download providers
terraform plan      # Preview changes
terraform apply     # Apply changes
terraform destroy   # Tear down
Enter fullscreen mode Exit fullscreen mode

Modules (Reusable Components)

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

  name = "production"
  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"]

  enable_nat_gateway = true
}
Enter fullscreen mode Exit fullscreen mode

Variables and Outputs

variable "environment" {
  type    = string
  default = "dev"
}

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

Key Features

  • 3,000+ providers — manage any cloud or service
  • Plan before apply — see changes before making them
  • State management — tracks real infrastructure
  • Modules — reusable, shareable components
  • Workspaces — multiple environments from one config
  • Import — bring existing resources under management

Resources


Need to extract cloud configs, infrastructure data, or provider APIs? Check out my Apify tools or email spinov001@gmail.com for custom solutions.

Top comments (0)