Skip to content

Commit

Permalink
Retry on MySQL database deletion (#613)
Browse files Browse the repository at this point in the history
  • Loading branch information
LBGarber authored Mar 29, 2022
1 parent fb859aa commit 91bc671
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions linode/databasemysql/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ import (
"fmt"
"log"
"strconv"
"strings"
"time"

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/linode/linodego"
"github.com/linode/terraform-provider-linode/linode/helper"
Expand Down Expand Up @@ -148,13 +150,19 @@ func deleteResource(ctx context.Context, d *schema.ResourceData, meta interface{
return diag.Errorf("Error parsing Linode MySQL database ID %s as int: %s", d.Id(), err)
}

if err := client.DeleteMySQLDatabase(ctx, int(id)); err != nil {
return diag.Errorf("failed to delete mysql database %d: %s", id, err)
}

d.SetId("")
// We should retry on intermittent deletion errors
return diag.FromErr(resource.RetryContext(ctx, d.Timeout(schema.TimeoutDelete), func() *resource.RetryError {
err := client.DeleteMySQLDatabase(ctx, int(id))
if err != nil {
if lerr, ok := err.(*linodego.Error); ok &&
lerr.Code == 500 && strings.Contains(lerr.Message, "Unable to delete instance") {
return resource.RetryableError(err)
}
return resource.NonRetryableError(fmt.Errorf("failed to delete mysql database %d: %s", id, err))
}

return nil
return nil
}))
}

func createEngineSlug(engine, version string) string {
Expand Down

0 comments on commit 91bc671

Please sign in to comment.