Creating a Azure Windows VM through terraform


In Azure , I'm trying to create a Windows VM using terraform.<br /> I have done this through powershell previously using Template.json file. Now I have to do with terraform, which I'm completely new to.<br /> So I have searched for some Sample scripts which creates VM in Azure and found <a href="https://docs.microsoft.com/en-us/azure/virtual-machines/linux/terraform-install-configure" rel="nofollow">this</a>.

In this link , there is a sample terraform script to spin a linux VM. But I need to spin a windows VM from an Image. Where should I give the Image details.<br /> My complete requirement is :<br /> 1. Create a Windows VM from an Image (have resource Id)<br /> 2. I already have Resource group, Virtual network, Subnet created. I just need to pass those values and create them.<br /> 3. We have already defined the Subnet address prefix , Vnet address space from the portal itslef. So do I have to give again in the script or can I skip it.<br /> 4. Business requirement is that no VMs should have public IP and DNS name, So if I remove "# Create public IPs" section, will that not create public IP?

The script for creating a linux machine is <a href="https://docs.microsoft.com/en-us/azure/virtual-machines/linux/terraform-create-complete-vm#complete-terraform-script" rel="nofollow">here</a> , which I'm taking it as reference.

Please forgive me if the questions I have asked is completely lame, but I need to know these details.<br /> Can anyone help me / guide me the correct way please!


From Terraform's perspective, a Windows VM is really quite similar to a Linux VM. The #1 difference in my opinion is that the Windows VM requires a os_profile_windows_config attribute, while the Linux VM needs os_profile_linux_config.

The TF code you found on the Microsoft site is a fine start. Additionally, you may look in the <a href="https://registry.terraform.io/" rel="nofollow">Terraform Registry</a>. For example, here's a <a href="https://registry.terraform.io/modules/kjanshair/virtual-machines/azurerm/1.3.0" rel="nofollow">module for a Linux VM</a>.

I strongly recommend reading through all of the options in the <a href="https://www.terraform.io/docs/providers/azurerm/r/virtual_machine.html" rel="nofollow">VM resource</a>. I know it's a lot, but you should understand what choices you have.

Lastly, there's no substitute for writing some code and testing it. If you do something wrong, either Terraform and/or the Azure API will tell you, and if it's unclear, a web search will pop up an answer or a pointer in the right direction.

Good luck!


Below is an example of how to use data to use already existing resources in terraform, also there is a code block to create a windows VM. You will need to get the existing VNET and create a NIC

Use the data directive to get the VNET azurerm_virtual_network, you can see the syntax below for the resource group. You will need to add the resource group and possibly location into this block.

Create a azurerm_network_interface resource using the VNET ID

Add the network interface ID to the VM (network_interface_ids = [])

<a href="https://github.com/terraform-providers/terraform-provider-azurerm/tree/master/examples/traffic-manager-lb-scale-set" rel="nofollow">Example TF Code to Create and load balance VMs</a>

variable "subscription_id" {} variable "client_id" {} variable "client_secret" {} variable "tenant_id" {} provider "azurerm" { tenant_id = "${var.tenant_id}" subscription_id = "${var.subscription_id}" client_id = "${var.client_id}" client_secret = "${var.client_secret}" } data "azurerm_resource_group" "resource_group" { name = "learning-tf-web-rg" } resource "azurerm_virtual_machine" "web_server" { name = "server" location = "westus2" resource_group_name = "${data.azurerm_resource_group.resource_group.name}" network_interface_ids = [] vm_size = "Standard_B2s" storage_image_reference { publisher = "MicrosoftWindowsServer" offer = "WindowsServer" sku = "2016-Datacenter-Server-Core-smalldisk" version = "latest" } storage_os_disk { name = "server-os" caching = "ReadWrite" create_option = "FromImage" managed_disk_type = "Standard_LRS" } os_profile { computer_name = "server" admin_username = "server" admin_password = "Passw0rd1234" } os_profile_windows_config { } }


  • How to alter the display of what Spacebars outputs?
  • [] is not identical to [] [duplicate]
  • Share executable between docker images
  • Entity Framework v4 and underscores in column names
  • Thrift Client can't connect
  • How do I get the data from a finished `NSURLSessionDataTask`?
  • Sorting IP Addresses in a Python Script
  • Using a ListFragment with a SimpleCursorAdapter with the Holder Pattern
  • deploying Node.js app for production
  • Celery + Redis - .get() hangs indefinitely after running smoothly for ~70 hours
  • MySpace DOM?
  • How to browse android SDK sources in Android studio 2.0
  • Submission of new app with iAds
  • Is it possible to ask GIT, don't show a file?
  • How to generate an asynchronous reset verilog always blocks with chisel
  • How to create two column output from a single column
  • Aptana 3 remove bundle (jquery)
  • How do I retrieve the user information of a user authenticated with Apache's mod_ldap?
  • using System.Speech.Synthesis with Windows10 universal app (XAML-C#)
  • Uncaught TypeError: $(…).select2 is not a function
  • Django model inheritance, filtering models
  • GAE: Way to get reference to an HttpSession from its ID?
  • Spring boot 2.0.0.M4 required a bean named 'entityManagerFactory' that could not be found
  • Graphics.CopyFromScreen [Web application] + The handle is invalid
  • What is the purpose of TaskExecutor in spring?
  • Sequential (transactional) API calls in angular 4 with state management
  • ADO and msqli connections very slow
  • With Hadoop, can I create a tasktracker on a machine that isn't running a datanode?
  • Initializer list vs. initialization method
  • Control modification in presentation layer
  • Sails.js/waterline: Executing waterline queries in toJSON function of a model?
  • Regex thinks I'm nesting, but I'm not
  • What is the “return” in scheme?
  • Fetching methods from BroadcastReceiver to update UI
  • javaw.exe and eclipse startup problems
  • Javascript Callbacks with Object constructor
  • SSO with signing and signature validation doesn't work
  • Function pointer “assignment from incompatible pointer type” only when using vararg ellipsis
  • Matrix multiplication with MKL
  • How to disable jQuery.jplayer autoplay?