diff --git a/aws/resource_aws_waf_byte_match_set_test.go b/aws/resource_aws_waf_byte_match_set_test.go index d68ceaa8418..1ff3f417010 100644 --- a/aws/resource_aws_waf_byte_match_set_test.go +++ b/aws/resource_aws_waf_byte_match_set_test.go @@ -29,25 +29,27 @@ func init() { func testSweepWafByteMatchSet(region string) error { client, err := sharedClientForRegion(region) + if err != nil { return fmt.Errorf("error getting client: %s", err) } - conn := client.(*AWSClient).wafconn - var sweeperErrs *multierror.Error + conn := client.(*AWSClient).wafconn + sweepResources := make([]*testSweepResource, 0) + var errs *multierror.Error input := &waf.ListByteMatchSetsInput{} - err = lister.ListByteMatchSetsPages(conn, input, func(page *waf.ListByteMatchSetsOutput, lastPage bool) bool { + err = lister.ListByteMatchSetsPages(conn, input, func(page *waf.ListByteMatchSetsOutput, isLast bool) bool { if page == nil { - return !lastPage + return !isLast } for _, byteMatchSet := range page.ByteMatchSets { - id := aws.StringValue(byteMatchSet.ByteMatchSetId) - r := resourceAwsWafByteMatchSet() d := r.Data(nil) + + id := aws.StringValue(byteMatchSet.ByteMatchSetId) d.SetId(id) // Need to Read first to fill in byte_match_tuples attribute @@ -56,7 +58,7 @@ func testSweepWafByteMatchSet(region string) error { if err != nil { sweeperErr := fmt.Errorf("error reading WAF Byte Match Set (%s): %w", id, err) log.Printf("[ERROR] %s", sweeperErr) - sweeperErrs = multierror.Append(sweeperErrs, sweeperErr) + errs = multierror.Append(errs, sweeperErr) continue } @@ -65,29 +67,29 @@ func testSweepWafByteMatchSet(region string) error { continue } - err = r.Delete(d, client) - - if err != nil { - sweeperErr := fmt.Errorf("error deleting WAF Byte Match Set (%s): %w", id, err) - log.Printf("[ERROR] %s", sweeperErr) - sweeperErrs = multierror.Append(sweeperErrs, sweeperErr) - continue - } + sweepResources = append(sweepResources, NewTestSweepResource(r, d, client)) } - return !lastPage + return !isLast }) - if testSweepSkipSweepError(err) { - log.Printf("[WARN] Skipping WAF Byte Match Set sweep for %s: %s", region, err) - return sweeperErrs.ErrorOrNil() // In case we have completed some pages, but had errors + if err != nil { + errs = multierror.Append(errs, fmt.Errorf("error listing WAF Byte Match Set for %s: %w", region, err)) } - if err != nil { - sweeperErrs = multierror.Append(sweeperErrs, fmt.Errorf("error describing WAF Byte Match Sets: %w", err)) + if len(sweepResources) > 0 { + // Any errors didn't prevent gathering some sweeping work, so do it. + if err := testSweepResourceOrchestrator(sweepResources); err != nil { + errs = multierror.Append(errs, fmt.Errorf("error sweeping WAF Byte Match Set for %s: %w", region, err)) + } + } + + if testSweepSkipSweepError(errs.ErrorOrNil()) { + log.Printf("[WARN] Skipping WAF Byte Match Set sweep for %s: %s", region, errs) + return nil } - return sweeperErrs.ErrorOrNil() + return errs.ErrorOrNil() } func TestAccAWSWafByteMatchSet_basic(t *testing.T) {