Azure DevOps Tutorial: Automate Windows VM Deployment Using Terraform
Introduction
Deploying infrastructure as code (IaC) is a modern and scalable way to manage your cloud resources. In this guide, we’ll walk you step-by-step on how to create a Windows Virtual Machine in Azure using Terraform.
This tutorial is ideal for beginners and intermediate users who want a repeatable and automated way to spin up Windows VMs in Azure.
What You Will Learn
✔ Write Terraform code to deploy a Windows VM
✔ Output VM details after deployment
✔ Set up Azure Service Principal
Prerequisites
✔ An Azure Subscription
✔ Terraform installed on your machine
✔ Azure CLI installed (optional but recommended)
✔ Basic understanding of IaC and Azure resources
1. Install Terraform
➡ https://www.terraform.io/downloads
After installation, verify with:
2. Configure Azure CLI & Login
3. Create Azure Service Principal
A Service Principal gives Terraform permission to provision resources in Azure.
Run:
az ad sp create-for-rbac --name "TerraformSP" --role="Contributor" --sdk-auth
4. Create Terraform Project Folder
Create a new folder:
mkdir azure-windows-vm
cd azure-windows-vm
Create the following files:
✔ main.tf
✔ variables.tf
✔ outputs.tf