diff --git a/GNUmakefile b/GNUmakefile index 408d8891e08..bafced17bbb 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -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 @@ -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 diff --git a/internal/service/dms/sweep.go b/internal/service/dms/sweep.go index 967cf780646..b81f4f8a899 100644 --- a/internal/service/dms/sweep.go +++ b/internal/service/dms/sweep.go @@ -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, }) } @@ -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() +} diff --git a/internal/service/ec2/sweep.go b/internal/service/ec2/sweep.go index c9168ffc501..a19910a6565 100644 --- a/internal/service/ec2/sweep.go +++ b/internal/service/ec2/sweep.go @@ -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",