44package cloudfront
55
66import (
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
811800func sweepVPCOrigins (region string ) error {
0 commit comments