Terraform
Infrastructure as code tool that enables safe, efficient provisioning and management of infrastructure across cloud providers using declarative configuration.
What is Terraform?
Terraform is an open-source Infrastructure as Code (IaC) tool created by HashiCorp that allows you to define, provision, and manage infrastructure using human-readable configuration files. It supports multiple cloud providers including AWS, Google Cloud, Azure, and many others, enabling a unified approach to infrastructure management across different platforms.
Key Components
- Configuration Language (HCL): HashiCorp Configuration Language for declaring infrastructure resources
- State Management: Tracking infrastructure state to detect changes and manage lifecycle
- Providers: Plugins that allow Terraform to interact with cloud platforms and services
- Modules: Reusable packages of Terraform configurations for common infrastructure patterns
- Remote State: Centralized state storage for team collaboration and consistency
Typical Use Cases
-
Cloud Infrastructure Provisioning
Automated deployment of compute, storage, networking resources across cloud providers.
-
Multi-Environment Management
Consistent infrastructure across development, staging, and production environments.
-
Infrastructure as Code Automation
Version-controlled, repeatable infrastructure deployments with GitOps workflows.
-
Multi-Cloud Orchestration
Unified management of resources across multiple cloud providers simultaneously.
Mental Model
Think of Terraform as a blueprint language for infrastructure. You describe what you want ("I want 3 servers, a database, a load balancer"), and Terraform figures out how to build it and keep it in sync. Change your blueprint, and Terraform intelligently updates only what changed.
Architecture Overview
[HCL Configuration Files]
↓
[Terraform CLI]
├─ Parse Configuration
├─ Plan Changes (terraform plan)
└─ Apply Changes (terraform apply)
↓
[Terraform State File]
↓
[Provider Plugins] ← → [Cloud APIs]
├─ AWS Provider
├─ GCP Provider
└─ Azure Provider
↓
[Cloud Resources]
Terraform reads HCL configs, consults state to detect changes, and communicates with cloud provider APIs through plugins. The state file ensures idempotency—running apply twice produces the same result.
Key Concepts Glossary
- HCL (HashiCorp Configuration Language): Declarative language for defining infrastructure
- State: Current infrastructure state tracked locally or remotely
- Provider: Plugin enabling Terraform to interact with cloud platforms
- Resource: Cloud infrastructure unit (server, database, network, etc.)
- Module: Reusable package of configurations for common patterns
When to Use Terraform
Choose Terraform if you need:
- Infrastructure as code across multiple cloud providers
- Versioned, auditable infrastructure changes through Git
- Reproducible, consistent infrastructure deployments
Consider alternatives if:
- You only use a single cloud provider (cloud-native tools may suffice)
- Your infrastructure is simple and rarely changes
Getting Started
Download and install Terraform, then initialize a project:
terraform version
cd my-infrastructure && terraform init
Resources for Further Learning
- Official Documentation - Complete reference and tutorials
- GitHub Repository - Source code and issue tracking
- Terraform Registry - Modules and providers
- Terraform Cloud - Managed state and team collaboration