Skip to content

Commit

Permalink
ForceStop vm before destroy
Browse files Browse the repository at this point in the history
  • Loading branch information
outscale-toa committed Feb 28, 2024
1 parent 0d44979 commit 765580a
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions outscale/resource_outscale_vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down

0 comments on commit 765580a

Please sign in to comment.