-
Notifications
You must be signed in to change notification settings - Fork 9.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
r/aws_s3_bucket: Support S3 Cross-Region Replication filtering based on S3 object tags #6095
Conversation
err := resource.Retry(1*time.Minute, func() *resource.RetryError { | ||
if _, err := s3conn.PutBucketReplication(i); err != nil { | ||
if isAWSErr(err, s3.ErrCodeNoSuchBucket, "") || | ||
isAWSErr(err, "InvalidRequest", "Versioning must be 'Enabled' on the bucket") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This check fixes #828.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
Prefix: aws.String(rr["prefix"].(string)), | ||
Status: aws.String(rr["status"].(string)), | ||
rcRule := &s3.ReplicationRule{} | ||
if status, ok := rr["status"]; ok && status != "" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This check and the subsequent continue
is required for updates when the bucket is using CRR schema V2 or else the PutBucketReplication
API call fails with missing Bucket Name errors.
@@ -1577,6 +1758,14 @@ func testAccCheckAWSS3BucketReplicationRules(n string, providerF func() *schema. | |||
} | |||
} | |||
} | |||
// Sort filter tags by key. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to sort both the specified and returned filter tags as they are in non-deterministic order and I was getting errors like
$ make testacc TEST=./aws/ TESTARGS='-run=TestAccAWSS3Bucket_ReplicationSchemaV2'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws/ -v -parallel 20 -run=TestAccAWSS3Bucket_ReplicationSchemaV2 -timeout 120m
=== RUN TestAccAWSS3Bucket_ReplicationSchemaV2
--- FAIL: TestAccAWSS3Bucket_ReplicationSchemaV2 (167.52s)
testing.go:538: Step 3 error: Check failed: Check 6/6 error: bad replication rules, expected: [{
DeleteMarkerReplication: {
Status: "Disabled"
},
Destination: {
Bucket: "arn:aws:s3:::tf-test-bucket-destination-5528715964644708672",
StorageClass: "STANDARD"
},
Filter: {
And: {
Tags: [{
Key: "ReplicateMe",
Value: "Yes"
},{
Key: "AnotherTag",
Value: "OK"
},{
Key: "Foo",
Value: "Bar"
}]
}
},
ID: "foobar",
Priority: 0,
Status: "Enabled"
}], got [{
DeleteMarkerReplication: {
Status: "Disabled"
},
Destination: {
Bucket: "arn:aws:s3:::tf-test-bucket-destination-5528715964644708672",
StorageClass: "STANDARD"
},
Filter: {
And: {
Prefix: "",
Tags: [{
Key: "AnotherTag",
Value: "OK"
},{
Key: "ReplicateMe",
Value: "Yes"
},{
Key: "Foo",
Value: "Bar"
}]
}
},
ID: "foobar",
Priority: 0,
Status: "Enabled"
}]
FAIL
FAIL github.com/terraform-providers/terraform-provider-aws/aws 167.532s
GNUmakefile:20: recipe for target 'testacc' failed
make: *** [testacc] Error 1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
Removed WIP, ready for review. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, excellent job @ewbankkit! 🚀 I've run the acceptance times a few times and passes just fine.
err := resource.Retry(1*time.Minute, func() *resource.RetryError { | ||
if _, err := s3conn.PutBucketReplication(i); err != nil { | ||
if isAWSErr(err, s3.ErrCodeNoSuchBucket, "") || | ||
isAWSErr(err, "InvalidRequest", "Versioning must be 'Enabled' on the bucket") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
@@ -1577,6 +1758,14 @@ func testAccCheckAWSS3BucketReplicationRules(n string, providerF func() *schema. | |||
} | |||
} | |||
} | |||
// Sort filter tags by key. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
This has been released in version 1.42.0 of the AWS provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading. |
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thanks! |
Fixes #828
Fixes #5940.
Acceptance tests: