Terraform
An open-source infrastructure as code tool that allows you to build, change, and version cloud resources safely.
Detailed Explanation
Terraform uses a declarative language (HCL) to define the desired state of your infrastructure. It supports hundreds of providers (AWS, Google Cloud, Azure, etc.) and handles the complex dependency mapping required to provision resources in the correct order. It is the most popular tool for multi-cloud infrastructure management.
Quick Summary
Terraform is the most widely used Infrastructure as Code tool, declare resources in HCL, run `plan` to preview, `apply` to make it so. It works across nearly every cloud and SaaS via a plugin model called providers.
Key Takeaways
- HCL is declarative: you describe the resources you want, not the API calls to create them.
- Terraform tracks reality in a state file; commands diff state against config to compute the change set.
- Modules package reusable groups of resources with inputs and outputs, the basic unit of code sharing.
- Workspaces and remote backends (S3 + DynamoDB lock, Terraform Cloud) enable safe team collaboration.
- OpenTofu is a fork of Terraform that emerged after the 2023 license change; both are largely compatible today.
When to use it
- Provisioning multi-cloud or multi-SaaS infrastructure with a single workflow.
- Bootstrapping new AWS/GCP/Azure accounts with VPCs, IAM, and baseline services.
- Managing GitHub repos, Cloudflare DNS, Datadog monitors, and PagerDuty schedules as code.
- Building self-service platforms where developers consume curated Terraform modules.
Common Mistakes
- Storing state files locally on a laptop, when the laptop dies, so does the ability to manage the infra.
- One mega-state covering everything; small mistakes risk destroying the whole environment.
- Skipping `terraform plan` review in CI and letting `apply` run on every merge unsupervised.
- Importing existing resources sloppily, ending up with config that does not match reality and noisy diffs forever.
Terraform, Frequently Asked
Terraform vs. OpenTofu, which should I pick?
For new projects, OpenTofu is the open-source-licensed fork and is largely a drop-in for current Terraform features. Terraform itself remains widely supported by HashiCorp and the ecosystem. Pick OpenTofu if licensing matters; otherwise either is safe.
How do I share state across a team?
Use a remote backend with locking, S3 + DynamoDB on AWS, GCS on GCP, or Terraform Cloud/Spacelift/Atlantis as managed services. Local state is fine for solo experiments and nothing else.
Can Terraform manage Kubernetes resources?
Yes, via the kubernetes and helm providers, but most teams prefer dedicated GitOps tools (Argo CD, Flux) for K8s manifests because they reconcile continuously, while Terraform only acts on apply.