-
Notifications
You must be signed in to change notification settings - Fork 9.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
r/aws_scheduler_schedule_group: add sweeper
- Loading branch information
Showing
2 changed files
with
74 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
//go:build sweep | ||
// +build sweep | ||
|
||
package scheduler | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"log" | ||
|
||
"github.com/aws/aws-sdk-go-v2/aws" | ||
"github.com/aws/aws-sdk-go-v2/service/scheduler" | ||
"github.com/hashicorp/go-multierror" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
"github.com/hashicorp/terraform-provider-aws/internal/conns" | ||
"github.com/hashicorp/terraform-provider-aws/internal/sweep" | ||
) | ||
|
||
func init() { | ||
resource.AddTestSweepers("aws_scheduler_schedule_group", &resource.Sweeper{ | ||
Name: "aws_scheduler_schedule_group", | ||
F: sweepScheduleGroups, | ||
}) | ||
} | ||
|
||
func sweepScheduleGroups(region string) error { | ||
client, err := sweep.SharedRegionalSweepClient(region) | ||
|
||
if err != nil { | ||
return fmt.Errorf("getting client: %w", err) | ||
} | ||
|
||
conn := client.(*conns.AWSClient).SchedulerClient | ||
sweepResources := make([]sweep.Sweepable, 0) | ||
var errs *multierror.Error | ||
|
||
paginator := scheduler.NewListScheduleGroupsPaginator(conn, &scheduler.ListScheduleGroupsInput{}) | ||
|
||
for paginator.HasMorePages() { | ||
page, err := paginator.NextPage(context.Background()) | ||
|
||
if err != nil { | ||
errs = multierror.Append(errs, fmt.Errorf("listing Schedule Groups for %s: %w", region, err)) | ||
break | ||
} | ||
|
||
for _, it := range page.ScheduleGroups { | ||
name := aws.ToString(it.Name) | ||
|
||
if name == "default" { | ||
// Can't delete the default schedule group. | ||
continue | ||
} | ||
|
||
r := ResourceScheduleGroup() | ||
d := r.Data(nil) | ||
d.SetId(name) | ||
|
||
sweepResources = append(sweepResources, sweep.NewSweepResource(r, d, client)) | ||
} | ||
} | ||
|
||
if err := sweep.SweepOrchestrator(sweepResources); err != nil { | ||
errs = multierror.Append(errs, fmt.Errorf("sweeping Schedule Group for %s: %w", region, err)) | ||
} | ||
|
||
if sweep.SkipSweepError(err) { | ||
log.Printf("[WARN] Skipping Schedule Group sweep for %s: %s", region, errs) | ||
return nil | ||
} | ||
|
||
return errs.ErrorOrNil() | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.