From ac4b033ebf5b703d5c68bcf9bf6aecdc3b3cc231 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Tue, 27 Nov 2018 10:18:16 -0500 Subject: [PATCH] Support S3 S3 Cross-Region Replication to Glacier. --- aws/resource_aws_s3_bucket.go | 1 + aws/resource_aws_s3_bucket_test.go | 35 ++++++++++++++++++++++---- website/docs/r/s3_bucket.html.markdown | 2 +- 3 files changed, 32 insertions(+), 6 deletions(-) diff --git a/aws/resource_aws_s3_bucket.go b/aws/resource_aws_s3_bucket.go index f0339c45994..32e5040223c 100644 --- a/aws/resource_aws_s3_bucket.go +++ b/aws/resource_aws_s3_bucket.go @@ -397,6 +397,7 @@ func resourceAwsS3Bucket() *schema.Resource { s3.StorageClassStandardIa, s3.StorageClassOnezoneIa, s3.StorageClassIntelligentTiering, + s3.StorageClassGlacier, }, false), }, "replica_kms_key_id": { diff --git a/aws/resource_aws_s3_bucket_test.go b/aws/resource_aws_s3_bucket_test.go index 3cddd819511..1431de3dff6 100644 --- a/aws/resource_aws_s3_bucket_test.go +++ b/aws/resource_aws_s3_bucket_test.go @@ -932,7 +932,7 @@ func TestAccAWSS3Bucket_Replication(t *testing.T) { ), }, { - Config: testAccAWSS3BucketConfigReplicationWithConfiguration(rInt), + Config: testAccAWSS3BucketConfigReplicationWithConfiguration(rInt, "STANDARD"), Check: resource.ComposeTestCheckFunc( testAccCheckAWSS3BucketExistsWithProvider("aws_s3_bucket.bucket", testAccAwsRegionProviderFunc(region, &providers)), resource.TestCheckResourceAttr("aws_s3_bucket.bucket", "replication_configuration.#", "1"), @@ -947,7 +947,32 @@ func TestAccAWSS3Bucket_Replication(t *testing.T) { ID: aws.String("foobar"), Destination: &s3.Destination{ Bucket: aws.String(fmt.Sprintf("arn:%s:s3:::tf-test-bucket-destination-%d", partition, rInt)), - StorageClass: aws.String(s3.ObjectStorageClassStandard), + StorageClass: aws.String(s3.StorageClassStandard), + }, + Prefix: aws.String("foo"), + Status: aws.String(s3.ReplicationRuleStatusEnabled), + }, + }, + ), + ), + }, + { + Config: testAccAWSS3BucketConfigReplicationWithConfiguration(rInt, "GLACIER"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAWSS3BucketExistsWithProvider("aws_s3_bucket.bucket", testAccAwsRegionProviderFunc(region, &providers)), + resource.TestCheckResourceAttr("aws_s3_bucket.bucket", "replication_configuration.#", "1"), + resource.TestMatchResourceAttr("aws_s3_bucket.bucket", "replication_configuration.0.role", regexp.MustCompile(fmt.Sprintf("^arn:aws[\\w-]*:iam::[\\d+]+:role/tf-iam-role-replication-%d", rInt))), + resource.TestCheckResourceAttr("aws_s3_bucket.bucket", "replication_configuration.0.rules.#", "1"), + testAccCheckAWSS3BucketExistsWithProvider("aws_s3_bucket.destination", testAccAwsRegionProviderFunc("eu-west-1", &providers)), + testAccCheckAWSS3BucketReplicationRules( + "aws_s3_bucket.bucket", + testAccAwsRegionProviderFunc(region, &providers), + []*s3.ReplicationRule{ + { + ID: aws.String("foobar"), + Destination: &s3.Destination{ + Bucket: aws.String(fmt.Sprintf("arn:%s:s3:::tf-test-bucket-destination-%d", partition, rInt)), + StorageClass: aws.String(s3.StorageClassGlacier), }, Prefix: aws.String("foo"), Status: aws.String(s3.ReplicationRuleStatusEnabled), @@ -2449,7 +2474,7 @@ resource "aws_s3_bucket" "destination" { `, randInt, randInt, randInt) } -func testAccAWSS3BucketConfigReplicationWithConfiguration(randInt int) string { +func testAccAWSS3BucketConfigReplicationWithConfiguration(randInt int, storageClass string) string { return fmt.Sprintf(testAccAWSS3BucketConfigReplicationBasic+` resource "aws_s3_bucket" "bucket" { provider = "aws.uswest2" @@ -2469,7 +2494,7 @@ resource "aws_s3_bucket" "bucket" { destination { bucket = "${aws_s3_bucket.destination.arn}" - storage_class = "STANDARD" + storage_class = "%s" } } } @@ -2484,7 +2509,7 @@ resource "aws_s3_bucket" "destination" { enabled = true } } -`, randInt, randInt, randInt) +`, randInt, randInt, storageClass, randInt) } func testAccAWSS3BucketConfigReplicationWithSseKmsEncryptedObjects(randInt int) string { diff --git a/website/docs/r/s3_bucket.html.markdown b/website/docs/r/s3_bucket.html.markdown index c16a4225d25..4ae7d0469d7 100644 --- a/website/docs/r/s3_bucket.html.markdown +++ b/website/docs/r/s3_bucket.html.markdown @@ -423,7 +423,7 @@ Replication configuration V1 supports filtering based on only the `prefix` attri The `destination` object supports the following: * `bucket` - (Required) The ARN of the S3 bucket where you want Amazon S3 to store replicas of the object identified by the rule. -* `storage_class` - (Optional) The class of storage used to store the object. Can be `STANDARD`, `REDUCED_REDUNDANCY`, `STANDARD_IA`, `ONEZONE_IA`, or `INTELLIGENT_TIERING`. +* `storage_class` - (Optional) The class of storage used to store the object. Can be `STANDARD`, `REDUCED_REDUNDANCY`, `STANDARD_IA`, `ONEZONE_IA`, `INTELLIGENT_TIERING`, or `GLACIER`. * `replica_kms_key_id` - (Optional) Destination KMS encryption key ARN for SSE-KMS replication. Must be used in conjunction with `sse_kms_encrypted_objects` source selection criteria. * `access_control_translation` - (Optional) Specifies the overrides to use for object owners on replication. Must be used in conjunction with `account_id` owner override configuration.