Checking for powered off state before deletion (#6283)

This commit is contained in:
aheeren 2016-04-21 12:27:36 -04:00 committed by Paul Stack
parent b1c215f5e2
commit db558ddc6b
1 changed files with 12 additions and 6 deletions

View File

@ -638,18 +638,24 @@ func resourceVSphereVirtualMachineDelete(d *schema.ResourceData, meta interface{
}
log.Printf("[INFO] Deleting virtual machine: %s", d.Id())
task, err := vm.PowerOff(context.TODO())
state, err := vm.PowerState(context.TODO())
if err != nil {
return err
}
err = task.Wait(context.TODO())
if err != nil {
return err
if state == types.VirtualMachinePowerStatePoweredOn {
task, err := vm.PowerOff(context.TODO())
if err != nil {
return err
}
err = task.Wait(context.TODO())
if err != nil {
return err
}
}
task, err = vm.Destroy(context.TODO())
task, err := vm.Destroy(context.TODO())
if err != nil {
return err
}