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,7 +638,12 @@ func resourceVSphereVirtualMachineDelete(d *schema.ResourceData, meta interface{
}
log.Printf("[INFO] Deleting virtual machine: %s", d.Id())
state, err := vm.PowerState(context.TODO())
if err != nil {
return err
}
if state == types.VirtualMachinePowerStatePoweredOn {
task, err := vm.PowerOff(context.TODO())
if err != nil {
return err
@ -648,8 +653,9 @@ func resourceVSphereVirtualMachineDelete(d *schema.ResourceData, meta interface{
if err != nil {
return err
}
}
task, err = vm.Destroy(context.TODO())
task, err := vm.Destroy(context.TODO())
if err != nil {
return err
}