Skip to content
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/s3_bucket_replication_configuration: Add token parameter for x-amz-bucket-object-lock-token #23624

Merged
merged 4 commits into from
Mar 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changelog/23624.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
```release-note:enhancement
resource/aws_s3_bucket_replication_configuration: Add `token` field to specify
x-amz-bucket-object-lock-token for enabling replication on object lock enabled
buckets or enabling object lock on an existing bucket.
```
13 changes: 13 additions & 0 deletions internal/service/s3/bucket_replication_configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ func ResourceBucketReplicationConfiguration() *schema.Resource {
Required: true,
ValidateFunc: verify.ValidARN,
},
"token": {
alexb-dd marked this conversation as resolved.
Show resolved Hide resolved
Type: schema.TypeString,
Optional: true,
Sensitive: true,
},
"rule": {
Type: schema.TypeSet,
Required: true,
Expand Down Expand Up @@ -311,6 +316,10 @@ func resourceBucketReplicationConfigurationCreate(d *schema.ResourceData, meta i
ReplicationConfiguration: rc,
}

if v, ok := d.GetOk("token"); ok {
input.Token = aws.String(v.(string))
}

err := resource.Retry(propagationTimeout, func() *resource.RetryError {
_, err := conn.PutBucketReplication(input)
if tfawserr.ErrCodeEquals(err, s3.ErrCodeNoSuchBucket) || tfawserr.ErrMessageContains(err, "InvalidRequest", "Versioning must be 'Enabled' on the bucket") {
Expand Down Expand Up @@ -387,6 +396,10 @@ func resourceBucketReplicationConfigurationUpdate(d *schema.ResourceData, meta i
ReplicationConfiguration: rc,
}

if v, ok := d.GetOk("token"); ok {
input.Token = aws.String(v.(string))
}

err := resource.Retry(propagationTimeout, func() *resource.RetryError {
_, err := conn.PutBucketReplication(input)
if tfawserr.ErrCodeEquals(err, s3.ErrCodeNoSuchBucket) || tfawserr.ErrMessageContains(err, "InvalidRequest", "Versioning must be 'Enabled' on the bucket") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,8 @@ The following arguments are supported:
* `bucket` - (Required) The name of the source S3 bucket you want Amazon S3 to monitor.
* `role` - (Required) The ARN of the IAM role for Amazon S3 to assume when replicating the objects.
* `rule` - (Required) Set of configuration blocks describing the rules managing the replication [documented below](#rule).
* `token` - (Optional) A token to allow replication to be enabled on an Object Lock-enabled bucket. You must contact AWS support for the bucket's "Object Lock token".
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very minor nit: do you mind moving token just below rule to maintain the order?

Copy link
Contributor

@anGie44 anGie44 Mar 11, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Going to edit this as we're going to do a release today and would love to get this in as it's ready to go 🚀

For more details, see [Using S3 Object Lock with replication](https://docs.aws.amazon.com/AmazonS3/latest/userguide/object-lock-managing.html#object-lock-managing-replication).

### rule

Expand Down