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

feat: add replication_time to aws_s3_bucket.replication_configuration #21176

Merged
merged 7 commits into from
Oct 26, 2021
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
3 changes: 3 additions & 0 deletions .changelog/21176.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
resource/aws_s3_bucket: Add `metrics` and `replication_time` arguments to `replication_configuration.rules` configuration block to support Amazon S3 Replication Time Control
```
116 changes: 116 additions & 0 deletions internal/service/s3/bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,48 @@ func ResourceBucket() *schema.Resource {
},
},
},
"replication_time": {
Type: schema.TypeList,
Optional: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"minutes": {
Type: schema.TypeInt,
Optional: true,
Default: 15,
ValidateFunc: validation.IntBetween(15, 15),
},
"status": {
Type: schema.TypeString,
Optional: true,
Default: s3.ReplicationTimeStatusEnabled,
ValidateFunc: validation.StringInSlice(s3.ReplicationTimeStatus_Values(), false),
},
},
},
},
"metrics": {
Type: schema.TypeList,
Optional: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"minutes": {
Type: schema.TypeInt,
Optional: true,
Default: 15,
ValidateFunc: validation.IntBetween(10, 15),
},
"status": {
Type: schema.TypeString,
Optional: true,
Default: s3.MetricsStatusEnabled,
ValidateFunc: validation.StringInSlice(s3.MetricsStatus_Values(), false),
},
},
},
},
},
},
},
Expand Down Expand Up @@ -2069,6 +2111,26 @@ func resourceBucketReplicationConfigurationUpdate(conn *s3.S3, d *schema.Resourc
ruleAclTranslation.Owner = aws.String(aclTranslationValues["owner"].(string))
ruleDestination.AccessControlTranslation = ruleAclTranslation
}

// replication metrics (required for RTC)
if metrics, ok := bd["metrics"].([]interface{}); ok && len(metrics) > 0 {
metricsConfig := &s3.Metrics{}
metricsValues := metrics[0].(map[string]interface{})
metricsConfig.EventThreshold = &s3.ReplicationTimeValue{}
metricsConfig.Status = aws.String(metricsValues["status"].(string))
metricsConfig.EventThreshold.Minutes = aws.Int64(int64(metricsValues["minutes"].(int)))
ruleDestination.Metrics = metricsConfig
}

// replication time control (RTC)
if rtc, ok := bd["replication_time"].([]interface{}); ok && len(rtc) > 0 {
rtcValues := rtc[0].(map[string]interface{})
rtcConfig := &s3.ReplicationTime{}
rtcConfig.Status = aws.String(rtcValues["status"].(string))
rtcConfig.Time = &s3.ReplicationTimeValue{}
rtcConfig.Time.Minutes = aws.Int64(int64(rtcValues["minutes"].(int)))
ruleDestination.ReplicationTime = rtcConfig
}
}
}
rcRule.Destination = ruleDestination
Expand Down Expand Up @@ -2355,6 +2417,20 @@ func flattenBucketReplicationConfiguration(r *s3.ReplicationConfiguration) []map
if v.Destination.StorageClass != nil {
rd["storage_class"] = aws.StringValue(v.Destination.StorageClass)
}
if v.Destination.ReplicationTime != nil {
rtc := map[string]interface{}{
"minutes": int(aws.Int64Value(v.Destination.ReplicationTime.Time.Minutes)),
"status": aws.StringValue(v.Destination.ReplicationTime.Status),
}
rd["replication_time"] = []interface{}{rtc}
}
if v.Destination.Metrics != nil {
metrics := map[string]interface{}{
"minutes": int(aws.Int64Value(v.Destination.Metrics.EventThreshold.Minutes)),
"status": aws.StringValue(v.Destination.Metrics.Status),
}
rd["metrics"] = []interface{}{metrics}
}
if v.Destination.EncryptionConfiguration != nil {
if v.Destination.EncryptionConfiguration.ReplicaKmsKeyID != nil {
rd["replica_kms_key_id"] = aws.StringValue(v.Destination.EncryptionConfiguration.ReplicaKmsKeyID)
Expand Down Expand Up @@ -2633,6 +2709,12 @@ func destinationHash(v interface{}) int {
if v, ok := m["access_control_translation"].([]interface{}); ok && len(v) > 0 && v[0] != nil {
buf.WriteString(fmt.Sprintf("%d-", accessControlTranslationHash(v[0])))
}
if v, ok := m["replication_time"].([]interface{}); ok && len(v) > 0 && v[0] != nil {
buf.WriteString(fmt.Sprintf("%d-", replicationTimeHash(v[0])))
}
if v, ok := m["metrics"].([]interface{}); ok && len(v) > 0 && v[0] != nil {
buf.WriteString(fmt.Sprintf("%d-", metricsHash(v[0])))
}
return create.StringHashcode(buf.String())
}

Expand All @@ -2650,6 +2732,40 @@ func accessControlTranslationHash(v interface{}) int {
return create.StringHashcode(buf.String())
}

func metricsHash(v interface{}) int {
var buf bytes.Buffer
m, ok := v.(map[string]interface{})

if !ok {
return 0
}

if v, ok := m["minutes"]; ok {
buf.WriteString(fmt.Sprintf("%d-", v.(int)))
}
if v, ok := m["status"]; ok {
buf.WriteString(fmt.Sprintf("%s-", v.(string)))
}
return create.StringHashcode(buf.String())
}

func replicationTimeHash(v interface{}) int {
var buf bytes.Buffer
m, ok := v.(map[string]interface{})

if !ok {
return 0
}

if v, ok := m["minutes"]; ok {
buf.WriteString(fmt.Sprintf("%d-", v.(int)))
}
if v, ok := m["status"]; ok {
buf.WriteString(fmt.Sprintf("%s-", v.(string)))
}
return create.StringHashcode(buf.String())
}

func sourceSelectionCriteriaHash(v interface{}) int {
var buf bytes.Buffer
m, ok := v.(map[string]interface{})
Expand Down
Loading