Hello,
Terraform newbie… I just want to do simple interactive with vsphere vm tasks like power on/off… I’m wondering if vsphere virtual machine has an option to power on/off. I’ve been searching terraform doc but couldn’t find any module has power on/off. Please help or point me to the right resource.
Best Regards
Hi using terraform provider vsphere - respurce vsphere_virtual_machine you can use power_state argument power_state, but it only work with VM that are managed by terraform
other options is use null provider and govc
resource "null_resource" "provisioning" {
depends_on = [ vsphere_virtual_machine.vm ]
triggers = {
vm_name = vsphere_virtual_machine.vm.name
}
provisioner "local-exec" {
command = "/usr/bin/sleep 10;/usr/bin/govc vm.power -on=true /${local.host_config.vm_datacenter}/vm/${local.host_config.vm_folder}/${vsphere_virtual_machine.vm.name} "
environment = {
GOVC_DATACENTER = local.host_config.vm_datacenter
GOVC_URL = local.host_config.vm_datacenter_url
GOVC_USERNAME = var.vsphere_login
GOVC_PASSWORD = var.vsphere_password
GOVC_INSECURE = true
}
}
}
local.host_config.vm_datacenter - Vsphere Datacenter
local.host_config.vm_folder - Vsphere vFolder
vsphere_virtual_machine.vm.name - Vsphere VMname