Terraform in Azure
MS Learn module: Create infrastructure with Terraform in Azure · Learning objectives: use HashiCorp Terraform with the AzureRM provider to provision and manage Azure resources, orchestrate
plan/apply, and store state remotely.
Overview
Covers the cross-cloud IaC option in the path. Unlike Azure-only Bicep/ARM templates, terraform manages Azure (and other clouds) via providers, uses HCL, and tracks what it owns in a state file — which must be stored remotely and locked for team use.
Units / lessons covered
- HCL syntax:
resource,data,variable,output,module - AzureRM provider;
azurerm_resource_group,azurerm_storage_account, etc. terraform init→plan→apply→destroylifecycle- Backend state on an Azure Storage account (blob) with locking;
azurerm_backend - Running Terraform in a provisioning-pipeline (Azure Pipelines/GitHub Actions) and drift detection via
plan
Concepts introduced (link to term notes)
Key terms / commands
terraform init·plan·apply·destroy·.tf/.tfvars·azurermprovider ·backend "azurerm"·terraform.tfstate· state locking
Hands-on / what to try
Write a main.tf creating a resource group + storage account, terraform init/plan/apply, then terraform state list and terraform plan again to see it converge. Manually delete/resize a resource in the Portal and re-run plan to observe drift.
Exam focus
- State file ownership and remote backend + locking is the classic Terraform-on-Azure exam point (Storage account as backend).
plan= preview + drift detector;apply= reconcile to desired-state.- Contrast: Bicep/ARM have no state file (Azure is the source of truth); Terraform keeps explicit state.
Related
Path MOC · intro-infrastructure-as-code · use-bicep-arm · configuration-and-drift