Ahmed Abdelwahed

Ahmed Abdelwahed

Technical Trainer | Cloud & Infrastructure Specialist

ahmed@abdelwahed.me

Technical Blog

From the Server Room
to the Cloud

200+ Delivered Courses
30+ Certificates
10+ Years in IT

Terraform for VMware vSphere | Quick Guide

Terraform for VMware vSphere — Ahmed Abdelwahed
VMware Terraform · IaC 4 Labs · Quick Guide

Terraform for VMware vSphere

Automate VM deployments on vSphere using Terraform — from installing the provider to deploying fleets of VMs with custom sizes, IPs, and host targeting. Infrastructure as Code, lab-proven.

Ahmed Abdelwahed Version 25.06 4 Hands-on Labs VMware & DevOps

About This Guide

This quick guide walks you through automating VM deployments on VMware vSphere using Terraform — the industry-standard Infrastructure as Code tool. Starting from a fresh Windows installation all the way to deploying multi-VM fleets with custom CPU, memory, and IP configurations. Each lab is built against a real vCenter environment at vcenter.abdelwahed.me with full main.tf code provided and screenshots from production deployments.

Getting Started

1

Install Terraform on Windows

Download from the Terraform Downloads Page, extract to C:\Terraform, add to system PATH, then verify with terraform --version.

2

Prepare Your Configuration Files

Create a project folder (e.g. C:\MyTerraformProject), write your main.tf using VS Code or Notepad++, then navigate to the folder in PowerShell.

3

Initialize & Apply

Run terraform init to download the vSphere provider, then terraform plan to preview, and terraform apply to deploy. That’s it.

Lab Walkthroughs

Lab 1

Create 1 Linux VM from a Template

Beginner

Connect to vCenter, load your datacenter, cluster, datastore, and network objects, then clone a Linux template into a new VM named Linux1 with a static IP, custom hostname, and EFI firmware.

VM: Linux1 CPU: 2 vCPU RAM: 1 GB IP: 192.168.221.100 Disk: Thin provisioned Firmware: EFI
resource “vsphere_virtual_machine” “vm” {
  name = “Linux1”
  num_cpus = 2
  memory = 1024 # 1 GB
  firmware = “efi”
  
}
Lab 2

Deploy 10 VMs with Custom IP Range

Intermediate

Use Terraform’s count meta-argument to loop and deploy multiple VMs automatically — each with a sequentially assigned static IP address from a defined range.

VMs: Linux-1 … Linux-N IPs: 192.168.221.20+ Method: count loop Cluster: vCluster
name = “Linux-${count.index + 1}”
ipv4_address = “192.168.221.${20 + count.index}”
# Produces: Linux-1 → .20, Linux-2 → .21 …
Lab 3

Deploy 5 VMs on a Specific ESXi Host

Intermediate

Target a specific ESXi host (h2.abdelwahed.me) instead of the cluster resource pool — useful for host-pinning, licensing control, or maintenance scenarios.

VMs: Linux-H2-1 … Linux-H2-5 Host: h2.abdelwahed.me IPs: 192.168.221.40–44
data “vsphere_host” “host_h2” {
  name = “h2.abdelwahed.me”
}

resource_pool_id = data.vsphere_host.host_h2.resource_pool_id
Lab 4

Deploy VMs with Different Sizes

Advanced

Use a Terraform variable map to define heterogeneous VM configurations — deploy a web server, database, and test VM each with different CPU, memory, and IP in a single terraform apply.

web: 2 vCPU / 2 GB db: 4 vCPU / 4 GB test: 1 vCPU / 1 GB Method: variable map + count
variable “vm_configs” {
  default = [
    { name = “web”, cpu = 2, mem = 2048 },
    { name = “db”, cpu = 4, mem = 4096 },
    { name = “test”, cpu = 1, mem = 1024 },
  ]
}

Who Is This For

⚙️
VMware Admins

vSphere engineers wanting to automate repetitive VM provisioning tasks.

🔁
DevOps Engineers

Teams adopting Infrastructure as Code for on-premises VMware environments.

☁️
Cloud Architects

Professionals bridging traditional vSphere to hybrid or multi-cloud workflows.

Guide Details

Version25.06
·
Labs4 Hands-on Labs
·
PlatformVMware vSphere / vCenter
·
ToolTerraform (HashiCorp)
·
AuthorAhmed Abdelwahed

Download the Complete Guide

Full Terraform code, step-by-step labs, and production screenshots — free to download.