mirror of
https://github.com/opentofu/opentofu.git
synced 2025-01-09 23:54:17 -06:00
- Adding in additional retry logic due to latency with AWS delete (#7312)
This commit is contained in:
parent
9ddeb70312
commit
71532fff8b
@ -5,11 +5,13 @@ import (
|
||||
"fmt"
|
||||
"log"
|
||||
"regexp"
|
||||
"time"
|
||||
|
||||
"github.com/aws/aws-sdk-go/aws"
|
||||
"github.com/aws/aws-sdk-go/aws/awserr"
|
||||
"github.com/aws/aws-sdk-go/service/rds"
|
||||
"github.com/hashicorp/terraform/helper/hashcode"
|
||||
"github.com/hashicorp/terraform/helper/resource"
|
||||
"github.com/hashicorp/terraform/helper/schema"
|
||||
)
|
||||
|
||||
@ -278,11 +280,22 @@ func resourceAwsDbOptionGroupDelete(d *schema.ResourceData, meta interface{}) er
|
||||
}
|
||||
|
||||
log.Printf("[DEBUG] Delete DB Option Group: %#v", deleteOpts)
|
||||
_, err := rdsconn.DeleteOptionGroup(deleteOpts)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error Deleting DB Option Group: %s", err)
|
||||
ret := resource.Retry(1*time.Minute, func() *resource.RetryError {
|
||||
_, err := rdsconn.DeleteOptionGroup(deleteOpts)
|
||||
if err != nil {
|
||||
if awsErr, ok := err.(awserr.Error); ok {
|
||||
if awsErr.Code() == "InvalidOptionGroupStateFault" {
|
||||
log.Printf("[DEBUG] AWS believes the RDS Option Group is still in use, retrying")
|
||||
return resource.RetryableError(awsErr)
|
||||
}
|
||||
}
|
||||
return resource.NonRetryableError(err)
|
||||
}
|
||||
return nil
|
||||
})
|
||||
if ret != nil {
|
||||
return fmt.Errorf("Error Deleting DB Option Group: %s", ret)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -34,6 +34,21 @@ func TestAccAWSDBOptionGroup_basic(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
func TestAccAWSDBOptionGroup_basicDestroyWithInstance(t *testing.T) {
|
||||
rName := fmt.Sprintf("option-group-test-terraform-%s", acctest.RandString(5))
|
||||
|
||||
resource.Test(t, resource.TestCase{
|
||||
PreCheck: func() { testAccPreCheck(t) },
|
||||
Providers: testAccProviders,
|
||||
CheckDestroy: testAccCheckAWSDBOptionGroupDestroy,
|
||||
Steps: []resource.TestStep{
|
||||
resource.TestStep{
|
||||
Config: testAccAWSDBOptionGroupBasicDestroyConfig(rName),
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TestAccAWSDBOptionGroup_OptionSettings(t *testing.T) {
|
||||
var v rds.OptionGroup
|
||||
rName := fmt.Sprintf("option-group-test-terraform-%s", acctest.RandString(5))
|
||||
@ -259,6 +274,37 @@ resource "aws_db_option_group" "bar" {
|
||||
`, r)
|
||||
}
|
||||
|
||||
func testAccAWSDBOptionGroupBasicDestroyConfig(r string) string {
|
||||
return fmt.Sprintf(`
|
||||
resource "aws_db_instance" "bar" {
|
||||
allocated_storage = 10
|
||||
engine = "MySQL"
|
||||
engine_version = "5.6.21"
|
||||
instance_class = "db.t2.micro"
|
||||
name = "baz"
|
||||
password = "barbarbarbar"
|
||||
username = "foo"
|
||||
|
||||
|
||||
# Maintenance Window is stored in lower case in the API, though not strictly
|
||||
# documented. Terraform will downcase this to match (as opposed to throw a
|
||||
# validation error).
|
||||
maintenance_window = "Fri:09:00-Fri:09:30"
|
||||
|
||||
backup_retention_period = 0
|
||||
|
||||
option_group_name = "${aws_db_option_group.bar.name}"
|
||||
}
|
||||
|
||||
resource "aws_db_option_group" "bar" {
|
||||
name = "%s"
|
||||
option_group_description = "Test option group for terraform"
|
||||
engine_name = "mysql"
|
||||
major_engine_version = "5.6"
|
||||
}
|
||||
`, r)
|
||||
}
|
||||
|
||||
func testAccAWSDBOptionGroupOptionSettings(r string) string {
|
||||
return fmt.Sprintf(`
|
||||
resource "aws_db_option_group" "bar" {
|
||||
|
Loading…
Reference in New Issue
Block a user