From 1916f8e4da633a0e759bfdf4936fc11529555cee Mon Sep 17 00:00:00 2001 From: Matthias Gatto Date: Mon, 20 Nov 2023 14:58:08 +0100 Subject: [PATCH 1/2] improve delete nic up to this patch, if the API was returning an empty array on ReadNics after a DeleteNic, the delete_nic operation on terraform was waiting for the end of the timeout to validate the delete. Not anymore. Note that this bug did happen on Ricochet, but was not hapenning on the API because the API was returning a nic either in deleting or deleted state. But it was still a bug nevertheless. Signed-off-by: Matthias Gatto --- outscale/resource_outscale_net.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/outscale/resource_outscale_net.go b/outscale/resource_outscale_net.go index 1ba48e041..cad6176f1 100644 --- a/outscale/resource_outscale_net.go +++ b/outscale/resource_outscale_net.go @@ -186,7 +186,7 @@ func resourceOutscaleOAPINetDelete(d *schema.ResourceData, meta interface{}) err state = nats[0].GetState() return resp, state, nil } - return nil, state, nil + return resp, state, nil }, Timeout: 8 * time.Minute, MinTimeout: 30 * time.Second, From ce05d8b52b93e15aeaa6f488e456c06bbdd79347 Mon Sep 17 00:00:00 2001 From: Matthias Gatto Date: Tue, 28 Nov 2023 18:51:29 +0100 Subject: [PATCH 2/2] improve delete vm the same way I did it for nic Signed-off-by: Matthias Gatto --- outscale/resource_outscale_vm.go | 38 +++++++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/outscale/resource_outscale_vm.go b/outscale/resource_outscale_vm.go index abf3f51ed..f680ee77a 100644 --- a/outscale/resource_outscale_vm.go +++ b/outscale/resource_outscale_vm.go @@ -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,