diff --git a/aws/resource_aws_s3_bucket.go b/aws/resource_aws_s3_bucket.go index 4673dd194e1..d7ee14d00de 100644 --- a/aws/resource_aws_s3_bucket.go +++ b/aws/resource_aws_s3_bucket.go @@ -1783,9 +1783,6 @@ func resourceAwsS3BucketReplicationConfigurationUpdate(s3conn *s3.S3, d *schema. if rrid, ok := rr["id"]; ok && rrid != "" { rcRule.ID = aws.String(rrid.(string)) } - if prefix, ok := rr["prefix"]; ok && prefix != "" { - rcRule.Prefix = aws.String(prefix.(string)) - } ruleDestination := &s3.Destination{} if dest, ok := rr["destination"].(*schema.Set); ok && dest.Len() > 0 { @@ -1849,6 +1846,9 @@ func resourceAwsS3BucketReplicationConfigurationUpdate(s3conn *s3.S3, d *schema. rcRule.DeleteMarkerReplication = &s3.DeleteMarkerReplication{ Status: aws.String(s3.DeleteMarkerReplicationStatusDisabled), } + } else { + // XML schema V1. + rcRule.Prefix = aws.String(rr["prefix"].(string)) } rules = append(rules, rcRule) diff --git a/aws/resource_aws_s3_bucket_test.go b/aws/resource_aws_s3_bucket_test.go index 245c44a5504..615a4541e7f 100644 --- a/aws/resource_aws_s3_bucket_test.go +++ b/aws/resource_aws_s3_bucket_test.go @@ -1119,6 +1119,33 @@ func TestAccAWSS3Bucket_ReplicationExpectVersioningValidationError(t *testing.T) }) } +// Prefix issue: https://github.com/terraform-providers/terraform-provider-aws/issues/6340 +func TestAccAWSS3Bucket_ReplicationWithoutPrefix(t *testing.T) { + rInt := acctest.RandInt() + region := testAccGetRegion() + + // record the initialized providers so that we can use them to check for the instances in each region + var providers []*schema.Provider + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { + testAccPreCheck(t) + testAccMultipleRegionsPreCheck(t) + }, + ProviderFactories: testAccProviderFactories(&providers), + CheckDestroy: testAccCheckWithProviders(testAccCheckAWSS3BucketDestroyWithProvider, &providers), + Steps: []resource.TestStep{ + { + Config: testAccAWSS3BucketConfigReplicationWithoutPrefix(rInt), + Check: resource.ComposeTestCheckFunc( + testAccCheckAWSS3BucketExistsWithProvider("aws_s3_bucket.bucket", testAccAwsRegionProviderFunc(region, &providers)), + testAccCheckAWSS3BucketExistsWithProvider("aws_s3_bucket.destination", testAccAwsRegionProviderFunc("eu-west-1", &providers)), + ), + }, + }, + }) +} + func TestAccAWSS3Bucket_ReplicationSchemaV2(t *testing.T) { rInt := acctest.RandInt() region := testAccGetRegion() @@ -1127,7 +1154,7 @@ func TestAccAWSS3Bucket_ReplicationSchemaV2(t *testing.T) { // record the initialized providers so that we can use them to check for the instances in each region var providers []*schema.Provider - resource.Test(t, resource.TestCase{ + resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) testAccMultipleRegionsPreCheck(t) @@ -2640,6 +2667,43 @@ resource "aws_s3_bucket" "destination" { `, randInt, randInt, randInt) } +func testAccAWSS3BucketConfigReplicationWithoutPrefix(randInt int) string { + return fmt.Sprintf(testAccAWSS3BucketConfigReplicationBasic+` +resource "aws_s3_bucket" "bucket" { + provider = "aws.uswest2" + bucket = "tf-test-bucket-%d" + acl = "private" + + versioning { + enabled = true + } + + replication_configuration { + role = "${aws_iam_role.role.arn}" + rules { + id = "foobar" + status = "Enabled" + + destination { + bucket = "${aws_s3_bucket.destination.arn}" + storage_class = "STANDARD" + } + } + } +} + +resource "aws_s3_bucket" "destination" { + provider = "aws.euwest" + bucket = "tf-test-bucket-destination-%d" + region = "eu-west-1" + + versioning { + enabled = true + } +} +`, randInt, randInt, randInt) +} + func testAccAWSS3BucketConfigReplicationNoVersioning(randInt int) string { return fmt.Sprintf(testAccAWSS3BucketConfigReplicationBasic+` resource "aws_s3_bucket" "bucket" {