mirror of
https://github.com/opentofu/opentofu.git
synced 2025-01-10 08:03:08 -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"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/aws/aws-sdk-go/aws"
|
"github.com/aws/aws-sdk-go/aws"
|
||||||
"github.com/aws/aws-sdk-go/aws/awserr"
|
"github.com/aws/aws-sdk-go/aws/awserr"
|
||||||
"github.com/aws/aws-sdk-go/service/rds"
|
"github.com/aws/aws-sdk-go/service/rds"
|
||||||
"github.com/hashicorp/terraform/helper/hashcode"
|
"github.com/hashicorp/terraform/helper/hashcode"
|
||||||
|
"github.com/hashicorp/terraform/helper/resource"
|
||||||
"github.com/hashicorp/terraform/helper/schema"
|
"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)
|
log.Printf("[DEBUG] Delete DB Option Group: %#v", deleteOpts)
|
||||||
_, err := rdsconn.DeleteOptionGroup(deleteOpts)
|
ret := resource.Retry(1*time.Minute, func() *resource.RetryError {
|
||||||
if err != nil {
|
_, err := rdsconn.DeleteOptionGroup(deleteOpts)
|
||||||
return fmt.Errorf("Error Deleting DB Option Group: %s", err)
|
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
|
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) {
|
func TestAccAWSDBOptionGroup_OptionSettings(t *testing.T) {
|
||||||
var v rds.OptionGroup
|
var v rds.OptionGroup
|
||||||
rName := fmt.Sprintf("option-group-test-terraform-%s", acctest.RandString(5))
|
rName := fmt.Sprintf("option-group-test-terraform-%s", acctest.RandString(5))
|
||||||
@ -259,6 +274,37 @@ resource "aws_db_option_group" "bar" {
|
|||||||
`, r)
|
`, 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 {
|
func testAccAWSDBOptionGroupOptionSettings(r string) string {
|
||||||
return fmt.Sprintf(`
|
return fmt.Sprintf(`
|
||||||
resource "aws_db_option_group" "bar" {
|
resource "aws_db_option_group" "bar" {
|
||||||
|
Loading…
Reference in New Issue
Block a user