Skip to content

You are viewing a free preview of this lesson.

Subscribe to unlock all 10 lessons in this course and every other course on LearningBro.

What is Terraform

What is Terraform

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.


What is Infrastructure as Code?

Infrastructure as Code (IaC) is the practice of managing infrastructure — servers, networks, databases, load balancers — through machine-readable configuration files rather than manual processes.

Benefits of IaC

  • Consistency — the same configuration always produces the same result
  • Version control — track changes over time with Git
  • Automation — provision and update infrastructure with a single command
  • Collaboration — teams can review infrastructure changes like code
  • Documentation — the code itself describes the infrastructure

A Brief History

  • 2014 — Mitchell Hashimoto releases Terraform 0.1 as an open-source project
  • 2017 — Terraform 0.10 introduces provider/provisioner separation
  • 2019 — Terraform 0.12 brings a major HCL rewrite with first-class expressions
  • 2020 — Terraform 0.13 adds depends_on for modules and provider requirements
  • 2021 — Terraform 1.0 released — the first major stable release with compatibility promises
  • 2023 — HashiCorp changes Terraform's licence from MPL to BSL (Business Source Licence)
  • 2024 — OpenTofu forks Terraform under the Linux Foundation as an MPL-licensed alternative
  • Today — Terraform remains the most widely adopted IaC tool with thousands of providers

Declarative vs Imperative

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).


How Terraform Works

Terraform follows a simple workflow:

Write (.tf files)  →  Plan (preview changes)  →  Apply (make changes)

1. Write

You write configuration files (.tf) that describe your desired infrastructure.

2. Plan

terraform plan compares your configuration with the current state and shows what changes will be made — without making them.

3. Apply

terraform apply executes the plan and provisions or modifies the infrastructure.

4. Destroy

terraform destroy removes all resources defined in the configuration.


Terraform vs Other IaC Tools

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.


Core Concepts at a Glance

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

When to Use Terraform

Terraform is ideal when you need to:

  • Manage infrastructure across multiple cloud providers
  • Version-control your infrastructure alongside application code
  • Automate provisioning in CI/CD pipelines
  • Create reusable infrastructure modules for your organisation
  • Maintain a clear audit trail of infrastructure changes

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.


Summary

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.