Skip to content

Commit b5923f3

Browse files
committed
r/aws_cloudfront_trust_store: Tidy up.
1 parent 24e6626 commit b5923f3

File tree

6 files changed

+210
-303
lines changed

6 files changed

+210
-303
lines changed

internal/service/cloudfront/exports_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ var (
1919
ResourcePublicKey = resourcePublicKey
2020
ResourceRealtimeLogConfig = resourceRealtimeLogConfig
2121
ResourceResponseHeadersPolicy = resourceResponseHeadersPolicy
22-
ResourceTrustStore = newResourceTrustStore
22+
ResourceTrustStore = newTrustStoreResource
2323
ResourceVPCOrigin = newVPCOriginResource
2424

2525
FindCachePolicyByID = findCachePolicyByID
@@ -38,5 +38,6 @@ var (
3838
FindResponseHeadersPolicyByID = findResponseHeadersPolicyByID
3939
FindTrustStoreByID = findTrustStoreByID
4040
FindVPCOriginByID = findVPCOriginByID
41-
WaitDistributionDeployed = waitDistributionDeployed
41+
42+
WaitDistributionDeployed = waitDistributionDeployed
4243
)

internal/service/cloudfront/service_package_gen.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/service/cloudfront/sweep.go

Lines changed: 20 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
package cloudfront
55

66
import (
7+
"context"
78
"errors"
89
"fmt"
910
"log"
@@ -12,10 +13,12 @@ import (
1213
"github.com/aws/aws-sdk-go-v2/service/cloudfront"
1314
awstypes "github.com/aws/aws-sdk-go-v2/service/cloudfront/types"
1415
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
16+
"github.com/hashicorp/terraform-provider-aws/internal/conns"
1517
"github.com/hashicorp/terraform-provider-aws/internal/retry"
1618
"github.com/hashicorp/terraform-provider-aws/internal/sweep"
1719
"github.com/hashicorp/terraform-provider-aws/internal/sweep/awsv2"
1820
"github.com/hashicorp/terraform-provider-aws/internal/sweep/framework"
21+
sweepfw "github.com/hashicorp/terraform-provider-aws/internal/sweep/framework"
1922
"github.com/hashicorp/terraform-provider-aws/names"
2023
)
2124

@@ -99,13 +102,7 @@ func RegisterSweepers() {
99102
},
100103
})
101104

102-
resource.AddTestSweepers("aws_cloudfront_trust_store", &resource.Sweeper{
103-
Name: "aws_cloudfront_trust_store",
104-
F: sweepTrustStoresWrapper,
105-
Dependencies: []string{
106-
"aws_cloudfront_distribution",
107-
},
108-
})
105+
awsv2.Register("aws_cloudfront_trust_store", sweepTrustStores, "aws_cloudfront_distribution")
109106

110107
resource.AddTestSweepers("aws_cloudfront_vpc_origin", &resource.Sweeper{
111108
Name: "aws_cloudfront_vpc_origin",
@@ -778,34 +775,26 @@ func sweepOriginAccessControls(region string) error {
778775
return nil
779776
}
780777

781-
func sweepTrustStoresWrapper(region string) error {
782-
ctx := sweep.Context(region)
783-
client, err := sweep.SharedRegionalSweepClient(ctx, region)
784-
if err != nil {
785-
return fmt.Errorf("getting client: %w", err)
786-
}
787-
788-
sweepResources, err := sweepTrustStores(ctx, client)
789-
if err != nil {
790-
return err
791-
}
792-
793-
if awsv2.SkipSweepError(err) {
794-
log.Printf("[WARN] Skipping CloudFront Trust Store sweep for %s: %s", region, err)
795-
return nil
796-
}
797-
798-
if err != nil {
799-
return fmt.Errorf("error listing CloudFront Trust Stores (%s): %w", region, err)
800-
}
778+
func sweepTrustStores(ctx context.Context, client *conns.AWSClient) ([]sweep.Sweepable, error) {
779+
input := cloudfront.ListTrustStoresInput{}
780+
conn := client.CloudFrontClient(ctx)
781+
var sweepResources []sweep.Sweepable
801782

802-
err = sweep.SweepOrchestrator(ctx, sweepResources)
783+
pages := cloudfront.NewListTrustStoresPaginator(conn, &input)
784+
for pages.HasMorePages() {
785+
page, err := pages.NextPage(ctx)
786+
if err != nil {
787+
return nil, err
788+
}
803789

804-
if err != nil {
805-
return fmt.Errorf("error sweeping CloudFront Trust Stores (%s): %w", region, err)
790+
for _, v := range page.TrustStoreList {
791+
sweepResources = append(sweepResources, sweepfw.NewSweepResource(newTrustStoreResource, client,
792+
sweepfw.NewAttribute(names.AttrID, aws.ToString(v.Id)),
793+
))
794+
}
806795
}
807796

808-
return nil
797+
return sweepResources, nil
809798
}
810799

811800
func sweepVPCOrigins(region string) error {

0 commit comments

Comments
 (0)