Skip to content

Commit

Permalink
Merge pull request #39543 from hashicorp/s-appfabric
Browse files Browse the repository at this point in the history
appfabric: Add sweepers
  • Loading branch information
ewbankkit authored Sep 30, 2024
2 parents 3b52512 + e2c1af1 commit 42be262
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 0 deletions.
82 changes: 82 additions & 0 deletions internal/service/appfabric/sweep.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0

package appfabric

import (
"context"

"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/appfabric"
"github.com/hashicorp/terraform-provider-aws/internal/conns"
"github.com/hashicorp/terraform-provider-aws/internal/sweep"
"github.com/hashicorp/terraform-provider-aws/internal/sweep/awsv2"
"github.com/hashicorp/terraform-provider-aws/internal/sweep/framework"
"github.com/hashicorp/terraform-provider-aws/names"
)

func RegisterSweepers() {
awsv2.Register("aws_appfabric_app_bundle", sweepAppBundles, "aws_appfabric_app_authorization")
awsv2.Register("aws_appfabric_app_authorization", sweepAppAuthorizations)
}

func sweepAppBundles(ctx context.Context, client *conns.AWSClient) ([]sweep.Sweepable, error) {
conn := client.AppFabricClient(ctx)
input := &appfabric.ListAppBundlesInput{}
var sweepResources []sweep.Sweepable

pages := appfabric.NewListAppBundlesPaginator(conn, input)
for pages.HasMorePages() {
page, err := pages.NextPage(ctx)

if err != nil {
return nil, err
}

for _, v := range page.AppBundleSummaryList {
sweepResources = append(sweepResources, framework.NewSweepResource(newAppBundleResource, client,
framework.NewAttribute(names.AttrID, aws.ToString(v.Arn))))
}
}

return sweepResources, nil
}

func sweepAppAuthorizations(ctx context.Context, client *conns.AWSClient) ([]sweep.Sweepable, error) {
conn := client.AppFabricClient(ctx)
input := &appfabric.ListAppBundlesInput{}
var sweepResources []sweep.Sweepable

pages := appfabric.NewListAppBundlesPaginator(conn, input)
for pages.HasMorePages() {
page, err := pages.NextPage(ctx)

if err != nil {
return nil, err
}

for _, v := range page.AppBundleSummaryList {
appBundleARN := aws.ToString(v.Arn)
input := &appfabric.ListAppAuthorizationsInput{
AppBundleIdentifier: aws.String(appBundleARN),
}

pages := appfabric.NewListAppAuthorizationsPaginator(conn, input)
for pages.HasMorePages() {
page, err := pages.NextPage(ctx)

if err != nil {
return nil, err
}

for _, v := range page.AppAuthorizationSummaryList {
sweepResources = append(sweepResources, framework.NewSweepResource(newAppAuthorizationResource, client,
framework.NewAttribute("app_bundle_arn", appBundleARN),
framework.NewAttribute(names.AttrARN, aws.ToString(v.AppAuthorizationArn))))
}
}
}
}

return sweepResources, nil
}
1 change: 1 addition & 0 deletions internal/sweep/awsv2/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,6 @@ func Register(name string, f sweep.SweeperFn, dependencies ...string) {

return nil
},
Dependencies: dependencies,
})
}
2 changes: 2 additions & 0 deletions internal/sweep/register_gen_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 42be262

Please sign in to comment.