-
Notifications
You must be signed in to change notification settings - Fork 9.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #39543 from hashicorp/s-appfabric
appfabric: Add sweepers
- Loading branch information
Showing
3 changed files
with
85 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.