From 765580af0bd4d7ff71a311c6f474e3ea68487a36 Mon Sep 17 00:00:00 2001 From: Thiery Ouattara Date: Tue, 27 Feb 2024 12:54:04 +0000 Subject: [PATCH] ForceStop vm before destroy --- outscale/resource_outscale_vm.go | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/outscale/resource_outscale_vm.go b/outscale/resource_outscale_vm.go index 13bfe6c05..108b8c5ac 100644 --- a/outscale/resource_outscale_vm.go +++ b/outscale/resource_outscale_vm.go @@ -1112,10 +1112,23 @@ func resourceOAPIVMDelete(d *schema.ResourceData, meta interface{}) error { conn := meta.(*OutscaleClient).OSCAPI id := d.Id() + var err error - log.Printf("[INFO] Terminating VM: %s", id) + err = resource.Retry(d.Timeout(schema.TimeoutDelete), func() *resource.RetryError { + _, httpResp, err := conn.VmApi.StopVms(context.Background()).StopVmsRequest(oscgo.StopVmsRequest{ + VmIds: []string{id}, + ForceStop: oscgo.PtrBool(true), + }).Execute() + if err != nil { + return utils.CheckThrottling(httpResp, err) + } + return nil + }) + + if err != nil { + return fmt.Errorf("Error Force stopping vms before destroy %s", err) + } - var err error err = resource.Retry(d.Timeout(schema.TimeoutDelete), func() *resource.RetryError { _, httpResp, err := conn.VmApi.DeleteVms(context.Background()).DeleteVmsRequest(oscgo.DeleteVmsRequest{ VmIds: []string{id},