Module 1: Introduction to Terraform on Azure

Overview

Welcome to the first module in our Azure Terraform Tutorial series. This guide lays the foundation for provisioning and managing infrastructure on Microsoft Azure using Terraform — the open-source Infrastructure as Code (IaC) tool from HashiCorp.

What Is Terraform?

Terraform is a declarative IaC tool that lets you define cloud infrastructure using code. It compares your desired state (written in HCL — HashiCorp Configuration Language) with the current state and generates a plan to reconcile the two.

Key benefits

Why use Terraform with Azure?

Terraform’s Azure integration is powered by the robust azurerm provider. Here’s why it’s a great fit:

Installing Terraform CLI and Azure CLI

To get started, install both tools:

Terraform CLI

choco install -y terraform
brew tap hashicorp/tap  
brew install hashicorp/tap/terraform
sudo apt update && sudo apt-get install terraform

Verify installation:

terraform --version

Azure CLI

Install via Microsoft Docs and verify:

az --version

Authenticating with Azure

Before Terraform can manage Azure resources, you need to authenticate.

az login

This opens a browser for sign-in and stores credentials locally.

az ad sp create-for-rbac \
  --name "<SP_Name>" \
  --role "Contributor" \
  --scopes "/subscriptions/<Subscription_Id>"

Set environment variables:

export ARM_SUBSCRIPTION_ID=<subscription_id>
export ARM_CLIENT_ID=<appId>
export ARM_CLIENT_SECRET=<password>
export ARM_TENANT_ID=<tenant_id>

Setting Up Your First Terraform Project

Terraform reads all .tf files in the working directory. Recommended structure:

/my-terraform-project
├── providers.tf       # Azure provider config
├── main.tf            # Resource definitions
├── variables.tf       # Input variables
├── outputs.tf         # Output values
Terraform on Azure tutorial
Introduction to Terraform on Azure

Initialize the project:

terraform init

This downloads providers and sets up the backend (default: local terraform.tfstate).

Core Terraform Workflow

comments powered by Disqus

Copyright 2025. All rights reserved.