Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve delete vm the same way I did it for nic #406

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 35 additions & 3 deletions outscale/resource_outscale_vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -1120,9 +1120,41 @@ func resourceOAPIVMDelete(d *schema.ResourceData, meta interface{}) error {
log.Printf("[DEBUG] Waiting for VM (%s) to become terminated", id)

stateConf := &resource.StateChangeConf{
Pending: []string{"pending", "running", "shutting-down", "stopped", "stopping"},
Target: []string{"terminated"},
Refresh: vmStateRefreshFunc(conn, id, ""),
Pending: []string{"pending", "running", "shutting-down", "stopped", "stopping"},
Target: []string{"terminated"},
Refresh: func() (interface{}, string, error) {
var resp oscgo.ReadVmsResponse
err := resource.Retry(30*time.Second, func() *resource.RetryError {
rp, httpResp, err := conn.VmApi.ReadVms(context.Background()).ReadVmsRequest(oscgo.ReadVmsRequest{
Filters: &oscgo.FiltersVm{
VmIds: &[]string{id},
},
}).Execute()
if err != nil {
return utils.CheckThrottling(httpResp, err)
}
resp = rp
return nil
})
if err != nil {
log.Printf("[ERROR] error on InstanceStateRefresh: %s", err)
return nil, "", err
}

if !resp.HasVms() || len(resp.GetVms()) < 1 {
return resp, "terminated", nil
}

vm := resp.GetVms()[0]
state := vm.GetState()

if state != "terminated" {
return vm, state, fmt.Errorf("Failed to reach target state. Reason: %v", *vm.State)

}

return vm, state, nil
},
Timeout: d.Timeout(schema.TimeoutDelete),
Delay: 10 * time.Second,
MinTimeout: 3 * time.Second,
Expand Down
Loading