@@ -10,19 +10,16 @@ import (
1010
1111 "github.com/aws/aws-sdk-go-v2/aws"
1212 "github.com/aws/aws-sdk-go-v2/aws/arn"
13- "github.com/aws/aws-sdk-go-v2/service/cloudfront"
14- cftypes "github.com/aws/aws-sdk-go-v2/service/cloudfront/types"
1513 "github.com/aws/aws-sdk-go-v2/service/wafv2"
1614 awstypes "github.com/aws/aws-sdk-go-v2/service/wafv2/types"
1715 "github.com/hashicorp/terraform-plugin-sdk/v2/diag"
18- "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry"
16+ sdkretry "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry"
1917 "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
2018 "github.com/hashicorp/terraform-provider-aws/internal/conns"
2119 "github.com/hashicorp/terraform-provider-aws/internal/enum"
22- "github.com/hashicorp/terraform-provider-aws/internal/errs"
2320 "github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag"
24- pretry "github.com/hashicorp/terraform-provider-aws/internal/retry"
25- "github.com/hashicorp/terraform-provider-aws/internal/tfresource "
21+ "github.com/hashicorp/terraform-provider-aws/internal/retry"
22+ tfcloudfront "github.com/hashicorp/terraform-provider-aws/internal/service/cloudfront "
2623 "github.com/hashicorp/terraform-provider-aws/internal/verify"
2724 "github.com/hashicorp/terraform-provider-aws/names"
2825)
@@ -83,7 +80,7 @@ func dataSourceWebACLRead(ctx context.Context, d *schema.ResourceData, meta any)
8380 webACL , err = findWebACLByResourceARN (ctx , conn , resourceArn )
8481 }
8582 if err != nil {
86- if pretry .NotFound (err ) {
83+ if retry .NotFound (err ) {
8784 return sdkdiag .AppendErrorf (diags , "WAFv2 WebACL not found for resource_arn: %s" , resourceArn )
8885 }
8986 return sdkdiag .AppendErrorf (diags , "reading WAFv2 WebACL for resource_arn (%s): %s" , resourceArn , err )
@@ -159,32 +156,15 @@ func findWebACLByCloudFrontDistributionARN(ctx context.Context, client *conns.AW
159156 return nil , err
160157 }
161158
162- // Get CloudFront client
163- cfConn := client .CloudFrontClient (ctx )
159+ output , err := tfcloudfront .FindDistributionByID (ctx , client .CloudFrontClient (ctx ), distributionID )
164160
165- // Get distribution configuration
166- input := & cloudfront.GetDistributionInput {
167- Id : aws .String (distributionID ),
168- }
169-
170- output , err := cfConn .GetDistribution (ctx , input )
171161 if err != nil {
172- if errs.IsA [* cftypes.NoSuchDistribution ](err ) {
173- return nil , & retry.NotFoundError {
174- LastError : err ,
175- LastRequest : input ,
176- }
177- }
178162 return nil , fmt .Errorf ("getting CloudFront distribution (%s): %w" , distributionID , err )
179163 }
180164
181- if output .Distribution == nil || output .Distribution .DistributionConfig == nil {
182- return nil , tfresource .NewEmptyResultError (input )
183- }
184-
185165 webACLARN := aws .ToString (output .Distribution .DistributionConfig .WebACLId )
186166 if webACLARN == "" {
187- return nil , & retry .NotFoundError {
167+ return nil , & sdkretry .NotFoundError {
188168 Message : fmt .Sprintf ("no WebACL associated with CloudFront distribution: %s" , distributionID ),
189169 }
190170 }
@@ -212,7 +192,7 @@ func findWebACLByCloudFrontDistributionARN(ctx context.Context, client *conns.AW
212192 return nil , fmt .Errorf ("finding WAFv2 WebACL (%s): %w" , webACLARN , err )
213193 }
214194 if webACLOut == nil {
215- return nil , & retry .NotFoundError {
195+ return nil , & sdkretry .NotFoundError {
216196 Message : fmt .Sprintf ("no WAFv2 WebACL found: %s" , webACLARN ),
217197 }
218198 }
0 commit comments