Skip to content

Commit

Permalink
Retry database delete if response is 409 (#328)
Browse files Browse the repository at this point in the history
Fixes #327
  • Loading branch information
emerkle826 authored Nov 22, 2023
1 parent 4d0d598 commit 202c28e
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion internal/provider/resource_database.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ var availableDbTypes = []string{

var databaseCreateTimeout = time.Minute * 40
var databaseReadTimeout = time.Minute * 5
var databaseDeleteTimeout = time.Minute * 20
var databaseDeleteTimeout = time.Minute * 40
var databaseUpdateTimeout = time.Minute * 40

func resourceDatabase() *schema.Resource {
Expand Down Expand Up @@ -323,6 +323,11 @@ func resourceDatabaseDelete(ctx context.Context, resourceData *schema.ResourceDa
return nil
}

// If the database is in Maintenance state, it will return a 409. We can retry this
if resp.StatusCode() == http.StatusConflict {
return retry.RetryableError(fmt.Errorf("Unable to terminate database %s. %s", databaseID, string(resp.Body)))
}

// All other 4XX status codes are NOT retried
if resp.StatusCode() >= http.StatusBadRequest {
return retry.NonRetryableError(fmt.Errorf("unexpected response attempting to terminate database. Status code: %d, message = %s", resp.StatusCode(), string(resp.Body)))
Expand Down

0 comments on commit 202c28e

Please sign in to comment.