Terraform

What it is

Terraform (HashiCorp) is an open-source cross-cloud infrastructure as code tool. You write infrastructure in HCL (HashiCorp Configuration Language), and Terraform’s providers translate that into API calls for many clouds — including the AzureRM and AzureAD providers for Azure. Terraform keeps a state file that records what it has created, and compares desired vs. current state before each apply.

Why it exists

Organizations are multi-cloud / hybrid. An Azure-only DSL like Bicep or ARM templates can’t manage AWS, GCP, or on-prem in one language. Terraform gives a single declarative workflow and model across every provider, plus a huge public module registry and mature plan/apply lifecycle.

Key ideas

  • HCL syntax: .tf files declare resources, data sources, variables, outputs, and modules.
  • Plan / Apply loop: terraform plan shows the diff (+ change / ~ update / - destroy); terraform apply executes it — the equivalent of desired-state reconciliation.
  • State file (terraform.tfstate): the source of truth for mapping resources to real objects; must be stored remotely (e.g. Azure Storage with locking) for team use.
  • Providers: plugin resolvers (AzureRM, AWS, GCP, kubernetes); azurerm manages Azure resources, azurerm_backend for state.
  • Integration with Pipelines/GitHub Actions: Terraform tasks in Azure Pipelines or GitHub Actions run init → plan → apply as a provisioning-pipeline.

How it fits (diagram)

terraform - Microsoft diagram

Diagrams courtesy of Microsoft Learn / Azure docs: azure/developer/terraform/overview

Exam notes

  • Compare to Bicep: Bicep = Azure-only, transpiles to ARM, no state file (ARM refreshes from live). Terraform = multi-cloud, HCL, explicit state, third-party.
  • Know terraform init (download providers), plan, apply, destroy, and remote state locking.
  • Terraform drift detection: terraform plan against live cloud reveals manual changes → configuration drift.

infrastructure-as-code · bicep · arm-template · desired-state · configuration-drift · provisioning-pipeline

📘 Source: Microsoft Learn — Terraform