Only undeploy a machine if it is switched on

This commit is contained in:
Brett Mack 2015-11-25 12:05:59 +00:00
parent 5dde514281
commit a02667389e
1 changed files with 16 additions and 9 deletions

View File

@ -315,16 +315,23 @@ func resourceVcdVAppDelete(d *schema.ResourceData, meta interface{}) error {
return fmt.Errorf("error finding vapp: %s", err)
}
err = retryCall(vcdClient.MaxRetryTimeout, func() error {
task, err := vapp.Undeploy()
if err != nil {
return fmt.Errorf("Error undeploying: %#v", err)
}
return task.WaitTaskCompletion()
})
status, err := vapp.GetStatus()
if err != nil {
return err
return fmt.Errorf("Error getting VApp status: %#v", err)
}
if status == "POWERED_ON" {
err = retryCall(vcdClient.MaxRetryTimeout, func() error {
task, err := vapp.Undeploy()
if err != nil {
return fmt.Errorf("Error undeploying: %#v", err)
}
return task.WaitTaskCompletion()
})
if err != nil {
return err
}
}
err = retryCall(vcdClient.MaxRetryTimeout, func() error {