Skip to content

Commit

Permalink
Support S3 S3 Cross-Region Replication to Glacier.
Browse files Browse the repository at this point in the history
  • Loading branch information
Kit Ewbank authored and ewbankkit committed Dec 2, 2018
1 parent 7a37b00 commit ac4b033
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 6 deletions.
1 change: 1 addition & 0 deletions aws/resource_aws_s3_bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,7 @@ func resourceAwsS3Bucket() *schema.Resource {
s3.StorageClassStandardIa,
s3.StorageClassOnezoneIa,
s3.StorageClassIntelligentTiering,
s3.StorageClassGlacier,
}, false),
},
"replica_kms_key_id": {
Expand Down
35 changes: 30 additions & 5 deletions aws/resource_aws_s3_bucket_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand All @@ -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),
Expand Down Expand Up @@ -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"
Expand All @@ -2469,7 +2494,7 @@ resource "aws_s3_bucket" "bucket" {
destination {
bucket = "${aws_s3_bucket.destination.arn}"
storage_class = "STANDARD"
storage_class = "%s"
}
}
}
Expand All @@ -2484,7 +2509,7 @@ resource "aws_s3_bucket" "destination" {
enabled = true
}
}
`, randInt, randInt, randInt)
`, randInt, randInt, storageClass, randInt)
}

func testAccAWSS3BucketConfigReplicationWithSseKmsEncryptedObjects(randInt int) string {
Expand Down
2 changes: 1 addition & 1 deletion website/docs/r/s3_bucket.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit ac4b033

Please sign in to comment.