Introduction
This article will focus on deploying an Azure Windows virtual machine using Terraform as infrastructure as code.
In this article, you will learn how to set up your Azure account, configure your Terraform environment, write Terraform code to define your VM and associated resources, and deploy your VM to Azure using Terraform.
If you're interested, my GitHub repository is open for use. You can access it at https://github.com/shanuka-thushara/Azure-Windows-VM-Using-Terraform-IaC
Prerequisites
- Azure subscription
- Install and configure Terraform
- Visual Studio Code
Solution Diagram

Step 1. Create a file directory in your local location.

Step 2. Create a named Provider.tf file.

Step 3. Insert the following code in Provide.tf file.
provider "azurerm" {
features {}
}

Step 4. In Main.tf file use the following code to create a resource group (RG).
resource "azurerm_resource_group" "RG" {
name = "Shanuka-RG"
location = "East US"
}

Step 5. In Main.tf file use the following code to create a Virtual Network and Subnet.
resource "azurerm_virtual_network" "VNet" {
name = "Shanuka-VNet"
address_space = ["10.99.0.0/16"]
location = azurerm_resource_group.RG.location
resource_group_name = azurerm_resource_group.RG.name
}
resource "azurerm_subnet" "AzureSubnet" {
name = "ShanukaSubnet"
resource_group_name = azurerm_resource_group.RG.name
virtual_network_name = azurerm_virtual_network.VNet.name
address_prefixes = ["10.99.2.0/24"]
}

Note: As per your requirement you can choose the IP address space.
Step 6. Create a Network Interface Card (nic) using the following code.
resource "azurerm_network_interface" "nic" {
name = "shanuka-nic"
location = azurerm_resource_group.RG.location
resource_group_name = azurerm_resource_group.RG.name
ip_configuration {
name = "internal"
subnet_id = azurerm_subnet.ShanukaSubnet.id
private_ip_address_allocation = "Dynamic"
}
}










Join the conversation! Your thoughts help the community grow.