Creating a Terraform Windows 2016 server Virtual Machine with Azure – Part 4

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"
  }
}
 

About cloudinspired

Cloud Inspired authors have over 30 years experience within the IT industry, providing expertise and knowledge on infrastructure, hybrid, public and private clouds platforms. Detailed easy to follow technical videos, training and tutorial guides are provided by subject matter experts covering various technologies including Azure, IaaS, SaaS, PaaS and Microsoft 365. This website focuses mainly on the Microsoft 365 and Azure Cloud platform and provides easy to follow step by step technical guides, diagrams, cloud certifications and tutorials. The aim is to deliver articles and videos on Microsoft 365 and Azure Cloud from start to finish on many different Azure services and certifications, building and increasing the viewers knowledge in a short, logical, easy to understand format quickly getting to the point of the subject matter! Check out the YouTube channel for a full list of published Cloud Inspired videos and lets get inspired about Cloud!

View all posts by cloudinspired →

Leave a Reply

Your email address will not be published. Required fields are marked *