Skip to content

Commit

Permalink
r/s3_bucket_replication_configuration: backport #23624, #23616, #23586,
Browse files Browse the repository at this point in the history
  • Loading branch information
anGie44 committed Mar 16, 2022
1 parent 552f472 commit a4e696d
Show file tree
Hide file tree
Showing 5 changed files with 600 additions and 155 deletions.
19 changes: 16 additions & 3 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 @@ -303,14 +308,18 @@ func resourceBucketReplicationConfigurationCreate(d *schema.ResourceData, meta i

rc := &s3.ReplicationConfiguration{
Role: aws.String(d.Get("role").(string)),
Rules: ExpandRules(d.Get("rule").(*schema.Set).List()),
Rules: ExpandReplicationRules(d.Get("rule").(*schema.Set).List()),
}

input := &s3.PutBucketReplicationInput{
Bucket: aws.String(bucket),
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 @@ -367,7 +376,7 @@ func resourceBucketReplicationConfigurationRead(d *schema.ResourceData, meta int

d.Set("bucket", d.Id())
d.Set("role", r.Role)
if err := d.Set("rule", schema.NewSet(rulesHash, FlattenRules(r.Rules))); err != nil {
if err := d.Set("rule", schema.NewSet(rulesHash, FlattenReplicationRules(r.Rules))); err != nil {
return fmt.Errorf("error setting rule: %w", err)
}

Expand All @@ -379,14 +388,18 @@ func resourceBucketReplicationConfigurationUpdate(d *schema.ResourceData, meta i

rc := &s3.ReplicationConfiguration{
Role: aws.String(d.Get("role").(string)),
Rules: ExpandRules(d.Get("rule").(*schema.Set).List()),
Rules: ExpandReplicationRules(d.Get("rule").(*schema.Set).List()),
}

input := &s3.PutBucketReplicationInput{
Bucket: aws.String(d.Id()),
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
Loading

0 comments on commit a4e696d

Please sign in to comment.