Terraform — Infrastructure as Code for Any Cloud
Terraform codifies cloud APIs into declarative configuration files. Provision and manage AWS, Azure, GCP, Kubernetes, and 3000+ providers with version-controlled infrastructure.
Ready-to-run agent install
This asset can be installed after the agent chooses its runtime, checks the plan, and runs the matching command.
npx -y tokrepo@latest install d31a13f3-3530-11f1-9bc6-00163e2b0d79 --target codexRun after dry-run confirms the install plan.
What it is
Terraform is an open-source infrastructure-as-code tool by HashiCorp. You write declarative configuration files (HCL) that describe your desired infrastructure state, and Terraform figures out what API calls to make to reach that state. It supports 3000+ providers including AWS, Azure, GCP, Kubernetes, Cloudflare, and Datadog.
Terraform targets DevOps engineers, platform teams, and any developer who provisions cloud resources. Whether you manage a single VPS or a multi-cloud enterprise environment, Terraform provides a consistent workflow: write, plan, apply.
How it saves time or tokens
Without Terraform, provisioning infrastructure means clicking through cloud consoles or writing imperative scripts that break when APIs change. Terraform replaces that with a declarative approach: you describe what you want, not how to get there. The plan step shows exactly what will change before you apply, eliminating surprise modifications. State tracking means Terraform knows what already exists and only modifies the delta.
How to use
- Install Terraform:
brew install terraform # macOS
apt install terraform # Debian/Ubuntu
- Write a configuration file defining your resources.
- Run the standard workflow:
terraform init # Download providers
terraform plan # Preview changes
terraform apply # Apply changes
terraform destroy # Tear down when done
Example
# main.tf -- Create an AWS S3 bucket
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 5.0"
}
}
}
provider "aws" {
region = "us-east-1"
}
resource "aws_s3_bucket" "data" {
bucket = "my-app-data-bucket"
tags = {
Environment = "production"
ManagedBy = "terraform"
}
}
Run terraform apply and Terraform creates the S3 bucket. Run it again and nothing changes because the state already matches.
Related on TokRepo
- DevOps Tools -- Infrastructure automation and deployment tools
- Automation Tools -- Tools for automating repetitive infrastructure tasks
Common pitfalls
- Storing Terraform state locally works for learning but breaks in teams. Use remote state backends (S3 + DynamoDB, Terraform Cloud, or GCS) for shared environments.
- Importing existing resources into Terraform state requires
terraform importand manually writing the matching HCL. It is tedious but necessary to avoid duplicates. - Provider version pinning is important. An unpinned provider can upgrade and introduce breaking changes on your next
terraform init.
Frequently Asked Questions
Terraform CLI is open source under the BSL license (formerly MPL 2.0). It is free to download and use. HashiCorp offers Terraform Cloud with a free tier for small teams and paid plans for larger organizations.
Terraform uses its own HCL language for configuration. Pulumi lets you write infrastructure code in general-purpose languages like Python, TypeScript, or Go. Both achieve infrastructure-as-code but differ in language approach and ecosystem.
Yes. The Kubernetes provider lets Terraform manage namespaces, deployments, services, and other K8s resources. However, many teams prefer Helm or Kustomize for in-cluster resources and use Terraform for the underlying cloud infrastructure.
Terraform state files can contain sensitive values in plain text. Use remote backends with encryption, mark variables as sensitive, and integrate with secret managers like Vault or AWS Secrets Manager to protect credentials.
Terraform detects drift on the next plan or apply. It compares the real infrastructure state with the desired configuration and shows you what changed. You can then decide to reconcile by applying the Terraform configuration or updating it to match.
Citations (3)
- Terraform GitHub— Infrastructure as code with 3000+ providers
- Terraform Documentation— HashiCorp Configuration Language and workflow
- Terraform Registry— Terraform provider registry
Related on TokRepo
Discussion
Related Assets
Pulumi — Infrastructure as Code in Any Programming Language
Pulumi is infrastructure as code using general-purpose languages: TypeScript, Python, Go, C#, Java, YAML. Unlike Terraform HCL, Pulumi lets you use loops, functions, classes, and real package ecosystems to describe cloud infra.
Terraformer — Reverse-Engineer Existing Cloud Infrastructure to Terraform
Terraformer is a CLI tool by Google that reads live cloud resources from AWS, GCP, Azure, and 30+ other providers and generates corresponding Terraform HCL files and state, enabling infrastructure-as-code adoption on brownfield environments.
tfsec — Static Security Scanner for Terraform Code
Catch security misconfigurations in Terraform before they reach production. tfsec scans HCL files for hundreds of cloud security rules across AWS, Azure, and GCP with zero configuration.
Infracost — Cloud Cost Estimates for Infrastructure as Code
See cloud cost breakdowns before you deploy. Infracost integrates with Terraform and CI/CD to show how every change impacts your bill.