Skip to content

Commit

Permalink
r/aws_redshiftserverless_namespace: Retry delete on ConflictException.
Browse files Browse the repository at this point in the history
  • Loading branch information
ewbankkit committed Sep 1, 2022
1 parent c68d9fa commit 7aafc73
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions internal/service/redshiftserverless/namespace.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package redshiftserverless
import (
"fmt"
"log"
"time"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/redshiftserverless"
Expand Down Expand Up @@ -251,18 +252,22 @@ func resourceNamespaceUpdate(d *schema.ResourceData, meta interface{}) error {
func resourceNamespaceDelete(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*conns.AWSClient).RedshiftServerlessConn

deleteInput := redshiftserverless.DeleteNamespaceInput{
NamespaceName: aws.String(d.Id()),
}

log.Printf("[DEBUG] Deleting Redshift Serverless Namespace: %s", d.Id())
_, err := conn.DeleteNamespace(&deleteInput)
_, err := tfresource.RetryWhenAWSErrMessageContains(10*time.Minute,
func() (interface{}, error) {
return conn.DeleteNamespace(&redshiftserverless.DeleteNamespaceInput{
NamespaceName: aws.String(d.Id()),
})
},
// "ConflictException: There is an operation running on the namespace. Try deleting the namespace again later."
redshiftserverless.ErrCodeConflictException, "operation running")

if tfawserr.ErrCodeEquals(err, redshiftserverless.ErrCodeResourceNotFoundException) {
return nil
}

if err != nil {
if tfawserr.ErrCodeEquals(err, redshiftserverless.ErrCodeResourceNotFoundException) {
return nil
}
return err
return fmt.Errorf("error deleting Redshift Serverless Namespace (%s): %w", d.Id(), err)
}

if _, err := waitNamespaceDeleted(conn, d.Id()); err != nil {
Expand Down

0 comments on commit 7aafc73

Please sign in to comment.