You are viewing a free preview of this lesson.
Subscribe to unlock all 10 lessons in this course and every other course on LearningBro.
Terraform is an open-source Infrastructure as Code (IaC) tool created by HashiCorp. It lets you define, provision, and manage cloud infrastructure using a declarative configuration language called HCL (HashiCorp Configuration Language). With Terraform, your infrastructure is described in code, version-controlled, and reproducible.
Infrastructure as Code (IaC) is the practice of managing infrastructure — servers, networks, databases, load balancers — through machine-readable configuration files rather than manual processes.
depends_on for modules and provider requirements| Approach | Description | Example Tools |
|---|---|---|
| Declarative | You describe the desired end state; the tool figures out how to get there | Terraform, CloudFormation, Pulumi (YAML) |
| Imperative | You describe the exact steps to execute in order | Bash scripts, Ansible playbooks, AWS CLI |
Terraform is declarative — you describe what you want, not how to build it:
resource "aws_instance" "web" {
ami = "ami-0c55b159cbfafe1f0"
instance_type = "t3.micro"
}
Terraform determines the actions required to reach this desired state (create, update, or destroy resources).
Terraform follows a simple workflow:
Write (.tf files) → Plan (preview changes) → Apply (make changes)
You write configuration files (.tf) that describe your desired infrastructure.
terraform plan compares your configuration with the current state and shows what changes will be made — without making them.
terraform apply executes the plan and provisions or modifies the infrastructure.
terraform destroy removes all resources defined in the configuration.
| Feature | Terraform | AWS CloudFormation | Azure Bicep | Pulumi |
|---|---|---|---|---|
| Multi-cloud | Yes (any provider) | AWS only | Azure only | Yes |
| Language | HCL | JSON / YAML | Bicep DSL | Python, TypeScript, Go, etc. |
| State management | Explicit state file | Managed by AWS | Managed by Azure | Explicit state file |
| Open source | BSL (OpenTofu is MPL) | No | No | Yes |
| Provider ecosystem | 4,000+ providers | AWS services only | Azure services only | Growing |
Terraform's key advantage is its multi-cloud, provider-agnostic approach — one tool and one language for AWS, Azure, GCP, Kubernetes, GitHub, Datadog, and thousands more.
| Concept | Description |
|---|---|
| Provider | A plugin that interacts with an API (e.g., AWS, Azure, GCP) |
| Resource | A single piece of infrastructure (e.g., a VM, a DNS record) |
| Data source | A read-only reference to existing infrastructure |
| State | A file that maps your configuration to real-world resources |
| Module | A reusable, self-contained package of Terraform configuration |
| Variable | An input parameter for your configuration |
| Output | A value exported from your configuration |
Terraform is ideal when you need to:
Tip: Even if you only use a single cloud provider, Terraform's mature ecosystem, extensive documentation, and large community make it a strong choice for IaC.
Terraform is a declarative, multi-cloud Infrastructure as Code tool that lets you define infrastructure in HCL configuration files. It follows a write-plan-apply workflow, maintains state to track resources, and supports thousands of providers. In the following lessons, we will install Terraform, learn HCL syntax, and build real infrastructure step by step.