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,6 +315,12 @@ func resourceVcdVAppDelete(d *schema.ResourceData, meta interface{}) error {
return fmt.Errorf("error finding vapp: %s", err) return fmt.Errorf("error finding vapp: %s", err)
} }
status, err := vapp.GetStatus()
if err != nil {
return fmt.Errorf("Error getting VApp status: %#v", err)
}
if status == "POWERED_ON" {
err = retryCall(vcdClient.MaxRetryTimeout, func() error { err = retryCall(vcdClient.MaxRetryTimeout, func() error {
task, err := vapp.Undeploy() task, err := vapp.Undeploy()
if err != nil { if err != nil {
@ -326,6 +332,7 @@ func resourceVcdVAppDelete(d *schema.ResourceData, meta interface{}) error {
if err != nil { if err != nil {
return err return err
} }
}
err = retryCall(vcdClient.MaxRetryTimeout, func() error { err = retryCall(vcdClient.MaxRetryTimeout, func() error {
task, err := vapp.Delete() task, err := vapp.Delete()