Skip to content

Commit

Permalink
resource/aws_db_instance: Ignore DBInstanceNotFound error during dele…
Browse files Browse the repository at this point in the history
…tion

Reference: #12900

Unfortunately testing this scenario is complicated in the Terraform Plugin SDK acceptance testing framework as refresh before deletion is standard behavior and the error gets caught in the Read function (e.g. disappears testing). In the future, we may propose to write a standard way for converting AWS Go SDK errors with specific error codes and messages to the Terraform Plugin SDK resource.NotFoundError, which we could then use static analysis against in the Read/Delete/CheckDestroy functions to ensure its always handled. For now though, this is a targeted fix for a community reported situation.
  • Loading branch information
bflad committed Oct 30, 2020
1 parent 1a20bef commit 27df261
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions aws/resource_aws_db_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/rds"
"github.com/hashicorp/aws-sdk-go-base/tfawserr"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
Expand Down Expand Up @@ -1412,6 +1413,10 @@ func resourceAwsDbInstanceDelete(d *schema.ResourceData, meta interface{}) error
log.Printf("[DEBUG] DB Instance destroy configuration: %v", opts)
_, err := conn.DeleteDBInstance(&opts)

if tfawserr.ErrCodeEquals(err, rds.ErrCodeDBInstanceNotFoundFault) {
return nil
}

// InvalidDBInstanceState: Instance XXX is already being deleted.
if err != nil && !isAWSErr(err, rds.ErrCodeInvalidDBInstanceStateFault, "is already being deleted") {
return fmt.Errorf("error deleting Database Instance %q: %s", d.Id(), err)
Expand Down

0 comments on commit 27df261

Please sign in to comment.