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

r/aws_s3_object: Test access through a multi-region access point #33677

Merged
Merged
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
64 changes: 60 additions & 4 deletions internal/service/s3control/multi_region_access_point_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func TestAccS3ControlMultiRegionAccessPoint_basic(t *testing.T) {
Steps: []resource.TestStep{
{
Config: testAccMultiRegionAccessPointConfig_basic(bucketName, rName),
Check: resource.ComposeTestCheckFunc(
Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckMultiRegionAccessPointExists(ctx, resourceName, &v),
acctest.CheckResourceAttrAccountID(resourceName, "account_id"),
resource.TestMatchResourceAttr(resourceName, "alias", regexache.MustCompile(`^[a-z][0-9a-z]*[.]mrap$`)),
Expand Down Expand Up @@ -208,6 +208,29 @@ func TestAccS3ControlMultiRegionAccessPoint_threeRegions(t *testing.T) {
})
}

func TestAccS3ControlMultiRegionAccessPoint_putAndGetObject(t *testing.T) {
ctx := acctest.Context(t)
var v types.MultiRegionAccessPointReport
resourceName := "aws_s3control_multi_region_access_point.test"
bucketName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(ctx, t); acctest.PreCheckPartitionNot(t, names.USGovCloudPartitionID) },
ErrorCheck: acctest.ErrorCheck(t, names.S3ControlEndpointID),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
CheckDestroy: testAccCheckMultiRegionAccessPointDestroy(ctx),
Steps: []resource.TestStep{
{
Config: testAccMultiRegionAccessPointConfig_putAndGetObject(bucketName, rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckMultiRegionAccessPointExists(ctx, resourceName, &v),
),
},
},
})
}

func testAccCheckMultiRegionAccessPointDestroy(ctx context.Context) resource.TestCheckFunc {
return func(s *terraform.State) error {
conn := acctest.Provider.Meta().(*conns.AWSClient).S3ControlClient(ctx)
Expand Down Expand Up @@ -324,9 +347,7 @@ resource "aws_s3control_multi_region_access_point" "test" {
}

func testAccMultiRegionAccessPointConfig_three(bucketName1, bucketName2, bucketName3, multiRegionAccessPointName string) string {
return acctest.ConfigCompose(
acctest.ConfigMultipleRegionProvider(3),
fmt.Sprintf(`
return acctest.ConfigCompose(acctest.ConfigMultipleRegionProvider(3), fmt.Sprintf(`
resource "aws_s3_bucket" "test1" {
provider = aws
Expand Down Expand Up @@ -369,3 +390,38 @@ resource "aws_s3control_multi_region_access_point" "test" {
}
`, bucketName1, bucketName2, bucketName3, multiRegionAccessPointName))
}

func testAccMultiRegionAccessPointConfig_putAndGetObject(bucketName, multiRegionAccessPointName string) string {
return fmt.Sprintf(`
resource "aws_s3_bucket" "test" {
bucket = %[1]q
force_destroy = true
}
resource "aws_s3control_multi_region_access_point" "test" {
details {
name = %[2]q
region {
bucket = aws_s3_bucket.test.id
}
}
}
resource "aws_s3_object" "test" {
bucket = aws_s3control_multi_region_access_point.test.arn
key = "%[1]s-key"
content = "Hello World"
tags = {
Name = %[2]q
}
}
# Ensure that we can GET through the bucket.
data "aws_s3_object" "test" {
bucket = aws_s3_bucket.test.bucket
key = aws_s3_object.test.key
}
`, bucketName, multiRegionAccessPointName)
}
Loading