Skip to content

Commit

Permalink
Merge pull request hashicorp#32076 from hashicorp/td-sweep-framework
Browse files Browse the repository at this point in the history
Sweepers: Separates Framework- and SDK-related sweeper functions
  • Loading branch information
gdavison authored Jun 21, 2023
2 parents f7f8d9d + c29444f commit b3dc32e
Show file tree
Hide file tree
Showing 147 changed files with 849 additions and 961 deletions.
8 changes: 4 additions & 4 deletions docs/running-and-writing-acceptance-tests.md
Original file line number Diff line number Diff line change
Expand Up @@ -1129,7 +1129,7 @@ func sweepThings(region string) error {
return fmt.Errorf("getting client: %w", err)
}
conn := client.(*conns.AWSClient).ExampleConn(ctx)
conn := client.ExampleConn(ctx)
sweepResources := make([]sweep.Sweepable, 0)
var errs *multierror.Error
Expand All @@ -1150,7 +1150,7 @@ func sweepThings(region string) error {
// Perform resource specific pre-sweep setup.
// For example, you may need to perform one or more of these types of pre-sweep tasks, specific to the resource:
//
// err := sweep.ReadResource(ctx, r, d, client) // fill in data
// err := sdk.ReadResource(ctx, r, d, client) // fill in data
// d.Set("skip_final_snapshot", true) // set an argument in order to delete
// This "if" is only needed if the pre-sweep setup can produce errors.
Expand Down Expand Up @@ -1196,7 +1196,7 @@ func sweepThings(region string) error {
return fmt.Errorf("getting client: %w", err)
}
conn := client.(*conns.AWSClient).ExampleConn(ctx)
conn := client.ExampleConn(ctx)
sweepResources := make([]sweep.Sweepable, 0)
var errs *multierror.Error
Expand All @@ -1215,7 +1215,7 @@ func sweepThings(region string) error {
// Perform resource specific pre-sweep setup.
// For example, you may need to perform one or more of these types of pre-sweep tasks, specific to the resource:
//
// err := sweep.ReadResource(ctx, r, d, client) // fill in data
// err := sdk.ReadResource(ctx, r, d, client) // fill in data
// d.Set("skip_final_snapshot", true) // set an argument in order to delete
// This "if" is only needed if the pre-sweep setup can produce errors.
Expand Down
2 changes: 0 additions & 2 deletions internal/generate/sweepimp/file.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@ import (
{{- range .Services }}
_ "github.com/hashicorp/terraform-provider-aws/internal/service/{{ .ProviderPackage }}"
{{- end }}
"github.com/hashicorp/terraform-provider-aws/internal/sweep"
)

func TestMain(m *testing.M) {
sweep.SweeperClients = make(map[string]interface{})
resource.TestMain(m)
}
3 changes: 1 addition & 2 deletions internal/service/accessanalyzer/sweep.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/accessanalyzer"
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
"github.com/hashicorp/terraform-provider-aws/internal/conns"
"github.com/hashicorp/terraform-provider-aws/internal/sweep"
)

Expand All @@ -27,7 +26,7 @@ func sweepAnalyzers(region string) error {
if err != nil {
return fmt.Errorf("getting client: %s", err)
}
conn := client.(*conns.AWSClient).AccessAnalyzerClient(ctx)
conn := client.AccessAnalyzerClient(ctx)
input := &accessanalyzer.ListAnalyzersInput{}
sweepResources := make([]sweep.Sweepable, 0)

Expand Down
3 changes: 1 addition & 2 deletions internal/service/acm/sweep.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/acm"
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
"github.com/hashicorp/terraform-provider-aws/internal/conns"
"github.com/hashicorp/terraform-provider-aws/internal/sweep"
)

Expand Down Expand Up @@ -44,7 +43,7 @@ func sweepCertificates(region string) error {
if err != nil {
return fmt.Errorf("error getting client: %s", err)
}
conn := client.(*conns.AWSClient).ACMClient(ctx)
conn := client.ACMClient(ctx)
input := &acm.ListCertificatesInput{}
sweepResources := make([]sweep.Sweepable, 0)

Expand Down
3 changes: 1 addition & 2 deletions internal/service/acmpca/sweep.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"github.com/aws/aws-sdk-go/service/acmpca"
"github.com/hashicorp/go-multierror"
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
"github.com/hashicorp/terraform-provider-aws/internal/conns"
"github.com/hashicorp/terraform-provider-aws/internal/sweep"
)

Expand All @@ -29,7 +28,7 @@ func sweepCertificateAuthorities(region string) error {
return fmt.Errorf("error getting client: %w", err)
}

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

Expand Down
3 changes: 1 addition & 2 deletions internal/service/amplify/sweep.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/amplify"
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
"github.com/hashicorp/terraform-provider-aws/internal/conns"
"github.com/hashicorp/terraform-provider-aws/internal/sweep"
)

Expand All @@ -27,7 +26,7 @@ func sweepApps(region string) error {
if err != nil {
return fmt.Errorf("error getting client: %s", err)
}
conn := client.(*conns.AWSClient).AmplifyConn(ctx)
conn := client.AmplifyConn(ctx)
sweepResources := make([]sweep.Sweepable, 0)

input := &amplify.ListAppsInput{}
Expand Down
13 changes: 6 additions & 7 deletions internal/service/apigateway/sweep.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
"github.com/hashicorp/go-multierror"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry"
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
"github.com/hashicorp/terraform-provider-aws/internal/conns"
"github.com/hashicorp/terraform-provider-aws/internal/sweep"
)

Expand Down Expand Up @@ -59,7 +58,7 @@ func sweepRestAPIs(region string) error {
if err != nil {
return fmt.Errorf("getting client: %s", err)
}
conn := client.(*conns.AWSClient).APIGatewayConn(ctx)
conn := client.APIGatewayConn(ctx)

err = conn.GetRestApisPagesWithContext(ctx, &apigateway.GetRestApisInput{}, func(page *apigateway.GetRestApisOutput, lastPage bool) bool {
for _, item := range page.Items {
Expand Down Expand Up @@ -102,7 +101,7 @@ func sweepVPCLinks(region string) error {
if err != nil {
return fmt.Errorf("getting client: %w", err)
}
conn := client.(*conns.AWSClient).APIGatewayConn(ctx)
conn := client.APIGatewayConn(ctx)

sweepResources := make([]sweep.Sweepable, 0)
var sweeperErrs *multierror.Error
Expand Down Expand Up @@ -141,7 +140,7 @@ func sweepClientCertificates(region string) error {
return fmt.Errorf("getting client: %s", err)
}

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

Expand Down Expand Up @@ -186,7 +185,7 @@ func sweepUsagePlans(region string) error {

log.Printf("[INFO] Sweeping API Gateway Usage Plans for %s", region)

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

Expand Down Expand Up @@ -234,7 +233,7 @@ func sweepAPIKeys(region string) error {

log.Printf("[INFO] Sweeping API Gateway API Keys for %s", region)

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

Expand Down Expand Up @@ -281,7 +280,7 @@ func sweepDomainNames(region string) error {

log.Printf("[INFO] Sweeping API Gateway Domain Names for %s", region)

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

Expand Down
9 changes: 4 additions & 5 deletions internal/service/apigatewayv2/sweep.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"github.com/aws/aws-sdk-go/service/apigatewayv2"
multierror "github.com/hashicorp/go-multierror"
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
"github.com/hashicorp/terraform-provider-aws/internal/conns"
"github.com/hashicorp/terraform-provider-aws/internal/sweep"
)

Expand Down Expand Up @@ -49,7 +48,7 @@ func sweepAPIs(region string) error {
if err != nil {
return fmt.Errorf("error getting client: %s", err)
}
conn := client.(*conns.AWSClient).APIGatewayV2Conn(ctx)
conn := client.APIGatewayV2Conn(ctx)
input := &apigatewayv2.GetApisInput{}
sweepResources := make([]sweep.Sweepable, 0)

Expand Down Expand Up @@ -93,7 +92,7 @@ func sweepAPIMappings(region string) error {
if err != nil {
return fmt.Errorf("error getting client: %w", err)
}
conn := client.(*conns.AWSClient).APIGatewayV2Conn(ctx)
conn := client.APIGatewayV2Conn(ctx)
var sweeperErrs *multierror.Error
sweepResources := make([]sweep.Sweepable, 0)

Expand Down Expand Up @@ -162,7 +161,7 @@ func sweepDomainNames(region string) error {
if err != nil {
return fmt.Errorf("error getting client: %w", err)
}
conn := client.(*conns.AWSClient).APIGatewayV2Conn(ctx)
conn := client.APIGatewayV2Conn(ctx)
input := &apigatewayv2.GetDomainNamesInput{}
sweepResources := make([]sweep.Sweepable, 0)

Expand Down Expand Up @@ -206,7 +205,7 @@ func sweepVPCLinks(region string) error {
if err != nil {
return fmt.Errorf("error getting client: %s", err)
}
conn := client.(*conns.AWSClient).APIGatewayV2Conn(ctx)
conn := client.APIGatewayV2Conn(ctx)
input := &apigatewayv2.GetVpcLinksInput{}
sweepResources := make([]sweep.Sweepable, 0)

Expand Down
24 changes: 9 additions & 15 deletions internal/service/appconfig/sweep.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import (
"github.com/aws/aws-sdk-go/service/appconfig"
"github.com/hashicorp/go-multierror"
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
"github.com/hashicorp/terraform-provider-aws/internal/conns"
"github.com/hashicorp/terraform-provider-aws/internal/sweep"
"github.com/hashicorp/terraform-provider-aws/internal/sweep/framework"
)

func init() {
Expand Down Expand Up @@ -58,7 +58,7 @@ func sweepApplications(region string) error {
return fmt.Errorf("error getting client: %w", err)
}

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

Expand Down Expand Up @@ -111,7 +111,7 @@ func sweepConfigurationProfiles(region string) error {
return fmt.Errorf("error getting client: %w", err)
}

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

Expand Down Expand Up @@ -188,7 +188,7 @@ func sweepDeploymentStrategies(region string) error {
return fmt.Errorf("error getting client: %w", err)
}

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

Expand Down Expand Up @@ -247,7 +247,7 @@ func sweepEnvironments(region string) error {
return fmt.Errorf("error getting client: %w", err)
}

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

Expand Down Expand Up @@ -279,15 +279,9 @@ func sweepEnvironments(region string) error {
continue
}

sweepResources = append(sweepResources, sweep.NewSweepFrameworkResource(newResourceEnvironment, "", client,
sweep.FrameworkSupplementalAttribute{
Path: "application_id",
Value: aws.StringValue(item.ApplicationId),
},
sweep.FrameworkSupplementalAttribute{
Path: "environment_id",
Value: aws.StringValue(item.Id),
},
sweepResources = append(sweepResources, framework.NewSweepResource(newResourceEnvironment, client,
framework.NewAttribute("application_id", aws.StringValue(item.ApplicationId)),
framework.NewAttribute("environment_id", aws.StringValue(item.Id)),
))
}

Expand Down Expand Up @@ -326,7 +320,7 @@ func sweepHostedConfigurationVersions(region string) error {
return fmt.Errorf("error getting client: %w", err)
}

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

Expand Down
3 changes: 1 addition & 2 deletions internal/service/applicationinsights/sweep.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"github.com/aws/aws-sdk-go/service/applicationinsights"
"github.com/hashicorp/go-multierror"
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
"github.com/hashicorp/terraform-provider-aws/internal/conns"
"github.com/hashicorp/terraform-provider-aws/internal/sweep"
)

Expand All @@ -30,7 +29,7 @@ func sweepApplications(region string) error {
return fmt.Errorf("error getting client: %s", err)
}

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

Expand Down
15 changes: 7 additions & 8 deletions internal/service/appmesh/sweep.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"github.com/aws/aws-sdk-go/service/appmesh"
multierror "github.com/hashicorp/go-multierror"
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
"github.com/hashicorp/terraform-provider-aws/internal/conns"
"github.com/hashicorp/terraform-provider-aws/internal/sweep"
)

Expand Down Expand Up @@ -70,7 +69,7 @@ func sweepMeshes(region string) error {
if err != nil {
return fmt.Errorf("error getting client: %s", err)
}
conn := client.(*conns.AWSClient).AppMeshConn(ctx)
conn := client.AppMeshConn(ctx)
input := &appmesh.ListMeshesInput{}
sweepResources := make([]sweep.Sweepable, 0)

Expand Down Expand Up @@ -114,7 +113,7 @@ func sweepVirtualGateways(region string) error {
if err != nil {
return fmt.Errorf("error getting client: %w", err)
}
conn := client.(*conns.AWSClient).AppMeshConn(ctx)
conn := client.AppMeshConn(ctx)
var sweeperErrs *multierror.Error
sweepResources := make([]sweep.Sweepable, 0)

Expand Down Expand Up @@ -185,7 +184,7 @@ func sweepVirtualNodes(region string) error {
if err != nil {
return fmt.Errorf("error getting client: %w", err)
}
conn := client.(*conns.AWSClient).AppMeshConn(ctx)
conn := client.AppMeshConn(ctx)
input := &appmesh.ListMeshesInput{}
var sweeperErrs *multierror.Error
sweepResources := make([]sweep.Sweepable, 0)
Expand Down Expand Up @@ -256,7 +255,7 @@ func sweepVirtualRouters(region string) error {
if err != nil {
return fmt.Errorf("error getting client: %s", err)
}
conn := client.(*conns.AWSClient).AppMeshConn(ctx)
conn := client.AppMeshConn(ctx)
input := &appmesh.ListMeshesInput{}
var sweeperErrs *multierror.Error
sweepResources := make([]sweep.Sweepable, 0)
Expand Down Expand Up @@ -327,7 +326,7 @@ func sweepVirtualServices(region string) error {
if err != nil {
return fmt.Errorf("error getting client: %s", err)
}
conn := client.(*conns.AWSClient).AppMeshConn(ctx)
conn := client.AppMeshConn(ctx)
input := &appmesh.ListMeshesInput{}
var sweeperErrs *multierror.Error
sweepResources := make([]sweep.Sweepable, 0)
Expand Down Expand Up @@ -398,7 +397,7 @@ func sweepGatewayRoutes(region string) error {
if err != nil {
return fmt.Errorf("error getting client: %w", err)
}
conn := client.(*conns.AWSClient).AppMeshConn(ctx)
conn := client.AppMeshConn(ctx)
input := &appmesh.ListMeshesInput{}
var sweeperErrs *multierror.Error
sweepResources := make([]sweep.Sweepable, 0)
Expand Down Expand Up @@ -494,7 +493,7 @@ func sweepRoutes(region string) error {
if err != nil {
return fmt.Errorf("error getting client: %s", err)
}
conn := client.(*conns.AWSClient).AppMeshConn(ctx)
conn := client.AppMeshConn(ctx)
input := &appmesh.ListMeshesInput{}
var sweeperErrs *multierror.Error
sweepResources := make([]sweep.Sweepable, 0)
Expand Down
Loading

0 comments on commit b3dc32e

Please sign in to comment.