Skip to content

Commit c19ca82

Browse files
authored
cos bucket adds abort_incomplete_multipart_upload parameter (#2449)
* cos bucket adds abort_incomplete_multipart_upload parameter * add changelog 2449.txt
1 parent 8e94762 commit c19ca82

File tree

8 files changed

+100
-7
lines changed

8 files changed

+100
-7
lines changed

.changelog/2449.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
```release-note:enhancement
2+
resource/tencentcloud_cos_bucket: add `abort_incomplete_multipart_upload` field
3+
```
4+
5+
```release-note:enhancement
6+
datasource/tencentcloud_cos_buckets: add `abort_incomplete_multipart_upload` field
7+
```

tencentcloud/services/cos/data_source_tc_cos_buckets.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,20 @@ func DataSourceTencentCloudCosBuckets() *schema.Resource {
172172
},
173173
},
174174
},
175+
"abort_incomplete_multipart_upload": {
176+
Type: schema.TypeList,
177+
Computed: true,
178+
Description: "Set the maximum time a multipart upload is allowed to remain running.",
179+
Elem: &schema.Resource{
180+
Schema: map[string]*schema.Schema{
181+
"days_after_initiation": {
182+
Type: schema.TypeInt,
183+
Computed: true,
184+
Description: "Specifies the number of days after the multipart upload starts that the upload must be completed. The maximum value is 3650.",
185+
},
186+
},
187+
},
188+
},
175189
},
176190
},
177191
},

tencentcloud/services/cos/data_source_tc_cos_buckets_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@ func TestAccTencentCloudCosBucketDataSource_full(t *testing.T) {
8585
"bucket_list.0.lifecycle_rules.0.non_current_expiration.#", "1"),
8686
resource.TestCheckResourceAttr("data.tencentcloud_cos_buckets.bucket_list",
8787
"bucket_list.0.lifecycle_rules.0.non_current_transition.#", "2"),
88+
resource.TestCheckResourceAttr("data.tencentcloud_cos_buckets.bucket_list",
89+
"bucket_list.0.lifecycle_rules.0.abort_incomplete_multipart_upload.#", "1"),
90+
resource.TestCheckResourceAttr("data.tencentcloud_cos_buckets.bucket_list",
91+
"bucket_list.0.lifecycle_rules.0.abort_incomplete_multipart_upload.0.days_after_initiation", "1"),
8892
resource.TestCheckResourceAttr("data.tencentcloud_cos_buckets.bucket_list", "bucket_list.0.website.#", "1"),
8993
resource.TestCheckResourceAttr("data.tencentcloud_cos_buckets.bucket_list", "bucket_list.0.website.0.index_document", "index.html"),
9094
resource.TestCheckResourceAttr("data.tencentcloud_cos_buckets.bucket_list", "bucket_list.0.website.0.error_document", "error.html"),
@@ -158,6 +162,10 @@ resource "tencentcloud_cos_bucket" "bucket_full" {
158162
non_current_days = 180
159163
storage_class = "ARCHIVE"
160164
}
165+
166+
abort_incomplete_multipart_upload {
167+
days_after_initiation = 1
168+
}
161169
}
162170
163171
website {

tencentcloud/services/cos/resource_tc_cos_bucket.go

Lines changed: 42 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,23 @@ func ResourceTencentCloudCosBucket() *schema.Resource {
433433
},
434434
},
435435
},
436+
"abort_incomplete_multipart_upload": {
437+
Type: schema.TypeSet,
438+
Optional: true,
439+
Set: abortIncompleteMultipartUploadHash,
440+
MaxItems: 1,
441+
Description: "Set the maximum time a multipart upload is allowed to remain running.",
442+
Elem: &schema.Resource{
443+
Schema: map[string]*schema.Schema{
444+
"days_after_initiation": {
445+
Type: schema.TypeInt,
446+
Required: true,
447+
ValidateFunc: tccommon.ValidateIntegerMin(1),
448+
Description: "Specifies the number of days after the multipart upload starts that the upload must be completed. The maximum value is 3650.",
449+
},
450+
},
451+
},
452+
},
436453
},
437454
},
438455
},
@@ -920,13 +937,9 @@ func waitAclEnable(ctx context.Context, meta interface{}, bucket string) error {
920937
err := resource.Retry(tccommon.ReadRetryTimeout, func() *resource.RetryError {
921938
aclResult, e := cosService.GetBucketACL(ctx, bucket)
922939
if e != nil {
923-
sdkError, ok := e.(*errors.TencentCloudSDKError)
924-
if ok {
925-
log.Printf("[CRITAL]%s api[%s] fail when try to update acl, reason[%s,%s,%s]\n", logId, "GetBucketACL", sdkError.Error(), sdkError.GetCode(), sdkError.GetMessage())
926-
927-
if strings.Contains(sdkError.GetMessage(), "NoSuchBucket") {
928-
return resource.RetryableError(fmt.Errorf("[CRITAL][retry]%s api[%s] it still on creating, need try again.\n", logId, "GetBucketACL"))
929-
}
940+
if strings.Contains(e.Error(), "NoSuchBucket") {
941+
log.Printf("[CRITAL][retry]%s api[%s] because of bucket[%s] still on creating, need try again.\n", logId, "GetBucketACL", bucket)
942+
return resource.RetryableError(fmt.Errorf("[CRITAL][retry]%s api[%s] it still on creating, need try again.\n", logId, "GetBucketACL"))
930943
}
931944
log.Printf("[CRITAL]%s api[%s] fail when try to update acl, reason[%s]\n", logId, "GetBucketACL", e.Error())
932945
return resource.NonRetryableError(e)
@@ -1291,6 +1304,19 @@ func resourceTencentCloudCosBucketLifecycleUpdate(ctx context.Context, meta inte
12911304

12921305
rule.NoncurrentVersionExpiration = e
12931306
}
1307+
1308+
// AbortIncompleteMultipartUpload
1309+
abortIncompleteMultipartUploads := d.Get(fmt.Sprintf("lifecycle_rules.%d.abort_incomplete_multipart_upload", i)).(*schema.Set).List()
1310+
if len(abortIncompleteMultipartUploads) > 0 {
1311+
abortIncompleteMultipartUpload := abortIncompleteMultipartUploads[0].(map[string]interface{})
1312+
e := &s3.AbortIncompleteMultipartUpload{}
1313+
1314+
if val, ok := abortIncompleteMultipartUpload["days_after_initiation"].(int); ok && val > 0 {
1315+
e.DaysAfterInitiation = aws.Int64(int64(val))
1316+
}
1317+
1318+
rule.AbortIncompleteMultipartUpload = e
1319+
}
12941320
rules = append(rules, rule)
12951321
}
12961322

@@ -1664,6 +1690,15 @@ func nonCurrentExpirationHash(v interface{}) int {
16641690
return helper.HashString(buf.String())
16651691
}
16661692

1693+
func abortIncompleteMultipartUploadHash(v interface{}) int {
1694+
var buf bytes.Buffer
1695+
m := v.(map[string]interface{})
1696+
if v, ok := m["days_after_initiation"]; ok {
1697+
buf.WriteString(fmt.Sprintf("%d-", v.(int)))
1698+
}
1699+
return helper.HashString(buf.String())
1700+
}
1701+
16671702
func transitionHash(v interface{}) int {
16681703
var buf bytes.Buffer
16691704
m := v.(map[string]interface{})

tencentcloud/services/cos/resource_tc_cos_bucket_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,8 @@ func TestAccTencentCloudCosBucketResource_lifecycle(t *testing.T) {
273273
}),
274274
resource.TestCheckResourceAttr("tencentcloud_cos_bucket.bucket_lifecycle", "lifecycle_rules.0.non_current_expiration.#", "1"),
275275
resource.TestCheckResourceAttr("tencentcloud_cos_bucket.bucket_lifecycle", "lifecycle_rules.0.non_current_transition.#", "2"),
276+
resource.TestCheckResourceAttr("tencentcloud_cos_bucket.bucket_lifecycle", "lifecycle_rules.0.abort_incomplete_multipart_upload.#", "1"),
277+
resource.TestCheckResourceAttr("tencentcloud_cos_bucket.bucket_lifecycle", "lifecycle_rules.0.abort_incomplete_multipart_upload.0.days_after_initiation", "1"),
276278
),
277279
},
278280
{
@@ -786,6 +788,10 @@ resource "tencentcloud_cos_bucket" "bucket_lifecycle" {
786788
non_current_days = 180
787789
storage_class = "ARCHIVE"
788790
}
791+
792+
abort_incomplete_multipart_upload {
793+
days_after_initiation = 1
794+
}
789795
}
790796
}
791797
`, tcacctest.UserInfoData)

tencentcloud/services/cos/service_tencentcloud_cos.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -571,6 +571,14 @@ func (me *CosService) GetBucketLifecycle(ctx context.Context, bucket string) (li
571571
}
572572
rule["non_current_expiration"] = schema.NewSet(nonCurrentExpirationHash, []interface{}{e})
573573
}
574+
// abortIncompleteMultipartUpload
575+
if value.AbortIncompleteMultipartUpload != nil {
576+
e := make(map[string]interface{})
577+
if value.AbortIncompleteMultipartUpload.DaysAfterInitiation != nil {
578+
e["days_after_initiation"] = int(*value.AbortIncompleteMultipartUpload.DaysAfterInitiation)
579+
}
580+
rule["abort_incomplete_multipart_upload"] = schema.NewSet(abortIncompleteMultipartUploadHash, []interface{}{e})
581+
}
574582

575583
lifecycleRules = append(lifecycleRules, rule)
576584
}
@@ -667,6 +675,14 @@ func (me *CosService) GetDataSourceBucketLifecycle(ctx context.Context, bucket s
667675
}
668676
rule["non_current_expiration"] = []interface{}{e}
669677
}
678+
// abortIncompleteMultipartUpload
679+
if value.AbortIncompleteMultipartUpload != nil {
680+
e := make(map[string]interface{})
681+
if value.AbortIncompleteMultipartUpload.DaysAfterInitiation != nil {
682+
e["days_after_initiation"] = int(*value.AbortIncompleteMultipartUpload.DaysAfterInitiation)
683+
}
684+
rule["abort_incomplete_multipart_upload"] = []interface{}{e}
685+
}
670686

671687
lifecycleRules = append(lifecycleRules, rule)
672688
}

website/docs/d/cos_buckets.html.markdown

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ In addition to all arguments above, the following attributes are exported:
4444
* `max_age_seconds` - Specifies time in seconds that browser can cache the response for a preflight request.
4545
* `cos_bucket_url` - The URL of this cos bucket.
4646
* `lifecycle_rules` - The lifecycle configuration of a bucket.
47+
* `abort_incomplete_multipart_upload` - Set the maximum time a multipart upload is allowed to remain running.
48+
* `days_after_initiation` - Specifies the number of days after the multipart upload starts that the upload must be completed. The maximum value is 3650.
4749
* `expiration` - Specifies a period in the object's expire.
4850
* `date` - Specifies the date after which you want the corresponding action to take effect.
4951
* `days` - Specifies the number of days after object creation when the specific rule action takes effect.

website/docs/r/cos_bucket.html.markdown

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,10 @@ The following arguments are supported:
256256
* `versioning_enable` - (Optional, Bool) Enable bucket versioning. NOTE: The `multi_az` feature is true for the current bucket, cannot disable version control.
257257
* `website` - (Optional, List) A website object(documented below).
258258

259+
The `abort_incomplete_multipart_upload` object of `lifecycle_rules` supports the following:
260+
261+
* `days_after_initiation` - (Required, Int) Specifies the number of days after the multipart upload starts that the upload must be completed. The maximum value is 3650.
262+
259263
The `cors_rules` object supports the following:
260264

261265
* `allowed_headers` - (Required, List) Specifies which headers are allowed.
@@ -273,6 +277,7 @@ The `expiration` object of `lifecycle_rules` supports the following:
273277
The `lifecycle_rules` object supports the following:
274278

275279
* `filter_prefix` - (Required, String) Object key prefix identifying one or more objects to which the rule applies.
280+
* `abort_incomplete_multipart_upload` - (Optional, Set) Set the maximum time a multipart upload is allowed to remain running.
276281
* `expiration` - (Optional, Set) Specifies a period in the object's expire (documented below).
277282
* `id` - (Optional, String) A unique identifier for the rule. It can be up to 255 characters.
278283
* `non_current_expiration` - (Optional, Set) Specifies when non current object versions shall expire.

0 commit comments

Comments
 (0)