Skip to content

Commit

Permalink
tests/resource/aws_s3_bucket: Add S3 Same-Region Replication acceptan…
Browse files Browse the repository at this point in the history
…ce test (#10170)

Output from acceptance testing in AWS Commercial:

```
--- PASS: TestAccAWSS3Bucket_SameRegionReplicationSchemaV2 (52.57s)
```

Output from acceptance testing in AWS GovCloud (US):

```
--- PASS: TestAccAWSS3Bucket_SameRegionReplicationSchemaV2 (56.62s)
```
  • Loading branch information
ewbankkit authored Jul 21, 2020
1 parent 2228798 commit d9f833b
Showing 1 changed file with 114 additions and 0 deletions.
114 changes: 114 additions & 0 deletions aws/resource_aws_s3_bucket_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1930,6 +1930,60 @@ func TestAccAWSS3Bucket_ReplicationSchemaV2(t *testing.T) {
})
}

func TestAccAWSS3Bucket_SameRegionReplicationSchemaV2(t *testing.T) {
resourceName := "aws_s3_bucket.bucket"
rName := acctest.RandomWithPrefix("tf-acc-test")
destinationResourceName := "aws_s3_bucket.destination"
rNameDestination := acctest.RandomWithPrefix("tf-acc-test")

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSS3BucketDestroy,
Steps: []resource.TestStep{
{
Config: testAccAWSS3BucketConfigSameRegionReplicationWithV2ConfigurationNoTags(rName, rNameDestination),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSS3BucketExists(resourceName),
resource.TestCheckResourceAttr(resourceName, "replication_configuration.#", "1"),
testAccCheckResourceAttrGlobalARN(resourceName, "replication_configuration.0.role", "iam", fmt.Sprintf("role/%s", rName)),
resource.TestCheckResourceAttr(resourceName, "replication_configuration.0.rules.#", "1"),
testAccCheckAWSS3BucketExists(destinationResourceName),
testAccCheckAWSS3BucketReplicationRules(
resourceName,
testAccProviderFunc,
[]*s3.ReplicationRule{
{
ID: aws.String("testid"),
Destination: &s3.Destination{
Bucket: aws.String(fmt.Sprintf("arn:%s:s3:::%s", testAccGetPartition(), rNameDestination)),
StorageClass: aws.String(s3.ObjectStorageClassStandard),
},
Status: aws.String(s3.ReplicationRuleStatusEnabled),
Filter: &s3.ReplicationRuleFilter{
Prefix: aws.String("testprefix"),
},
Priority: aws.Int64(0),
DeleteMarkerReplication: &s3.DeleteMarkerReplication{
Status: aws.String(s3.DeleteMarkerReplicationStatusDisabled),
},
},
},
),
),
},
{
Config: testAccAWSS3BucketConfigSameRegionReplicationWithV2ConfigurationNoTags(rName, rNameDestination),
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{
"force_destroy", "acl"},
},
},
})
}

func TestAccAWSS3Bucket_objectLock(t *testing.T) {
bucketName := acctest.RandomWithPrefix("tf-test-bucket")
resourceName := "aws_s3_bucket.arbitrary"
Expand Down Expand Up @@ -3880,6 +3934,44 @@ resource "aws_s3_bucket" "bucket" {
`, randInt)
}

func testAccAWSS3BucketConfigSameRegionReplicationWithV2ConfigurationNoTags(rName, rNameDestination string) string {
return composeConfig(testAccAWSS3BucketReplicationConfig_iamPolicy(rName), fmt.Sprintf(`
resource "aws_s3_bucket" "bucket" {
bucket = %[1]q
acl = "private"
versioning {
enabled = true
}
replication_configuration {
role = "${aws_iam_role.test.arn}"
rules {
id = "testid"
status = "Enabled"
filter {
prefix = "testprefix"
}
destination {
bucket = "${aws_s3_bucket.destination.arn}"
storage_class = "STANDARD"
}
}
}
}
resource "aws_s3_bucket" "destination" {
bucket = %[2]q
versioning {
enabled = true
}
}
`, rName, rNameDestination))
}

func testAccAWSS3BucketConfigReplicationWithV2ConfigurationNoTags(randInt int) string {
return testAccAWSS3BucketConfigReplicationBasic(randInt) + fmt.Sprintf(`
resource "aws_s3_bucket" "bucket" {
Expand Down Expand Up @@ -4074,6 +4166,28 @@ resource "aws_s3_bucket" "bucket" {
`, bucketName)
}

func testAccAWSS3BucketReplicationConfig_iamPolicy(rName string) string {
return fmt.Sprintf(`
resource "aws_iam_role" "test" {
name = %[1]q
assume_role_policy = <<POLICY
{
"Version": "2012-10-17",
"Statement": [{
"Action": "sts:AssumeRole",
"Principal": {
"Service": "s3.amazonaws.com"
},
"Effect": "Allow",
"Sid": ""
}]
}
POLICY
}
`, rName)
}

const testAccAWSS3BucketConfigBucketEmptyString = `
resource "aws_s3_bucket" "test" {
bucket = ""
Expand Down

0 comments on commit d9f833b

Please sign in to comment.