Skip to content

Commit

Permalink
Merge pull request #21554 from hashicorp/dms_sweeper
Browse files Browse the repository at this point in the history
Sweeper: Add sweeper for `aws_dms_replication_task`
  • Loading branch information
gdavison authored Nov 5, 2021
2 parents 4bb3157 + 73bffbb commit de17e73
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 1 deletion.
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

0 comments on commit de17e73

Please sign in to comment.