Friday, 20 February 2026

Azure DevOps Tutorial: Automate Windows VM Deployment Using Terraform

Azure DevOps Tutorial: Automate Windows VM Deployment Using Terraform

vmcreation

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

✔ Install and configure Terraform
✔ Write Terraform code to deploy a Windows VM
✔ Output VM details after deployment
✔ Set up Azure Service Principal

Prerequisites

Before starting, make sure you have:
✔ An Azure Subscription
Terraform installed on your machine
Azure CLI installed (optional but recommended)
✔ Basic understanding of IaC and Azure resources

1. Install Terraform

Download Terraform from the official website:
https://www.terraform.io/downloads
After installation, verify with:
terraform version

2. Configure Azure CLI & Login

Login to Azure using Azure CLI:

az login

(Optional) Set your desired subscription:

az account set --subscription "YOUR_SUBSCRIPTION_NAME"

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






5. Define Provider — main.tf

First, lets configure the provider. In Terraform, a provider is a plugin that acts as the bridge between terraform and the target platform. In today's demo the target platform is azure.

Author Details

Hi, I'm Prashant — a full-time software engineer with a passion for automation, DevOps, and sharing what I learn. I started Py-Bucket to document my journey through tools like Docker, Kubernetes, Azure DevOps, and PowerShell scripting — and to help others navigate the same path. When I’m not coding or writing, I’m experimenting with side projects, exploring productivity hacks, or learning how to build passive income streams online. This blog is my sandbox — and you're welcome to explore it with me. Get in touch or follow me for future updates!

About Me

About the Author

Author

Hi, I'm Prashant — a full-time software engineer with a passion for automation, DevOps, and sharing what I learn. I started Py-Bucket to document my journey through tools like Docker, Kubernetes, Azure DevOps, and PowerShell scripting — and to help others navigate the same path.

When I’m not coding or writing, I’m experimenting with side projects, exploring productivity hacks, or learning how to build passive income streams online. This blog is my sandbox — and you're welcome to explore it with me.

Get in touch or follow me for future updates!