Skip to content

Commit

Permalink
r/aws_s3control_object_lambda_access_point: Switch to 'WithoutTimeout…
Browse files Browse the repository at this point in the history
…' 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
  • Loading branch information
ewbankkit committed Dec 23, 2022
1 parent 723aae3 commit 213cb72
Show file tree
Hide file tree
Showing 6 changed files with 130 additions and 130 deletions.
4 changes: 0 additions & 4 deletions internal/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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(),
Expand Down
20 changes: 11 additions & 9 deletions internal/service/s3control/exports_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
89 changes: 0 additions & 89 deletions internal/service/s3control/find.go

This file was deleted.

81 changes: 56 additions & 25 deletions internal/service/s3control/object_lambda_access_point.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package s3control

import (
"context"
"fmt"
"log"
"strings"
Expand All @@ -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"
Expand All @@ -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,
Expand Down Expand Up @@ -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
Expand All @@ -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())
Expand All @@ -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)
Expand All @@ -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{
Expand All @@ -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),
})
Expand All @@ -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 {
Expand Down
Loading

0 comments on commit 213cb72

Please sign in to comment.