-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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
Adds the S3 Replication AccessControlTranslation and Account arguments #3577
Conversation
3f4370c
to
f0e9511
Compare
Just expressing my interest in this as well. I run a bunch of EC2 instances that continually write stuff to S3 (which then get replicated to another account), and the lack of this feature means that I have to pause my cluster and let things drain out for a few hours before I can deploy my terraform; deploying breaks the replication configuration, at which point I need to use aws cli to reset it |
A +1 from me for this feature too. I'm in a similar position to @seanscofield with data continually being written to a bucket. Unfortunately in my scenario I cannot pause the data coming in which leaves me with an issue if Terraform resets the rules and data is replicated before reapplying outside of it. Can anyone give an indication on when this feature is likely to become available @radeksimko ? |
If anybody is interested in testing out this feature in a patched v1.21.0 version, I've made some Alpine Linux x64 binaries available here: https://github.com/lifeomic/terraform-provider-aws/releases/tag/v1.21.0_patched_5f7d0def |
@radeksimko is there anything I can do to help this get merged into an official release? |
I'd be happy to make any changes necessary to get this in too. I'd especially love some feedback on the code and tests |
9370b16
to
677035f
Compare
|
Ok, I run the whole set of s3 bucket acceptance tests. They seem to be inconsistent.
|
If anybody is interested in testing out this feature in a patched v1.36.0 version, I've made some Alpine Linux x64 binaries available here: https://github.com/lifeomic/terraform-provider-aws/releases/tag/v1.36.0_patched_f2d0f833c |
78d828a
to
4518e09
Compare
@@ -377,6 +377,10 @@ func resourceAwsS3Bucket() *schema.Resource { | |||
Set: destinationHash, | |||
Elem: &schema.Resource{ | |||
Schema: map[string]*schema.Schema{ | |||
"account": { |
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.
I'd suggest renaming this to account_id
to match similar places in the code base.
Also can add ValidateFunc: validateAwsAccountId,
.
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.
Both these seem reasonable and will be updated on merge.
* Switch replication rule destination access_control_translation from TypeSet to TypeList * Add replication rule destination account validation * Add replication rule destination access_control_translation owner validation * Split replication rule destination access_control_translation acceptance testing into its own function and add non-encrypted configuration TestStep * Ensure testAccCheckAWSS3BucketReplicationRules can translate HIL references in Rule.Destination.Account
@ewbankkit thanks for the feedback here - I have some in-flight changes already and will try to incorporate some of your feedback. |
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.
Hi @jrstarke 👋 Thank you so much for submitting this and your patience! Overall it was in fantastic shape. I hope you don't mind I made a few minor adjustments in a followup commit on merge (a9c5649) based on mine and @ewbankkit's feedback below just so we could get this released today.
LGTM after running the acceptance testing multiple passes. 🚀
{ | ||
ID: aws.String("foobar"), | ||
Destination: &s3.Destination{ | ||
Account: aws.String("${data.aws_caller_identity.current.account_id}"), |
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.
I'm not sure how this was passing previously, but I needed to add the HIL translation for this parameter in testAccCheckAWSS3BucketReplicationRules
for the testing to pass for me. 😄
if account := dest.Account; account != nil && strings.HasPrefix(aws.StringValue(dest.Account), "${") {
resourceReference := strings.Replace(aws.StringValue(dest.Account), "${", "", 1)
resourceReference = strings.Replace(resourceReference, "}", "", 1)
resourceReferenceParts := strings.Split(resourceReference, ".")
resourceAttribute := resourceReferenceParts[len(resourceReferenceParts)-1]
resourceName := strings.Join(resourceReferenceParts[:len(resourceReferenceParts)-1], ".")
value := s.RootModule().Resources[resourceName].Primary.Attributes[resourceAttribute]
dest.Account = aws.String(value)
}
We should probably move this logic to its own function so it can be reused in other testing. 😅
@@ -731,6 +731,42 @@ func TestAccAWSS3Bucket_Cors_EmptyOrigin(t *testing.T) { | |||
), | |||
), | |||
}, | |||
{ |
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 generally prefer to create new, separate acceptance test functions for new attributes 👍
} | ||
if v.Destination.AccessControlTranslation != nil { | ||
rdt := make(map[string]interface{}) | ||
rdt["owner"] = *v.Destination.AccessControlTranslation.Owner |
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.
To prevent potential panics, we prefer to use the AWS Go SDK provided methods for dereferencing, e.g. aws.StringValue(v.Destination.AccessControlTranslation.Owner)
👍
* Switch replication rule destination access_control_translation from TypeSet to TypeList * Change replication rule destination account attribute naming to account_id * Add replication rule destination account_id validation * Add replication rule destination access_control_translation owner validation * Split replication rule destination access_control_translation acceptance testing into its own function and add non-encrypted configuration TestStep * Ensure testAccCheckAWSS3BucketReplicationRules can translate HIL references in Rule.Destination.Account
This has been released in version 1.40.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! |
This allows the S3 Replication to translate the owner of the objects on replication (GH-3575). This is particularly useful when you're replicating to a separate AWS Account, because otherwise, objects are by default not accessible beyond the original account. With translation, or replication, the replica account becomes the owner of the replica objects.
I'm new to Go and contributing to the Terraform Providers, so I'd love some feedback/guidance. But this feature is important enough to me that I felt it was worth the effort to learn.
I'm unsure how to set up an acceptance test for this feature, because it is, by design, cross account.
I tried running the acceptance tests, without modification, and they didn't seem to run as I would have expected
I would appreciate whatever help or guidance you can provide, as I'd love to see this feature complete.