Open
Description
The function resourceVcdVAppUpdate
almost always triggers a power-off operation.
Since this function is also called immediately after a vApp creation, the call to power-off is almost always guaranteed to be wasted. Furthermore, the code practically ignores the error returned by the operation (it's a "400 - bad request" response).
Here's the code in question
if d.HasChange("memory") || d.HasChange("cpus") || d.HasChange("power_on") || d.HasChange("ovf") {
if status != "POWERED_OFF" {
task, err := vapp.PowerOff()
if err != nil {
// can't *always* power off an empty vApp so not necesarrily an error
if _, ok := d.GetOk("template_name"); ok {
return fmt.Errorf("error Powering Off: %#v", err)
}
}
[...]
}
}
In similar circumstances, govcd library uses if vapp.VApp.Status == 4
(i.e. POWERED_ON
- See VAppStatuses
in types/v56/types.go
)
I propose changing the condition to if status == "POWERED_ON"
to prevent unnecessary pollution of the logs.