Skip to content

Commit

Permalink
Merge pull request #23624 from alexb-dd/f-replconfig-token
Browse files Browse the repository at this point in the history
r/s3_bucket_replication_configuration: Add token parameter for x-amz-bucket-object-lock-token
  • Loading branch information
anGie44 authored Mar 11, 2022
2 parents 79a092a + beac59f commit 538c633
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
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": {
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 @@ -219,6 +219,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".
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

0 comments on commit 538c633

Please sign in to comment.