Skip to content
5 min read·Lesson 2 of 10

Terraform Overview

Understand how Terraform works, its architecture, how it compares to other IaC tools, and the differences between Terraform and OpenTofu.

Terraform, created by HashiCorp and open-sourced in 2014, is the most widely adopted cloud infrastructure provisioning tool. It uses a declarative language (HCL), a provider plugin model, and a state file to manage infrastructure across hundreds of cloud platforms and services.

How Terraform Works

The Terraform workflow has four phases:

  1. Write: Define infrastructure in .tf files using HCL (HashiCorp Configuration Language)
  2. Init: terraform init downloads providers and initialises the backend
  3. Plan: terraform plan compares desired state (code) to current state (state file) and shows what will change
  4. Apply: terraform apply executes the changes — creates, updates, or destroys resources

Providers

Terraform uses a provider plugin model. Providers are plugins that define the resources and data sources for a specific platform:

  • hashicorp/aws — 1,000+ AWS resources
  • hashicorp/google — GCP resources
  • hashicorp/azurerm — Azure resources
  • hashicorp/kubernetes — Kubernetes resources
  • hashicorp/helm — Helm releases
  • hashicorp/github — GitHub repositories, teams, webhooks
  • ...1,000+ providers on the Terraform Registry

Providers are downloaded from the Terraform Registry during terraform init.

Terraform State

Terraform maintains a state file (terraform.tfstate) that maps your configuration to real-world resources. State is how Terraform knows:

  • Which resources it manages (vs resources that exist but weren't created by Terraform)
  • What the current configuration of those resources is
  • What needs to change when you run plan

By default, state is stored locally. For teams, use a remote backend (S3, Terraform Cloud) to share state and enable locking.

Terraform vs Other IaC Tools

FeatureTerraformCloudFormationPulumiAnsible
Multi-cloudYesAWS onlyYesYes
LanguageHCLYAML/JSONTS/Python/GoYAML
State managementYes (state file)Managed by AWSYesNo (idempotent tasks)
ProvisioningExcellentExcellent (AWS)ExcellentGood
Config managementLimitedNoLimitedExcellent
Learning curveLowMediumDepends on languageLow

Terraform vs OpenTofu

In August 2023, HashiCorp changed Terraform's licence from MPL 2.0 (open source) to BSL (Business Source Licence), which restricts commercial use. In response, the community forked Terraform as OpenTofu, donated to the Linux Foundation, and maintained as a truly open-source alternative.

  • OpenTofu 1.x is compatible with Terraform 1.5.x syntax
  • Both tools use the same HCL syntax and provider ecosystem
  • OpenTofu is the tool most open-source projects are migrating to

For learning purposes, HCL skills transfer directly between Terraform and OpenTofu.

Terraform CLI Commands Overview

terraform init          # initialise directory, download providers
terraform validate      # check syntax and configuration
terraform fmt           # format code to canonical style
terraform plan          # preview changes
terraform apply         # apply changes
terraform destroy       # destroy all managed resources
terraform output        # show output values
terraform state list    # list resources in state
terraform import        # import existing resource into state
terraform workspace     # manage named workspaces

Next: HCL — the language you write Terraform configurations in.

Key Takeaways

  • Terraform uses a provider plugin model — each cloud or service has a provider that Terraform downloads.
  • The Terraform workflow is: write → init → plan → apply. Plan shows changes before they happen.
  • Terraform state tracks the real-world resources it manages — it is the source of truth for Terraform.
  • OpenTofu is the open-source fork of Terraform maintained by the Linux Foundation after the BSL licence change.
  • Terraform Cloud and Terraform Enterprise add collaboration, remote state, and policy-as-code features.

Test your knowledge

Try exam-style practice questions to reinforce what you've learned.

Practice Questions →