Skip to content

Commit

Permalink
Merge pull request #9275 from terraform-providers/t-aws_db_parameter_…
Browse files Browse the repository at this point in the history
…group-sweeper

tests/resource/aws_db_parameter_group: Add sweeper
  • Loading branch information
bflad authored Jul 12, 2019
2 parents fe7052b + 8c941c9 commit 2dd7311
Showing 1 changed file with 60 additions and 0 deletions.
60 changes: 60 additions & 0 deletions aws/resource_aws_db_parameter_group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ package aws

import (
"fmt"
"log"
"math/rand"
"regexp"
"strings"
"testing"
"time"

Expand All @@ -15,6 +17,64 @@ import (
"github.com/hashicorp/terraform/terraform"
)

func init() {
resource.AddTestSweepers("aws_db_parameter_group", &resource.Sweeper{
Name: "aws_db_parameter_group",
F: testSweepRdsDbParameterGroups,
Dependencies: []string{
"aws_db_instance",
},
})
}

func testSweepRdsDbParameterGroups(region string) error {
client, err := sharedClientForRegion(region)
if err != nil {
return fmt.Errorf("error getting client: %s", err)
}
conn := client.(*AWSClient).rdsconn

err = conn.DescribeDBParameterGroupsPages(&rds.DescribeDBParameterGroupsInput{}, func(out *rds.DescribeDBParameterGroupsOutput, lastPage bool) bool {
for _, dbpg := range out.DBParameterGroups {
if dbpg == nil {
continue
}

input := &rds.DeleteDBParameterGroupInput{
DBParameterGroupName: dbpg.DBParameterGroupName,
}
name := aws.StringValue(dbpg.DBParameterGroupName)

if strings.HasPrefix(name, "default.") {
log.Printf("[INFO] Skipping DB Parameter Group: %s", name)
continue
}

log.Printf("[INFO] Deleting DB Parameter Group: %s", name)

_, err := conn.DeleteDBParameterGroup(input)

if err != nil {
log.Printf("[ERROR] Failed to delete DB Parameter Group %s: %s", name, err)
continue
}
}

return !lastPage
})

if testSweepSkipSweepError(err) {
log.Printf("[WARN] Skipping RDS DB Parameter Group sweep for %s: %s", region, err)
return nil
}

if err != nil {
return fmt.Errorf("error retrieving DB Parameter Groups: %s", err)
}

return nil
}

func TestAccAWSDBParameterGroup_importBasic(t *testing.T) {
resourceName := "aws_db_parameter_group.bar"
groupName := fmt.Sprintf("parameter-group-test-terraform-%d", acctest.RandInt())
Expand Down

0 comments on commit 2dd7311

Please sign in to comment.