Skip to content

Commit

Permalink
Merge pull request #6344 from ewbankkit/issue-6340
Browse files Browse the repository at this point in the history
r/aws_s3_bucket: Fix 'Error putting S3 replication configuration: MalformedXML' error
  • Loading branch information
bflad authored Nov 7, 2018
2 parents 0c2ec1c + 2ccd7b1 commit 197d49f
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 4 deletions.
6 changes: 3 additions & 3 deletions aws/resource_aws_s3_bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down
66 changes: 65 additions & 1 deletion aws/resource_aws_s3_bucket_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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)
Expand Down Expand Up @@ -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" {
Expand Down

0 comments on commit 197d49f

Please sign in to comment.