🧭 Introduction
In this guide, we will deploy a pair of Windows Server 2022 virtual machines behind an Azure Load Balancer, automatically install IIS on them using a startup script, and configure NAT rules to allow RDP access. This is a great hands-on example to learn Infrastructure as Code (IaC) and understand how Azure Load Balancers distribute traffic.
本指南将通过 Terraform 创建两个 VM + 负载均衡器 + NAT 规则 + 自动 IIS 安装,适合练习云架构基础。
🗂 Project Structure
bash
terraform-lb-iis-vm/
├── main.tf # All core infrastructure resources
├── variables.tf # Input variables (e.g., username/password)
├── terraform.tfvars # Actual values for variables
├── outputs.tf # Output info (e.g., Public IP)
├── startup-script.ps1 # Script to install IIS on each VM
🔧 What This Code Does
Creates a Resource Group and Virtual Network
Defines a Public Load Balancer with Backend Pool
Sets up NAT rules for RDP (TCP 50001 & 50002)
Deploys two Windows Server VMs and installs IIS
Associates the VMs with the Load Balancer backend pool
This architecture allows HTTP access via Load Balancer's Public IP, and RDP access via port NAT.
🪜 How to Deploy
Make sure you have:
Azure CLI installed and logged in (az login)
Terraform installed locally
Steps:
terraform init
terraform plan
terraform apply
When prompted, type yes.
🌐 Access Instructions
VM1 RDP: RDP to PublicIP:50001
VM2 RDP: RDP to PublicIP:50002
HTTP Test: http://PublicIP (should show IIS welcome page)
✅ Conclusion
Using only Terraform, we have:
Created two VMs
Configured a Load Balancer and NAT
Installed IIS automatically via startup script
This project demonstrates how to combine multiple Azure services in an automated and repeatable way. It’s a foundational building block for scalable web applications.
🔜 Coming Next...
Use Azure Run Command to manage VMs remotely
Add autoscaling rules for backend VMs
Integrate with Azure Monitor for health probes
If you find this helpful, feel free to ⭐️ the repo and share your feedback!
Top comments (0)