Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests/r/redshift_cluser: Add sweeper concurrency #18576

Merged
merged 3 commits into from
Apr 7, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 28 additions & 15 deletions aws/resource_aws_redshift_cluster_test.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/aws/awserr"
"github.com/aws/aws-sdk-go/service/redshift"
multierror "github.com/hashicorp/go-multierror"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
Expand All @@ -25,39 +26,51 @@ func init() {

func testSweepRedshiftClusters(region string) error {
client, err := sharedClientForRegion(region)

if err != nil {
return fmt.Errorf("error getting client: %s", err)
}

conn := client.(*AWSClient).redshiftconn
sweepResources := make([]*testSweepResource, 0)
var errs *multierror.Error

err = conn.DescribeClustersPages(&redshift.DescribeClustersInput{}, func(resp *redshift.DescribeClustersOutput, isLast bool) bool {
if len(resp.Clusters) == 0 {
log.Print("[DEBUG] No Redshift clusters to sweep")
return false
return !isLast
}

for _, c := range resp.Clusters {
id := aws.StringValue(c.ClusterIdentifier)
r := resourceAwsRedshiftCluster()
d := r.Data(nil)
d.Set("skip_final_snapshot", true)
d.SetId(aws.StringValue(c.ClusterIdentifier))

input := &redshift.DeleteClusterInput{
ClusterIdentifier: c.ClusterIdentifier,
SkipFinalClusterSnapshot: aws.Bool(true),
}
_, err := conn.DeleteCluster(input)
if err != nil {
log.Printf("[ERROR] Failed deleting Redshift cluster (%s): %s", id, err)
}
sweepResources = append(sweepResources, NewTestSweepResource(r, d, client))
}

return !isLast
})

if err != nil {
if testSweepSkipSweepError(err) {
log.Printf("[WARN] Skipping Redshift Cluster sweep for %s: %s", region, err)
return nil
errs = multierror.Append(errs, fmt.Errorf("error describing Redshift Clusters: %w", err))
// in case work can be done, don't jump out yet
}

if len(sweepResources) > 0 {
// any errors didn't prevent gathering of some work, so do it
if err := testSweepResourceOrchestrator(sweepResources); err != nil {
errs = multierror.Append(errs, fmt.Errorf("error sweeping Redshift Clusters for %s: %w", region, err))
}
return fmt.Errorf("Error retrieving Redshift Clusters: %s", err)
}
return nil

if testSweepSkipSweepError(errs.ErrorOrNil()) {
log.Printf("[WARN] Skipping Redshift Cluster sweep for %s: %s", region, err)
return nil
}

return errs.ErrorOrNil()
}

func TestAccAWSRedshiftCluster_basic(t *testing.T) {
Expand Down