From 40a706364321f2972bfa026ff17de51505364d99 Mon Sep 17 00:00:00 2001 From: Skiepp Date: Tue, 17 Oct 2023 08:49:02 +0200 Subject: [PATCH] +Cancel Instance (Ref: #25) (#26) * +CencelInstance (Ref: #25) * Tested Cancel Service --------- Co-authored-by: Skiepp --- contabo/resource_instance.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/contabo/resource_instance.go b/contabo/resource_instance.go index b883973..8160292 100644 --- a/contabo/resource_instance.go +++ b/contabo/resource_instance.go @@ -488,6 +488,23 @@ func reinstall(d *schema.ResourceData, client *openapi.APIClient, ctx context.Co func resourceInstanceDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { var diags diag.Diagnostics + + client := m.(*openapi.APIClient) + instanceId, err := strconv.ParseInt(d.Id(), 10, 64) + if err != nil { + return diag.FromErr(err) + } + + _, httpResp, err := client.InstancesApi. + CancelInstance(ctx, instanceId). + XRequestId(uuid.NewV4().String()). + Execute() + + if err != nil { + return HandleResponseErrors(diags, httpResp) + } + + d.SetId("") return diags }