How to create a Windows 10 VM in Azure with Terraform

I’m a strong believer in systems and infrastructure as code. But, I don’t feel strongly about which is the best cloud service. That is why I love Hashicorp’s Terraform product.

Terraform is an infrastructure automation tool that is cloud agnostic(usable with AWS, Azure, VMware, Open Stack,etc…) and uses simple configuration files to build and maintain servers, services, networks and more! Even the most basic Terraform configurations are highly useful for quickly building and destroying cloud resources for “on demand” type jobs.

My employer is in the process of migrating systems to Azure. Specifically I’m creating templates for clusters of Linux machines that run QA jobs. The jobs are spawned by a single Windows client. However setting up a Windows 10 VM is much harder than you would imagine considering Azure is a Microsoft cloud service! For example, Terraform doesn’t check for invalid hostnames or ‘user password’, values that are to short. Instead your Windows 10 VM will simply fail at the very end. If you enable boot logging you will get a black screen with OOBE error.

This tutorial assumes you have basic knowledge of,(and installed) Terraform. If you don’t please run through the Hashicorp tutorial before continuing. Additionally this article assumes you have a valid Azure account. You can sign up for a free trial in minutes, but requires a credit card. $200 of free credits the first 30 days!

Goals of this Post:

  • Use Azure CLI to select a Windows 10 image
  • Terraform configuration of Azure Resource Group
  • Terraform configuration of Network & public IP Andress
  • Terraform configuration of Windows 10 VM

Install Azure CLI for Linux

Lets start by logging into Azure. In order to launch Terraform in Azure you must install the Azure CLI. Execute ‘az login’ while a web browser is open. A tab will take you the Azure login. Once you login you can execute Terraform configurations.

Obtain a valid Windows image: Offer, SKU,Publisher & version

The toughest part is identifying a valid ‘Offer/Pub/SKU’ for Windows 10. the Microsoft store and Azure web portal do not seem to list the specific values we need to automate the builds.

The obvious thing to do is use the Azure CLI to find the values for the Offer, Publisher, and SKU for Windows 10. However using Microsoft as publisher shows no results for Windows 10, but list over 1280 other images!

Where is Windows 10? Searching ‘Microsoft’ as the publisher produces 100’s of results. Try,


After some Googling I managed to find the command that list their current Windows 10 offerings:

Pick the version of Windows you want. Add the information to your Terraform configuration file in the storage_image_reference { } of your Windows 10 VM Terraform configuration.

excerpt from az_windows10.tf:

storage_image_reference {
publisher = “MicrosoftWindowsDesktop”
offer = “Windows-10”
sku = “rs5-pro”
version = “17763.253.65”

Below is a complete working example for a Windows 10 configuration in Azure! If you run into trouble reference my system below. Good luck! Oh, and if you are not sure what to do next remember to run through that Terraform tutorial!


Written by mattb in: Automation,Linux,Windows |

No Comments »

RSS feed for comments on this post. TrackBack URL

Leave a comment