Skip to content

Commit

Permalink
Merge pull request #33677 from hashicorp/t-aws_s3control_multi_region…
Browse files Browse the repository at this point in the history
…_access_point-put-and-get-object

r/aws_s3_object: Test access through a multi-region access point
  • Loading branch information
ewbankkit authored Sep 28, 2023
2 parents dc6a56c + 43fcc47 commit dbf42d7
Showing 1 changed file with 60 additions and 4 deletions.
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)
}

0 comments on commit dbf42d7

Please sign in to comment.