From e2c1af12d960cdc03398f1d8f80a506a3c30813e Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Mon, 30 Sep 2024 15:14:10 -0400 Subject: [PATCH] r/aws_appfabric_app_authorization: Add sweeper. --- internal/service/appfabric/sweep.go | 42 ++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/internal/service/appfabric/sweep.go b/internal/service/appfabric/sweep.go index d9206bcfb1e..6694a7f6096 100644 --- a/internal/service/appfabric/sweep.go +++ b/internal/service/appfabric/sweep.go @@ -16,7 +16,8 @@ import ( ) func RegisterSweepers() { - awsv2.Register("aws_appfabric_app_bundle", sweepAppBundles) + 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) { @@ -40,3 +41,42 @@ func sweepAppBundles(ctx context.Context, client *conns.AWSClient) ([]sweep.Swee 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 +}