This repository contains Infrastructure as Code (IaC) for automating virtual machine provisioning on VMware vSphere using Terraform and Packer.
It enables consistent VM builds, rapid deployment, and simplified lifecycle management.
- Automated VM creation on vSphere with Terraform
- Golden image building with Packer
- Configurable CPU, memory, disk, and network settings
- Support for cloning from templates
- Easy customization via variables
- Terraform >= 1.0
- Packer
- VMware vSphere environment (vCenter + ESXi)
- vSphere credentials with sufficient permissions
- Access to a datastore and network in vSphere
- Clone the repo
git clone https://github.com/your-org/terraform-vsphere-vm-automation.git cd terraform-vsphere-vm-automation
vsphere_user = "administrator@vsphere.local" vsphere_password = "yourpassword" vsphere_server = "vcenter.example.com"
-
Configure variables Create or edit terraform.tfvars: datacenter_name = "Datacenter" cluster_name = "Cluster" datastore_name = "Datastore" network_name = "VM Network" ubuntu_name = "ubuntu-template"
-
Build base image with Packer
packer build packer/ubuntu.json
-
Initialize Terraform
terraform init
-
Validate configuration
terraform validate
-
Preview changes
terraform plan
-
Apply configuration
terraform apply
-
Destroy resources (optional)
terraform destroy