DevOps & Infra
terraform

Terraform

HCLOpen SourceCLICloud

The leading infrastructure-as-code tool. Terraform lets you define cloud infrastructure across AWS, GCP, Azure, and 1000+ providers in declarative HCL and manage it with a consistent plan/apply workflow.

License

BSL 1.1

Language

HCL

84
Trust
Strong

Why Terraform?

You want a consistent way to provision cloud resources across providers

You need to version-control your infrastructure like code

Your team needs repeatable, auditable infrastructure changes

Signal Breakdown

What drives the Trust Score

CLI downloads
10M+ / mo
Commits (90d)
421 commits
GitHub stars
43k ★
Stack Overflow
28k q's
Community
Very High
Weighted Trust Score84 / 100

Download Trend

Last 12 months

Tradeoffs & Caveats

Know before you commit

You prefer your cloud provider's native IaC (CDK, Deployment Manager)

Your team is small and Terraform's state management overhead isn't worth it

The BSL license change is a concern — consider OpenTofu instead

Pricing

Free tier & paid plans

Free tier

Open-source CLI free forever

Paid

$20/user/mo (Terraform Cloud Plus)

HCP Terraform free up to 500 resources

Often Used Together

Complementary tools that pair well with Terraform

aws

AWS

Cloud Platforms

94Excellent
View
gcp

Google Cloud Platform

Cloud Platforms

93Excellent
View
docker

Docker

DevOps & Infra

93Excellent
View
kubernetes

Kubernetes

DevOps & Infra

99Excellent
View
github-actions

GitHub Actions

DevOps & Infra

50Limited
View

Learning Resources

Docs, videos, tutorials, and courses

Get Started

Repository and installation options

View on GitHub

github.com/hashicorp/terraform

brewbrew install terraform
scriptcurl -fsSL https://releases.hashicorp.com/terraform | sh

Quick Start

Copy and adapt to get going fast

terraform {
  required_providers {
    aws = { source = "hashicorp/aws", version = "~> 5.0" }
  }
  backend "s3" {
    bucket = "my-tf-state"
    key    = "prod/terraform.tfstate"
    region = "us-east-1"
  }
}

resource "aws_s3_bucket" "app_assets" {
  bucket = "my-app-assets-${var.env}"
}

resource "aws_ecs_service" "app" {
  name          = "my-app"
  cluster       = aws_ecs_cluster.main.id
  desired_count = 2
}

# terraform init && terraform plan && terraform apply

Code Examples

Common usage patterns

Variables and outputs

Parameterize infrastructure with variables

# variables.tf
variable "env" {
  description = "Deployment environment"
  type        = string
  default     = "staging"
}

variable "instance_count" {
  type    = number
  default = 2
}

# outputs.tf
output "load_balancer_url" {
  value = aws_lb.main.dns_name
}

AWS RDS + VPC module

Create a Postgres RDS instance inside a VPC

module "vpc" {
  source  = "terraform-aws-modules/vpc/aws"
  version = "~> 5.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"]
}

resource "aws_db_instance" "postgres" {
  engine            = "postgres"
  engine_version    = "16"
  instance_class    = "db.t3.micro"
  allocated_storage = 20
  db_name           = "myapp"
  username          = var.db_user
  password          = var.db_password
  db_subnet_group_name = aws_db_subnet_group.main.name
  skip_final_snapshot  = true
}

Workspace-based environments

Use Terraform workspaces for dev/staging/prod

# Create and switch workspace
terraform workspace new staging
terraform workspace select staging

# Reference workspace in config
resource "aws_instance" "app" {
  instance_type = terraform.workspace == "prod" ? "t3.medium" : "t3.micro"
  tags = {
    Environment = terraform.workspace
  }
}

Community Notes

Real experiences from developers who've used this tool