Azure & Terraform
Part 4 – creating a Terraform Windows server Virtual Machine (VM) with azure infrastructure as code.
# Cloudinspired.com Part 4 - Create a Windows Virtual Machine resource "azurerm_network_interface" "main" { name = "nic" location = "UK South" resource_group_name = "${azurerm_resource_group.RG.name}" ip_configuration { name = "testconfiguration1" subnet_id = "${azurerm_subnet.FrontEnd.id}" private_ip_address_allocation = "dynamic" public_ip_address_id = "${azurerm_public_ip.publicip.id}" } } resource "azurerm_public_ip" "publicip" { name = "myPublicIP" location = "UK South" resource_group_name = "${azurerm_resource_group.RG.name}" public_ip_address_allocation = "static" } resource "azurerm_virtual_machine" "test" { name = "Server01" location = "UK South" resource_group_name = "${azurerm_resource_group.RG.name}" network_interface_ids = ["${azurerm_network_interface.main.id}"] vm_size = "Standard_F2s_v2" availability_set_id = "${azurerm_availability_set.AS1.id}" # Uncomment this line to delete the OS disk automatically when deleting the VM delete_os_disk_on_termination = true # Uncomment this line to delete the data disks automatically when deleting the VM delete_data_disks_on_termination = true storage_image_reference { publisher = "MicrosoftWindowsServer" offer = "WindowsServer" sku = "2012-R2-Datacenter" version = "latest" } storage_os_disk { name = "myosdisk1" caching = "ReadWrite" create_option = "FromImage" managed_disk_type = "Standard_LRS" } os_profile { computer_name = "Server01" admin_username = "techpro" admin_password = "Password1234!" } os_profile_windows_config { enable_automatic_upgrades = false } tags { environment = "Production" } }