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

Sweeper: Add sweeper for aws_dms_replication_task #21554

Merged
merged 2 commits into from
Nov 5, 2021
Merged
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion GNUmakefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
SWEEP?=us-east-1,us-east-2,us-west-2
SWEEP?=us-west-2,us-east-1,us-east-2
TEST?=./...
SWEEP_DIR?=./internal/sweep
PKG_NAME=internal
Expand All @@ -16,6 +16,7 @@ gen:
go generate ./...

sweep:
# make sweep SWEEPARGS=-sweep-run=aws_example_thing
@echo "WARNING: This will destroy infrastructure. Use only in development accounts."
go test $(SWEEP_DIR) -v -tags=sweep -sweep=$(SWEEP) $(SWEEPARGS) -timeout 60m

Expand Down
51 changes: 51 additions & 0 deletions internal/service/dms/sweep.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ func init() {
resource.AddTestSweepers("aws_dms_replication_instance", &resource.Sweeper{
Name: "aws_dms_replication_instance",
F: sweepReplicationInstances,
Dependencies: []string{
"aws_dms_replication_task",
},
})

resource.AddTestSweepers("aws_dms_replication_task", &resource.Sweeper{
Name: "aws_dms_replication_task",
F: sweepReplicationTasks,
})
}

Expand Down Expand Up @@ -61,3 +69,46 @@ func sweepReplicationInstances(region string) error {

return errs.ErrorOrNil()
}

func sweepReplicationTasks(region string) error {
client, err := sweep.SharedRegionalSweepClient(region)

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

conn := client.(*conns.AWSClient).DMSConn
sweepResources := make([]*sweep.SweepResource, 0)
var errs *multierror.Error

input := &dms.DescribeReplicationTasksInput{
WithoutSettings: aws.Bool(true),
}
err = conn.DescribeReplicationTasksPages(input, func(page *dms.DescribeReplicationTasksOutput, lastPage bool) bool {
for _, instance := range page.ReplicationTasks {
r := ResourceReplicationTask()
d := r.Data(nil)
d.SetId(aws.StringValue(instance.ReplicationTaskIdentifier))
d.Set("replication_task_arn", instance.ReplicationTaskArn)

sweepResources = append(sweepResources, sweep.NewSweepResource(r, d, client))
}

return !lastPage
})

if err != nil {
errs = multierror.Append(errs, fmt.Errorf("error describing DMS Replication Tasks: %w", err))
}

if err = sweep.SweepOrchestrator(sweepResources); err != nil {
errs = multierror.Append(errs, fmt.Errorf("error sweeping DMS Replication Tasks for %s: %w", region, err))
}

if sweep.SkipSweepError(errs.ErrorOrNil()) {
log.Printf("[WARN] Skipping DMS Replication Instance sweep for %s: %s", region, err)
return nil
}

return errs.ErrorOrNil()
}
1 change: 1 addition & 0 deletions internal/service/ec2/sweep.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ func init() {
"aws_cloudhsm_v2_cluster",
"aws_db_subnet_group",
"aws_directory_service_directory",
"aws_dms_replication_instance",
"aws_ec2_client_vpn_endpoint",
"aws_ec2_transit_gateway_vpc_attachment",
"aws_efs_file_system",
Expand Down