Table of Contents
Introduction
Terraform on Azure enables repeatable and auditable infrastructure changes. This guide walks you through a clean Terraform setup for Azure, including provider configuration and a minimal virtual network.
Prerequisites
- An Azure subscription.
- Azure CLI installed and authenticated (
az login). - Terraform installed (
terraform version).
Step 1: Create a Working Folder
Create a new folder and add a main.tf file.
terraform {
required_version = ">= 1.5.0"
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = "~> 3.0"
}
}
}
provider "azurerm" {
features {}
}
Step 2: Create a Resource Group and VNet
Define a resource group and a virtual network.
resource "azurerm_resource_group" "demo" {
name = "rg-terraformpilot-demo"
location = "westeurope"
}
resource "azurerm_virtual_network" "demo" {
name = "vnet-terraformpilot-demo"
address_space = ["10.0.0.0/16"]
location = azurerm_resource_group.demo.location
resource_group_name = azurerm_resource_group.demo.name
}
Step 3: Initialize and Deploy
Run the standard Terraform workflow:
terraform init
terraform plan
terraform apply
Step 4: Clean Up
Avoid charges by destroying resources when done:
terraform destroy
Best Practices for Beginners
- Keep your state remote for teams (Azure Storage + state locking).
- Separate environments with workspaces or dedicated state files.
- Use variables for location and names to keep configs reusable.
Next Steps in the DevOps Chain
Once infrastructure is ready, configure and orchestrate it:
- Configure servers: https://www.ansiblepilot.com
- Orchestrate apps: https://kubernetes.recipes
Related Tutorials
- Terraform variables and outputs
- Terraform state management
- Terraform workspaces

