Terraform with VMWare

I didn’t find much in the way of examples online for using Terraform against VMWare. So here is the .tf config that worked for me:

provider "vsphere" {
user = "jonny@dev"
password = "CHANGEME!"
vsphere_server = "192.168.1.2"
allow_unverified_ssl = true
}
data "vsphere_datacenter" "dc" {
name = "ESX Lab"
}
data "vsphere_datastore" "datastore" {
name = "netapp002-svm001-vmaggr01-datastore001"
datacenter_id = "${data.vsphere_datacenter.dc.id}"
}
data "vsphere_resource_pool" "pool" {
name = "Resources"
datacenter_id = "${data.vsphere_datacenter.dc.id}"
}
data "vsphere_network" "network" {
name = "LabOnDemand"
datacenter_id = "${data.vsphere_datacenter.dc.id}"
}
resource "vsphere_virtual_machine" "vm" {
name = "terraform-test"
resource_pool_id = "${data.vsphere_resource_pool.pool.id}"
datastore_id = "${data.vsphere_datastore.datastore.id}"
num_cpus = 2
memory = 1024
guest_id = "other3xLinux64Guest"

network_interface {
network_id = "${data.vsphere_network.network.id}"
}
disk {
label = "disk0"
size = 20
}
}

There are only a few items that need changed in the example above, such as the name of the storage, the name of the cluster and the name of the network. Most were available from the VMware UI.

The Resource Pool to use wasn’t easy to find but using ‘Resources’ as a default got things going and the output after running the plan showed a more precise resource_pool_id:

With the terrform plan the commands to use were:

terraform init
terraform plan
terraform apply

And afterwards the VM was available in VMWare.

Leave a Reply

  • (will not be published)

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>