Skip to content

Commit 6d62972

Browse files
authored
Merge pull request #38144 from hashicorp/td-m2-sweepers
Adds sweepers for M2
2 parents de37754 + bc7c539 commit 6d62972

File tree

6 files changed

+93
-4
lines changed

6 files changed

+93
-4
lines changed

internal/service/efs/sweep.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ func RegisterSweepers() {
2727
Dependencies: []string{
2828
"aws_efs_mount_target",
2929
"aws_efs_access_point",
30+
"aws_m2_environment",
3031
},
3132
})
3233

internal/service/fsx/sweep.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ func RegisterSweepers() {
2626
F: sweepLustreFileSystems,
2727
Dependencies: []string{
2828
"aws_datasync_location",
29+
"aws_m2_environment",
2930
},
3031
})
3132

@@ -35,6 +36,7 @@ func RegisterSweepers() {
3536
Dependencies: []string{
3637
"aws_datasync_location",
3738
"aws_fsx_ontap_storage_virtual_machine",
39+
"aws_m2_environment",
3840
},
3941
})
4042

@@ -57,6 +59,7 @@ func RegisterSweepers() {
5759
Dependencies: []string{
5860
"aws_datasync_location",
5961
"aws_fsx_openzfs_volume",
62+
"aws_m2_environment",
6063
},
6164
})
6265

@@ -70,6 +73,7 @@ func RegisterSweepers() {
7073
F: sweepWindowsFileSystems,
7174
Dependencies: []string{
7275
"aws_datasync_location",
76+
"aws_m2_environment",
7377
"aws_storagegateway_file_system_association",
7478
},
7579
})

internal/service/m2/environment.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -568,10 +568,12 @@ func waitEnvironmentUpdated(ctx context.Context, conn *m2.Client, id string, tim
568568

569569
func waitEnvironmentDeleted(ctx context.Context, conn *m2.Client, id string, timeout time.Duration) (*m2.GetEnvironmentOutput, error) {
570570
stateConf := &retry.StateChangeConf{
571-
Pending: enum.Slice(awstypes.EnvironmentLifecycleAvailable, awstypes.EnvironmentLifecycleCreating, awstypes.EnvironmentLifecycleDeleting),
572-
Target: []string{},
573-
Refresh: statusEnvironment(ctx, conn, id),
574-
Timeout: timeout,
571+
Pending: enum.Slice(awstypes.EnvironmentLifecycleAvailable, awstypes.EnvironmentLifecycleCreating, awstypes.EnvironmentLifecycleDeleting),
572+
Target: []string{},
573+
Refresh: statusEnvironment(ctx, conn, id),
574+
Timeout: timeout,
575+
Delay: 4 * time.Minute,
576+
MinTimeout: 10 * time.Second,
575577
}
576578

577579
outputRaw, err := stateConf.WaitForStateContext(ctx)

internal/service/m2/sweep.go

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
// Copyright (c) HashiCorp, Inc.
2+
// SPDX-License-Identifier: MPL-2.0
3+
4+
package m2
5+
6+
import (
7+
"context"
8+
9+
"github.com/aws/aws-sdk-go-v2/aws"
10+
"github.com/aws/aws-sdk-go-v2/service/m2"
11+
"github.com/hashicorp/terraform-plugin-log/tflog"
12+
"github.com/hashicorp/terraform-provider-aws/internal/conns"
13+
"github.com/hashicorp/terraform-provider-aws/internal/sweep"
14+
"github.com/hashicorp/terraform-provider-aws/internal/sweep/awsv2"
15+
"github.com/hashicorp/terraform-provider-aws/internal/sweep/framework"
16+
"github.com/hashicorp/terraform-provider-aws/names"
17+
)
18+
19+
func RegisterSweepers() {
20+
sweep.Register("aws_m2_application", sweepApplications)
21+
22+
sweep.Register("aws_m2_environment", sweepEnvironments)
23+
}
24+
25+
func sweepApplications(ctx context.Context, client *conns.AWSClient) ([]sweep.Sweepable, error) {
26+
conn := client.M2Client(ctx)
27+
28+
var sweepResources []sweep.Sweepable
29+
30+
pages := m2.NewListApplicationsPaginator(conn, &m2.ListApplicationsInput{})
31+
for pages.HasMorePages() {
32+
page, err := pages.NextPage(ctx)
33+
if awsv2.SkipSweepError(err) {
34+
tflog.Warn(ctx, "Skipping sweeper", map[string]any{
35+
"error": err.Error(),
36+
})
37+
return nil, nil
38+
}
39+
if err != nil {
40+
return nil, err
41+
}
42+
43+
for _, application := range page.Applications {
44+
sweepResources = append(sweepResources, framework.NewSweepResource(newApplicationResource, client,
45+
framework.NewAttribute(names.AttrID, aws.ToString(application.ApplicationId))))
46+
}
47+
}
48+
49+
return sweepResources, nil
50+
}
51+
52+
func sweepEnvironments(ctx context.Context, client *conns.AWSClient) ([]sweep.Sweepable, error) {
53+
conn := client.M2Client(ctx)
54+
55+
var sweepResources []sweep.Sweepable
56+
57+
pages := m2.NewListEnvironmentsPaginator(conn, &m2.ListEnvironmentsInput{})
58+
for pages.HasMorePages() {
59+
page, err := pages.NextPage(ctx)
60+
if awsv2.SkipSweepError(err) {
61+
tflog.Warn(ctx, "Skipping sweeper", map[string]any{
62+
"error": err.Error(),
63+
})
64+
return nil, nil
65+
}
66+
if err != nil {
67+
return nil, err
68+
}
69+
70+
for _, environment := range page.Environments {
71+
sweepResources = append(sweepResources, framework.NewSweepResource(newEnvironmentResource, client,
72+
framework.NewAttribute(names.AttrID, aws.ToString(environment.EnvironmentId))))
73+
}
74+
}
75+
76+
return sweepResources, nil
77+
}

internal/service/s3/sweep.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ func RegisterSweepers() {
2929
resource.AddTestSweepers("aws_s3_object", &resource.Sweeper{
3030
Name: "aws_s3_object",
3131
F: sweepObjects,
32+
Dependencies: []string{
33+
"aws_m2_application",
34+
},
3235
})
3336

3437
resource.AddTestSweepers("aws_s3_bucket", &resource.Sweeper{

internal/sweep/register_gen_test.go

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)