From 213cb72cf76db750cf02396e62e58a6cccff2b43 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Fri, 23 Dec 2022 14:11:53 -0500 Subject: [PATCH] r/aws_s3control_object_lambda_access_point: Switch to 'WithoutTimeout' CRUD handlers (#15090). Acceptance test output: % make testacc TESTARGS='-run=TestAccS3ControlObjectLambdaAccessPoint_' PKG=s3control ACCTEST_PARALLELISM=3 ==> Checking that code complies with gofmt requirements... TF_ACC=1 go test ./internal/service/s3control/... -v -count 1 -parallel 3 -run=TestAccS3ControlObjectLambdaAccessPoint_ -timeout 180m === RUN TestAccS3ControlObjectLambdaAccessPoint_basic === PAUSE TestAccS3ControlObjectLambdaAccessPoint_basic === RUN TestAccS3ControlObjectLambdaAccessPoint_disappears === PAUSE TestAccS3ControlObjectLambdaAccessPoint_disappears === RUN TestAccS3ControlObjectLambdaAccessPoint_update === PAUSE TestAccS3ControlObjectLambdaAccessPoint_update === CONT TestAccS3ControlObjectLambdaAccessPoint_basic === CONT TestAccS3ControlObjectLambdaAccessPoint_update === CONT TestAccS3ControlObjectLambdaAccessPoint_disappears --- PASS: TestAccS3ControlObjectLambdaAccessPoint_basic (45.60s) --- PASS: TestAccS3ControlObjectLambdaAccessPoint_disappears (48.86s) --- PASS: TestAccS3ControlObjectLambdaAccessPoint_update (73.36s) PASS ok github.com/hashicorp/terraform-provider-aws/internal/service/s3control 78.453s --- internal/provider/provider.go | 4 - internal/service/s3control/exports_test.go | 20 +++-- internal/service/s3control/find.go | 89 ------------------- .../s3control/object_lambda_access_point.go | 81 +++++++++++------ .../object_lambda_access_point_policy.go | 61 ++++++++++++- .../object_lambda_access_point_test.go | 5 +- 6 files changed, 130 insertions(+), 130 deletions(-) delete mode 100644 internal/service/s3control/find.go diff --git a/internal/provider/provider.go b/internal/provider/provider.go index 5c88d4c0da3..3a599e0c48a 100644 --- a/internal/provider/provider.go +++ b/internal/provider/provider.go @@ -161,7 +161,6 @@ import ( "github.com/hashicorp/terraform-provider-aws/internal/service/route53resolver" "github.com/hashicorp/terraform-provider-aws/internal/service/rum" "github.com/hashicorp/terraform-provider-aws/internal/service/s3" - "github.com/hashicorp/terraform-provider-aws/internal/service/s3control" "github.com/hashicorp/terraform-provider-aws/internal/service/s3outposts" "github.com/hashicorp/terraform-provider-aws/internal/service/sagemaker" "github.com/hashicorp/terraform-provider-aws/internal/service/scheduler" @@ -2003,9 +2002,6 @@ func New(ctx context.Context) (*schema.Provider, error) { "aws_s3_object_copy": s3.ResourceObjectCopy(), "aws_s3_bucket_object": s3.ResourceBucketObject(), // DEPRECATED: use aws_s3_object instead - "aws_s3control_object_lambda_access_point": s3control.ResourceObjectLambdaAccessPoint(), - "aws_s3control_object_lambda_access_point_policy": s3control.ResourceObjectLambdaAccessPointPolicy(), - "aws_s3outposts_endpoint": s3outposts.ResourceEndpoint(), "aws_sagemaker_app": sagemaker.ResourceApp(), diff --git a/internal/service/s3control/exports_test.go b/internal/service/s3control/exports_test.go index 6a8ee5fbe94..bd998d22d53 100644 --- a/internal/service/s3control/exports_test.go +++ b/internal/service/s3control/exports_test.go @@ -2,13 +2,15 @@ package s3control // Exports for use in tests only. var ( - ResourceAccessPoint = resourceAccessPoint - ResourceAccessPointPolicy = resourceAccessPointPolicy - ResourceAccountPublicAccessBlock = resourceAccountPublicAccessBlock - ResourceBucket = resourceBucket - ResourceBucketLifecycleConfiguration = resourceBucketLifecycleConfiguration - ResourceBucketPolicy = resourceBucketPolicy - ResourceMultiRegionAccessPoint = resourceMultiRegionAccessPoint - ResourceMultiRegionAccessPointPolicy = resourceMultiRegionAccessPointPolicy - ResourceStorageLensConfiguration = resourceStorageLensConfiguration + ResourceAccessPoint = resourceAccessPoint + ResourceAccessPointPolicy = resourceAccessPointPolicy + ResourceAccountPublicAccessBlock = resourceAccountPublicAccessBlock + ResourceBucket = resourceBucket + ResourceBucketLifecycleConfiguration = resourceBucketLifecycleConfiguration + ResourceBucketPolicy = resourceBucketPolicy + ResourceMultiRegionAccessPoint = resourceMultiRegionAccessPoint + ResourceMultiRegionAccessPointPolicy = resourceMultiRegionAccessPointPolicy + ResourceObjectLambdaAccessPoint = resourceObjectLambdaAccessPoint + ResourceObjectLambdaAccessPointPolicy = resourceObjectLambdaAccessPointPolicy + ResourceStorageLensConfiguration = resourceStorageLensConfiguration ) diff --git a/internal/service/s3control/find.go b/internal/service/s3control/find.go deleted file mode 100644 index 61bdd52f978..00000000000 --- a/internal/service/s3control/find.go +++ /dev/null @@ -1,89 +0,0 @@ -package s3control - -import ( - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/s3control" - "github.com/hashicorp/aws-sdk-go-base/v2/awsv1shim/v2/tfawserr" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" - "github.com/hashicorp/terraform-provider-aws/internal/tfresource" -) - -func FindObjectLambdaAccessPointByAccountIDAndName(conn *s3control.S3Control, accountID string, name string) (*s3control.ObjectLambdaConfiguration, error) { - input := &s3control.GetAccessPointConfigurationForObjectLambdaInput{ - AccountId: aws.String(accountID), - Name: aws.String(name), - } - - output, err := conn.GetAccessPointConfigurationForObjectLambda(input) - - if tfawserr.ErrCodeEquals(err, errCodeNoSuchAccessPoint) { - return nil, &resource.NotFoundError{ - LastError: err, - LastRequest: input, - } - } - - if err != nil { - return nil, err - } - - if output == nil || output.Configuration == nil { - return nil, tfresource.NewEmptyResultError(input) - } - - return output.Configuration, nil -} - -func FindObjectLambdaAccessPointPolicyAndStatusByAccountIDAndName(conn *s3control.S3Control, accountID string, name string) (string, *s3control.PolicyStatus, error) { - input1 := &s3control.GetAccessPointPolicyForObjectLambdaInput{ - AccountId: aws.String(accountID), - Name: aws.String(name), - } - - output1, err := conn.GetAccessPointPolicyForObjectLambda(input1) - - if tfawserr.ErrCodeEquals(err, errCodeNoSuchAccessPoint, errCodeNoSuchAccessPointPolicy) { - return "", nil, &resource.NotFoundError{ - LastError: err, - LastRequest: input1, - } - } - - if err != nil { - return "", nil, err - } - - if output1 == nil { - return "", nil, tfresource.NewEmptyResultError(input1) - } - - policy := aws.StringValue(output1.Policy) - - if policy == "" { - return "", nil, tfresource.NewEmptyResultError(input1) - } - - input2 := &s3control.GetAccessPointPolicyStatusForObjectLambdaInput{ - AccountId: aws.String(accountID), - Name: aws.String(name), - } - - output2, err := conn.GetAccessPointPolicyStatusForObjectLambda(input2) - - if tfawserr.ErrCodeEquals(err, errCodeNoSuchAccessPoint, errCodeNoSuchAccessPointPolicy) { - return "", nil, &resource.NotFoundError{ - LastError: err, - LastRequest: input2, - } - } - - if err != nil { - return "", nil, err - } - - if output2 == nil || output2.PolicyStatus == nil { - return "", nil, tfresource.NewEmptyResultError(input2) - } - - return policy, output2.PolicyStatus, nil -} diff --git a/internal/service/s3control/object_lambda_access_point.go b/internal/service/s3control/object_lambda_access_point.go index 316b5a6c787..97179f18cea 100644 --- a/internal/service/s3control/object_lambda_access_point.go +++ b/internal/service/s3control/object_lambda_access_point.go @@ -1,6 +1,7 @@ package s3control import ( + "context" "fmt" "log" "strings" @@ -9,6 +10,8 @@ import ( "github.com/aws/aws-sdk-go/aws/arn" "github.com/aws/aws-sdk-go/service/s3control" "github.com/hashicorp/aws-sdk-go-base/v2/awsv1shim/v2/tfawserr" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" "github.com/hashicorp/terraform-provider-aws/internal/conns" @@ -17,12 +20,16 @@ import ( "github.com/hashicorp/terraform-provider-aws/internal/verify" ) -func ResourceObjectLambdaAccessPoint() *schema.Resource { +func init() { + _sp.registerSDKResourceFactory("aws_s3control_object_lambda_access_point", resourceObjectLambdaAccessPoint) +} + +func resourceObjectLambdaAccessPoint() *schema.Resource { return &schema.Resource{ - Create: resourceObjectLambdaAccessPointCreate, - Read: resourceObjectLambdaAccessPointRead, - Update: resourceObjectLambdaAccessPointUpdate, - Delete: resourceObjectLambdaAccessPointDelete, + CreateWithoutTimeout: resourceObjectLambdaAccessPointCreate, + ReadWithoutTimeout: resourceObjectLambdaAccessPointRead, + UpdateWithoutTimeout: resourceObjectLambdaAccessPointUpdate, + DeleteWithoutTimeout: resourceObjectLambdaAccessPointDelete, Importer: &schema.ResourceImporter{ State: schema.ImportStatePassthrough, @@ -119,7 +126,7 @@ func ResourceObjectLambdaAccessPoint() *schema.Resource { } } -func resourceObjectLambdaAccessPointCreate(d *schema.ResourceData, meta interface{}) error { +func resourceObjectLambdaAccessPointCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { conn := meta.(*conns.AWSClient).S3ControlConn() accountID := meta.(*conns.AWSClient).AccountID @@ -138,28 +145,27 @@ func resourceObjectLambdaAccessPointCreate(d *schema.ResourceData, meta interfac input.Configuration = expandObjectLambdaConfiguration(v.([]interface{})[0].(map[string]interface{})) } - log.Printf("[DEBUG] Creating S3 Object Lambda Access Point: %s", input) - _, err := conn.CreateAccessPointForObjectLambda(input) + _, err := conn.CreateAccessPointForObjectLambdaWithContext(ctx, input) if err != nil { - return fmt.Errorf("error creating S3 Object Lambda Access Point (%s): %w", resourceID, err) + return diag.Errorf("creating S3 Object Lambda Access Point (%s): %s", resourceID, err) } d.SetId(resourceID) - return resourceObjectLambdaAccessPointRead(d, meta) + return resourceObjectLambdaAccessPointRead(ctx, d, meta) } -func resourceObjectLambdaAccessPointRead(d *schema.ResourceData, meta interface{}) error { +func resourceObjectLambdaAccessPointRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { conn := meta.(*conns.AWSClient).S3ControlConn() accountID, name, err := ObjectLambdaAccessPointParseResourceID(d.Id()) if err != nil { - return err + return diag.FromErr(err) } - output, err := FindObjectLambdaAccessPointByAccountIDAndName(conn, accountID, name) + output, err := FindObjectLambdaAccessPointByAccountIDAndName(ctx, conn, accountID, name) if !d.IsNewResource() && tfresource.NotFound(err) { log.Printf("[WARN] S3 Object Lambda Access Point (%s) not found, removing from state", d.Id()) @@ -168,7 +174,7 @@ func resourceObjectLambdaAccessPointRead(d *schema.ResourceData, meta interface{ } if err != nil { - return fmt.Errorf("error reading S3 Object Lambda Access Point (%s): %w", d.Id(), err) + return diag.Errorf("reading S3 Object Lambda Access Point (%s): %s", d.Id(), err) } d.Set("account_id", accountID) @@ -182,20 +188,20 @@ func resourceObjectLambdaAccessPointRead(d *schema.ResourceData, meta interface{ }.String() d.Set("arn", arn) if err := d.Set("configuration", []interface{}{flattenObjectLambdaConfiguration(output)}); err != nil { - return fmt.Errorf("error setting configuration: %w", err) + return diag.Errorf("setting configuration: %s", err) } d.Set("name", name) return nil } -func resourceObjectLambdaAccessPointUpdate(d *schema.ResourceData, meta interface{}) error { +func resourceObjectLambdaAccessPointUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { conn := meta.(*conns.AWSClient).S3ControlConn() accountID, name, err := ObjectLambdaAccessPointParseResourceID(d.Id()) if err != nil { - return err + return diag.FromErr(err) } input := &s3control.PutAccessPointConfigurationForObjectLambdaInput{ @@ -207,27 +213,26 @@ func resourceObjectLambdaAccessPointUpdate(d *schema.ResourceData, meta interfac input.Configuration = expandObjectLambdaConfiguration(v.([]interface{})[0].(map[string]interface{})) } - log.Printf("[DEBUG] Updating S3 Object Lambda Access Point: %s", input) - _, err = conn.PutAccessPointConfigurationForObjectLambda(input) + _, err = conn.PutAccessPointConfigurationForObjectLambdaWithContext(ctx, input) if err != nil { - return fmt.Errorf("error updating S3 Object Lambda Access Point (%s): %w", d.Id(), err) + return diag.Errorf("updating S3 Object Lambda Access Point (%s): %s", d.Id(), err) } - return resourceObjectLambdaAccessPointRead(d, meta) + return resourceObjectLambdaAccessPointRead(ctx, d, meta) } -func resourceObjectLambdaAccessPointDelete(d *schema.ResourceData, meta interface{}) error { +func resourceObjectLambdaAccessPointDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { conn := meta.(*conns.AWSClient).S3ControlConn() accountID, name, err := ObjectLambdaAccessPointParseResourceID(d.Id()) if err != nil { - return err + return diag.FromErr(err) } log.Printf("[DEBUG] Deleting S3 Object Lambda Access Point: %s", d.Id()) - _, err = conn.DeleteAccessPointForObjectLambda(&s3control.DeleteAccessPointForObjectLambdaInput{ + _, err = conn.DeleteAccessPointForObjectLambdaWithContext(ctx, &s3control.DeleteAccessPointForObjectLambdaInput{ AccountId: aws.String(accountID), Name: aws.String(name), }) @@ -237,12 +242,38 @@ func resourceObjectLambdaAccessPointDelete(d *schema.ResourceData, meta interfac } if err != nil { - return fmt.Errorf("error deleting S3 Object Lambda Access Point (%s): %w", d.Id(), err) + return diag.Errorf("deleting S3 Object Lambda Access Point (%s): %s", d.Id(), err) } return nil } +func FindObjectLambdaAccessPointByAccountIDAndName(ctx context.Context, conn *s3control.S3Control, accountID string, name string) (*s3control.ObjectLambdaConfiguration, error) { + input := &s3control.GetAccessPointConfigurationForObjectLambdaInput{ + AccountId: aws.String(accountID), + Name: aws.String(name), + } + + output, err := conn.GetAccessPointConfigurationForObjectLambdaWithContext(ctx, input) + + if tfawserr.ErrCodeEquals(err, errCodeNoSuchAccessPoint) { + return nil, &resource.NotFoundError{ + LastError: err, + LastRequest: input, + } + } + + if err != nil { + return nil, err + } + + if output == nil || output.Configuration == nil { + return nil, tfresource.NewEmptyResultError(input) + } + + return output.Configuration, nil +} + const objectLambdaAccessPointResourceIDSeparator = ":" func ObjectLambdaAccessPointCreateResourceID(accountID, accessPointName string) string { diff --git a/internal/service/s3control/object_lambda_access_point_policy.go b/internal/service/s3control/object_lambda_access_point_policy.go index 9523d116a3d..c81a2eb3b2e 100644 --- a/internal/service/s3control/object_lambda_access_point_policy.go +++ b/internal/service/s3control/object_lambda_access_point_policy.go @@ -7,6 +7,7 @@ import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/s3control" "github.com/hashicorp/aws-sdk-go-base/v2/awsv1shim/v2/tfawserr" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/structure" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" @@ -15,7 +16,11 @@ import ( "github.com/hashicorp/terraform-provider-aws/internal/verify" ) -func ResourceObjectLambdaAccessPointPolicy() *schema.Resource { +func init() { + _sp.registerSDKResourceFactory("aws_s3control_object_lambda_access_point_policy", resourceObjectLambdaAccessPointPolicy) +} + +func resourceObjectLambdaAccessPointPolicy() *schema.Resource { return &schema.Resource{ Create: resourceObjectLambdaAccessPointPolicyCreate, Read: resourceObjectLambdaAccessPointPolicyRead, @@ -187,3 +192,57 @@ func resourceObjectLambdaAccessPointPolicyDelete(d *schema.ResourceData, meta in return nil } + +func FindObjectLambdaAccessPointPolicyAndStatusByAccountIDAndName(conn *s3control.S3Control, accountID string, name string) (string, *s3control.PolicyStatus, error) { + input1 := &s3control.GetAccessPointPolicyForObjectLambdaInput{ + AccountId: aws.String(accountID), + Name: aws.String(name), + } + + output1, err := conn.GetAccessPointPolicyForObjectLambda(input1) + + if tfawserr.ErrCodeEquals(err, errCodeNoSuchAccessPoint, errCodeNoSuchAccessPointPolicy) { + return "", nil, &resource.NotFoundError{ + LastError: err, + LastRequest: input1, + } + } + + if err != nil { + return "", nil, err + } + + if output1 == nil { + return "", nil, tfresource.NewEmptyResultError(input1) + } + + policy := aws.StringValue(output1.Policy) + + if policy == "" { + return "", nil, tfresource.NewEmptyResultError(input1) + } + + input2 := &s3control.GetAccessPointPolicyStatusForObjectLambdaInput{ + AccountId: aws.String(accountID), + Name: aws.String(name), + } + + output2, err := conn.GetAccessPointPolicyStatusForObjectLambda(input2) + + if tfawserr.ErrCodeEquals(err, errCodeNoSuchAccessPoint, errCodeNoSuchAccessPointPolicy) { + return "", nil, &resource.NotFoundError{ + LastError: err, + LastRequest: input2, + } + } + + if err != nil { + return "", nil, err + } + + if output2 == nil || output2.PolicyStatus == nil { + return "", nil, tfresource.NewEmptyResultError(input2) + } + + return policy, output2.PolicyStatus, nil +} diff --git a/internal/service/s3control/object_lambda_access_point_test.go b/internal/service/s3control/object_lambda_access_point_test.go index c90b7895475..20a2e03262a 100644 --- a/internal/service/s3control/object_lambda_access_point_test.go +++ b/internal/service/s3control/object_lambda_access_point_test.go @@ -1,6 +1,7 @@ package s3control_test import ( + "context" "fmt" "testing" @@ -160,7 +161,7 @@ func testAccCheckObjectLambdaAccessPointDestroy(s *terraform.State) error { return err } - _, err = tfs3control.FindObjectLambdaAccessPointByAccountIDAndName(conn, accountID, name) + _, err = tfs3control.FindObjectLambdaAccessPointByAccountIDAndName(context.Background(), conn, accountID, name) if tfresource.NotFound(err) { continue @@ -195,7 +196,7 @@ func testAccCheckObjectLambdaAccessPointExists(n string, v *s3control.ObjectLamb conn := acctest.Provider.Meta().(*conns.AWSClient).S3ControlConn() - output, err := tfs3control.FindObjectLambdaAccessPointByAccountIDAndName(conn, accountID, name) + output, err := tfs3control.FindObjectLambdaAccessPointByAccountIDAndName(context.Background(), conn, accountID, name) if err != nil { return err