Skip to content

Commit

Permalink
r/aws_s3control_object_lambda_access_point_policy: Switch to 'Without…
Browse files Browse the repository at this point in the history
…Timeout' CRUD handlers (#15090).

Acceptance test output:

% make testacc TESTARGS='-run=TestAccS3ControlObjectLambdaAccessPointPolicy_' 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=TestAccS3ControlObjectLambdaAccessPointPolicy_ -timeout 180m
=== RUN   TestAccS3ControlObjectLambdaAccessPointPolicy_basic
=== PAUSE TestAccS3ControlObjectLambdaAccessPointPolicy_basic
=== RUN   TestAccS3ControlObjectLambdaAccessPointPolicy_disappears
=== PAUSE TestAccS3ControlObjectLambdaAccessPointPolicy_disappears
=== RUN   TestAccS3ControlObjectLambdaAccessPointPolicy_Disappears_accessPoint
=== PAUSE TestAccS3ControlObjectLambdaAccessPointPolicy_Disappears_accessPoint
=== RUN   TestAccS3ControlObjectLambdaAccessPointPolicy_update
=== PAUSE TestAccS3ControlObjectLambdaAccessPointPolicy_update
=== CONT  TestAccS3ControlObjectLambdaAccessPointPolicy_basic
=== CONT  TestAccS3ControlObjectLambdaAccessPointPolicy_update
=== CONT  TestAccS3ControlObjectLambdaAccessPointPolicy_Disappears_accessPoint
--- PASS: TestAccS3ControlObjectLambdaAccessPointPolicy_basic (52.85s)
=== CONT  TestAccS3ControlObjectLambdaAccessPointPolicy_disappears
--- PASS: TestAccS3ControlObjectLambdaAccessPointPolicy_Disappears_accessPoint (55.72s)
--- PASS: TestAccS3ControlObjectLambdaAccessPointPolicy_update (63.83s)
--- PASS: TestAccS3ControlObjectLambdaAccessPointPolicy_disappears (42.69s)
PASS
ok  	github.com/hashicorp/terraform-provider-aws/internal/service/s3control	100.602s
  • Loading branch information
ewbankkit committed Dec 23, 2022
1 parent 213cb72 commit 3324c08
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 37 deletions.
4 changes: 2 additions & 2 deletions internal/service/s3control/object_lambda_access_point.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ func resourceObjectLambdaAccessPointRead(ctx context.Context, d *schema.Resource
return diag.FromErr(err)
}

output, err := FindObjectLambdaAccessPointByAccountIDAndName(ctx, conn, accountID, name)
output, err := FindObjectLambdaAccessPointByTwoPartKey(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 Down Expand Up @@ -248,7 +248,7 @@ func resourceObjectLambdaAccessPointDelete(ctx context.Context, d *schema.Resour
return nil
}

func FindObjectLambdaAccessPointByAccountIDAndName(ctx context.Context, conn *s3control.S3Control, accountID string, name string) (*s3control.ObjectLambdaConfiguration, error) {
func FindObjectLambdaAccessPointByTwoPartKey(ctx context.Context, conn *s3control.S3Control, accountID string, name string) (*s3control.ObjectLambdaConfiguration, error) {
input := &s3control.GetAccessPointConfigurationForObjectLambdaInput{
AccountId: aws.String(accountID),
Name: aws.String(name),
Expand Down
59 changes: 29 additions & 30 deletions internal/service/s3control/object_lambda_access_point_policy.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package s3control

import (
"fmt"
"context"
"log"

"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/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/structure"
Expand All @@ -22,10 +23,10 @@ func init() {

func resourceObjectLambdaAccessPointPolicy() *schema.Resource {
return &schema.Resource{
Create: resourceObjectLambdaAccessPointPolicyCreate,
Read: resourceObjectLambdaAccessPointPolicyRead,
Update: resourceObjectLambdaAccessPointPolicyUpdate,
Delete: resourceObjectLambdaAccessPointPolicyDelete,
CreateWithoutTimeout: resourceObjectLambdaAccessPointPolicyCreate,
ReadWithoutTimeout: resourceObjectLambdaAccessPointPolicyRead,
UpdateWithoutTimeout: resourceObjectLambdaAccessPointPolicyUpdate,
DeleteWithoutTimeout: resourceObjectLambdaAccessPointPolicyDelete,

Importer: &schema.ResourceImporter{
State: schema.ImportStatePassthrough,
Expand Down Expand Up @@ -62,7 +63,7 @@ func resourceObjectLambdaAccessPointPolicy() *schema.Resource {
}
}

func resourceObjectLambdaAccessPointPolicyCreate(d *schema.ResourceData, meta interface{}) error {
func resourceObjectLambdaAccessPointPolicyCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
conn := meta.(*conns.AWSClient).S3ControlConn()

accountID := meta.(*conns.AWSClient).AccountID
Expand All @@ -75,7 +76,7 @@ func resourceObjectLambdaAccessPointPolicyCreate(d *schema.ResourceData, meta in
policy, err := structure.NormalizeJsonString(d.Get("policy").(string))

if err != nil {
return fmt.Errorf("policy (%s) is invalid JSON: %w", d.Get("policy").(string), err)
return diag.Errorf("policy (%s) is invalid JSON: %s", d.Get("policy").(string), err)
}

input := &s3control.PutAccessPointPolicyForObjectLambdaInput{
Expand All @@ -84,28 +85,27 @@ func resourceObjectLambdaAccessPointPolicyCreate(d *schema.ResourceData, meta in
Policy: aws.String(policy),
}

log.Printf("[DEBUG] Creating S3 Object Lambda Access Point Policy: %s", input)
_, err = conn.PutAccessPointPolicyForObjectLambda(input)
_, err = conn.PutAccessPointPolicyForObjectLambdaWithContext(ctx, input)

if err != nil {
return fmt.Errorf("error creating S3 Object Lambda Access Point (%s) Policy: %w", resourceID, err)
return diag.Errorf("creating S3 Object Lambda Access Point (%s) Policy: %s", resourceID, err)
}

d.SetId(resourceID)

return resourceObjectLambdaAccessPointPolicyRead(d, meta)
return resourceObjectLambdaAccessPointPolicyRead(ctx, d, meta)
}

func resourceObjectLambdaAccessPointPolicyRead(d *schema.ResourceData, meta interface{}) error {
func resourceObjectLambdaAccessPointPolicyRead(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)
}

policy, status, err := FindObjectLambdaAccessPointPolicyAndStatusByAccountIDAndName(conn, accountID, name)
policy, status, err := FindObjectLambdaAccessPointPolicyAndStatusByTwoPartKey(ctx, conn, accountID, name)

if !d.IsNewResource() && tfresource.NotFound(err) {
log.Printf("[WARN] S3 Object Lambda Access Point Policy (%s) not found, removing from state", d.Id())
Expand All @@ -114,7 +114,7 @@ func resourceObjectLambdaAccessPointPolicyRead(d *schema.ResourceData, meta inte
}

if err != nil {
return fmt.Errorf("error reading S3 Object Lambda Access Point Policy (%s): %w", d.Id(), err)
return diag.Errorf("reading S3 Object Lambda Access Point Policy (%s): %s", d.Id(), err)
}

d.Set("account_id", accountID)
Expand All @@ -125,7 +125,7 @@ func resourceObjectLambdaAccessPointPolicyRead(d *schema.ResourceData, meta inte
policyToSet, err := verify.PolicyToSet(d.Get("policy").(string), policy)

if err != nil {
return err
return diag.FromErr(err)
}

d.Set("policy", policyToSet)
Expand All @@ -136,19 +136,19 @@ func resourceObjectLambdaAccessPointPolicyRead(d *schema.ResourceData, meta inte
return nil
}

func resourceObjectLambdaAccessPointPolicyUpdate(d *schema.ResourceData, meta interface{}) error {
func resourceObjectLambdaAccessPointPolicyUpdate(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)
}

policy, err := structure.NormalizeJsonString(d.Get("policy").(string))

if err != nil {
return fmt.Errorf("policy (%s) is invalid JSON: %w", d.Get("policy").(string), err)
return diag.Errorf("policy (%s) is invalid JSON: %s", d.Get("policy").(string), err)
}

input := &s3control.PutAccessPointPolicyForObjectLambdaInput{
Expand All @@ -157,27 +157,26 @@ func resourceObjectLambdaAccessPointPolicyUpdate(d *schema.ResourceData, meta in
Policy: aws.String(policy),
}

log.Printf("[DEBUG] Updating S3 Object Lambda Access Point Policy: %s", input)
_, err = conn.PutAccessPointPolicyForObjectLambda(input)
_, err = conn.PutAccessPointPolicyForObjectLambdaWithContext(ctx, input)

if err != nil {
return fmt.Errorf("error updating S3 Object Lambda Access Point Policy (%s): %w", d.Id(), err)
return diag.Errorf("updating S3 Object Lambda Access Point Policy (%s): %s", d.Id(), err)
}

return resourceObjectLambdaAccessPointPolicyRead(d, meta)
return resourceObjectLambdaAccessPointPolicyRead(ctx, d, meta)
}

func resourceObjectLambdaAccessPointPolicyDelete(d *schema.ResourceData, meta interface{}) error {
func resourceObjectLambdaAccessPointPolicyDelete(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 Policy: %s", d.Id())
_, err = conn.DeleteAccessPointPolicyForObjectLambda(&s3control.DeleteAccessPointPolicyForObjectLambdaInput{
_, err = conn.DeleteAccessPointPolicyForObjectLambdaWithContext(ctx, &s3control.DeleteAccessPointPolicyForObjectLambdaInput{
AccountId: aws.String(accountID),
Name: aws.String(name),
})
Expand All @@ -187,19 +186,19 @@ func resourceObjectLambdaAccessPointPolicyDelete(d *schema.ResourceData, meta in
}

if err != nil {
return fmt.Errorf("error deleting S3 Object Lambda Access Point Policy (%s): %w", d.Id(), err)
return diag.Errorf("deleting S3 Object Lambda Access Point Policy (%s): %s", d.Id(), err)
}

return nil
}

func FindObjectLambdaAccessPointPolicyAndStatusByAccountIDAndName(conn *s3control.S3Control, accountID string, name string) (string, *s3control.PolicyStatus, error) {
func FindObjectLambdaAccessPointPolicyAndStatusByTwoPartKey(ctx context.Context, 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)
output1, err := conn.GetAccessPointPolicyForObjectLambdaWithContext(ctx, input1)

if tfawserr.ErrCodeEquals(err, errCodeNoSuchAccessPoint, errCodeNoSuchAccessPointPolicy) {
return "", nil, &resource.NotFoundError{
Expand Down Expand Up @@ -227,7 +226,7 @@ func FindObjectLambdaAccessPointPolicyAndStatusByAccountIDAndName(conn *s3contro
Name: aws.String(name),
}

output2, err := conn.GetAccessPointPolicyStatusForObjectLambda(input2)
output2, err := conn.GetAccessPointPolicyStatusForObjectLambdaWithContext(ctx, input2)

if tfawserr.ErrCodeEquals(err, errCodeNoSuchAccessPoint, errCodeNoSuchAccessPointPolicy) {
return "", nil, &resource.NotFoundError{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package s3control_test

import (
"context"
"fmt"
"testing"

Expand Down Expand Up @@ -141,7 +142,7 @@ func testAccCheckObjectLambdaAccessPointPolicyDestroy(s *terraform.State) error
return err
}

_, _, err = tfs3control.FindObjectLambdaAccessPointPolicyAndStatusByAccountIDAndName(conn, accountID, name)
_, _, err = tfs3control.FindObjectLambdaAccessPointPolicyAndStatusByTwoPartKey(context.Background(), conn, accountID, name)

if tfresource.NotFound(err) {
continue
Expand Down Expand Up @@ -176,7 +177,7 @@ func testAccCheckObjectLambdaAccessPointPolicyExists(n string) resource.TestChec

conn := acctest.Provider.Meta().(*conns.AWSClient).S3ControlConn()

_, _, err = tfs3control.FindObjectLambdaAccessPointPolicyAndStatusByAccountIDAndName(conn, accountID, name)
_, _, err = tfs3control.FindObjectLambdaAccessPointPolicyAndStatusByTwoPartKey(context.Background(), conn, accountID, name)

return err
}
Expand Down
4 changes: 2 additions & 2 deletions internal/service/s3control/object_lambda_access_point_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ func testAccCheckObjectLambdaAccessPointDestroy(s *terraform.State) error {
return err
}

_, err = tfs3control.FindObjectLambdaAccessPointByAccountIDAndName(context.Background(), conn, accountID, name)
_, err = tfs3control.FindObjectLambdaAccessPointByTwoPartKey(context.Background(), conn, accountID, name)

if tfresource.NotFound(err) {
continue
Expand Down Expand Up @@ -196,7 +196,7 @@ func testAccCheckObjectLambdaAccessPointExists(n string, v *s3control.ObjectLamb

conn := acctest.Provider.Meta().(*conns.AWSClient).S3ControlConn()

output, err := tfs3control.FindObjectLambdaAccessPointByAccountIDAndName(context.Background(), conn, accountID, name)
output, err := tfs3control.FindObjectLambdaAccessPointByTwoPartKey(context.Background(), conn, accountID, name)

if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion internal/service/s3control/sweep.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ func sweepObjectLambdaAccessPoints(region string) error {
}

for _, v := range page.ObjectLambdaAccessPointList {
r := ResourceObjectLambdaAccessPoint()
r := resourceObjectLambdaAccessPoint()
d := r.Data(nil)
d.SetId(ObjectLambdaAccessPointCreateResourceID(accountID, aws.StringValue(v.Name)))

Expand Down

0 comments on commit 3324c08

Please sign in to comment.