########################################### # Define Variable ########################################### variable "vsphere_user" {} variable "vsphere_password" {} variable "vsphere_server" {} ################################################ # Provider section ################################################ provider "vsphere" { user = "${var.vsphere_user}" password = "${var.vsphere_password}" vsphere_server = "${var.vsphere_server}" # If you have a self-signed cert allow_unverified_ssl = true } ################################################# #Capturing the data from vsphere ################################################# data "vsphere_datacenter" "dc" { name = "STACK-BLR" } data "vsphere_datastore" "datastore" { name = "DATASTORE-BLR" datacenter_id = "${data.vsphere_datacenter.dc.id}" } data "vsphere_resource_pool" "pool" { name = "UA-ResPool" datacenter_id = "${data.vsphere_datacenter.dc.id}" } data "vsphere_network" "network" { name = "VM Network" datacenter_id = "${data.vsphere_datacenter.dc.id}" } ######################################################## # sourcing template ############################################################# data "vsphere_virtual_machine" "template" { name = "CentOS-Template" datacenter_id = "${data.vsphere_datacenter.dc.id}" } ######################################################### # Resource ########################################################## 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 = 1 memory = 1024 guest_id = "centos7_64Guest" network_interface { network_id = "${data.vsphere_network.network.id}" } disk { label = "disk0" size = 50 } ################################################################ # Initiate the clone ################################################################# clone { template_uuid = "${data.vsphere_virtual_machine.template.id}" customize { linux_options { host_name = "terraform-test" domain = "local.localdomain" } network_interface { ipv4_address = "192.168.2.73" ipv4_netmask = "24" } ipv4_gateway = "192.168.2.1" } } } ###################################### # Output ######################################