Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

f/aws_s3control_object_lambda_access_point: add alias attribute to s3 object lambda #33388

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/33388.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
resource/aws_s3control_object_lambda_access_point: Add `alias` attribute
```
44 changes: 41 additions & 3 deletions internal/service/s3control/object_lambda_access_point.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ func resourceObjectLambdaAccessPoint() *schema.Resource {
ForceNew: true,
ValidateFunc: verify.ValidAccountID,
},
"alias": {
Type: schema.TypeString,
Computed: true,
},
"arn": {
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -165,7 +169,7 @@ func resourceObjectLambdaAccessPointRead(ctx context.Context, d *schema.Resource
return diag.FromErr(err)
}

output, err := FindObjectLambdaAccessPointByTwoPartKey(ctx, conn, accountID, name)
outputConfiguration, err := FindObjectLambdaAccessPointConfigurationByTwoPartKey(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 @@ -187,11 +191,19 @@ func resourceObjectLambdaAccessPointRead(ctx context.Context, d *schema.Resource
Resource: fmt.Sprintf("accesspoint/%s", name),
}.String()
d.Set("arn", arn)
if err := d.Set("configuration", []interface{}{flattenObjectLambdaConfiguration(output)}); err != nil {
if err := d.Set("configuration", []interface{}{flattenObjectLambdaConfiguration(outputConfiguration)}); err != nil {
return diag.Errorf("setting configuration: %s", err)
}
d.Set("name", name)

outputAlias, err := FindObjectLambdaAccessPointAliasByTwoPartKey(ctx, conn, accountID, name)

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

d.Set("alias", outputAlias.Value)

return nil
}

Expand Down Expand Up @@ -248,7 +260,7 @@ func resourceObjectLambdaAccessPointDelete(ctx context.Context, d *schema.Resour
return nil
}

func FindObjectLambdaAccessPointByTwoPartKey(ctx context.Context, conn *s3control.S3Control, accountID string, name string) (*s3control.ObjectLambdaConfiguration, error) {
func FindObjectLambdaAccessPointConfigurationByTwoPartKey(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 All @@ -274,6 +286,32 @@ func FindObjectLambdaAccessPointByTwoPartKey(ctx context.Context, conn *s3contro
return output.Configuration, nil
}

func FindObjectLambdaAccessPointAliasByTwoPartKey(ctx context.Context, conn *s3control.S3Control, accountID string, name string) (*s3control.ObjectLambdaAccessPointAlias, error) {
input := &s3control.GetAccessPointForObjectLambdaInput{
AccountId: aws.String(accountID),
Name: aws.String(name),
}

output, err := conn.GetAccessPointForObjectLambdaWithContext(ctx, input)

if tfawserr.ErrCodeEquals(err, errCodeNoSuchAccessPoint) {
return nil, &retry.NotFoundError{
LastError: err,
LastRequest: input,
}
}

if err != nil {
return nil, err
}

if output == nil || output.Alias == nil {
return nil, tfresource.NewEmptyResultError(input)
}

return output.Alias, nil
}

const objectLambdaAccessPointResourceIDSeparator = ":"

func ObjectLambdaAccessPointCreateResourceID(accountID, accessPointName string) string {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"fmt"
"testing"

"github.com/YakDriver/regexache"
"github.com/aws/aws-sdk-go/service/s3control"
sdkacctest "github.com/hashicorp/terraform-plugin-testing/helper/acctest"
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
Expand Down Expand Up @@ -37,6 +38,7 @@ func TestAccS3ControlObjectLambdaAccessPoint_basic(t *testing.T) {
Check: resource.ComposeTestCheckFunc(
testAccCheckObjectLambdaAccessPointExists(ctx, resourceName, &v),
acctest.CheckResourceAttrAccountID(resourceName, "account_id"),
resource.TestMatchResourceAttr(resourceName, "alias", regexache.MustCompile("^.{1,20}-.*--ol-s3$")),
acctest.CheckResourceAttrRegionalARN(resourceName, "arn", "s3-object-lambda", fmt.Sprintf("accesspoint/%s", rName)),
resource.TestCheckResourceAttr(resourceName, "configuration.#", "1"),
resource.TestCheckResourceAttr(resourceName, "configuration.0.allowed_features.#", "0"),
Expand Down Expand Up @@ -168,7 +170,7 @@ func testAccCheckObjectLambdaAccessPointDestroy(ctx context.Context) resource.Te
return err
}

_, err = tfs3control.FindObjectLambdaAccessPointByTwoPartKey(ctx, conn, accountID, name)
_, err = tfs3control.FindObjectLambdaAccessPointConfigurationByTwoPartKey(ctx, conn, accountID, name)

if tfresource.NotFound(err) {
continue
Expand Down Expand Up @@ -204,7 +206,7 @@ func testAccCheckObjectLambdaAccessPointExists(ctx context.Context, n string, v

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

output, err := tfs3control.FindObjectLambdaAccessPointByTwoPartKey(ctx, conn, accountID, name)
output, err := tfs3control.FindObjectLambdaAccessPointConfigurationByTwoPartKey(ctx, conn, accountID, name)

if err != nil {
return err
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ The `aws_lambda` block supports the following:

This resource exports the following attributes in addition to the arguments above:

* `alias` - Alias for the S3 Object Lambda Access Point.
* `arn` - Amazon Resource Name (ARN) of the Object Lambda Access Point.
* `id` - The AWS account ID and access point name separated by a colon (`:`).

Expand Down