Skip to content

Commit bac92f9

Browse files
authored
fix: cos - lifecycle rule id and delete marker (#910)
1 parent 7316a5a commit bac92f9

File tree

4 files changed

+28
-2
lines changed

4 files changed

+28
-2
lines changed

tencentcloud/resource_tc_cos_bucket.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -619,6 +619,11 @@ func resourceTencentCloudCosBucket() *schema.Resource {
619619
ValidateFunc: validateIntegerMin(0),
620620
Description: "Specifies the number of days after object creation when the specific rule action takes effect.",
621621
},
622+
"delete_marker": {
623+
Type: schema.TypeBool,
624+
Optional: true,
625+
Description: "Indicates whether the delete marker of an expired object will be removed.",
626+
},
622627
},
623628
},
624629
},
@@ -1288,7 +1293,11 @@ func resourceTencentCloudCosBucketLifecycleUpdate(ctx context.Context, client *s
12881293
for i, lifecycleRule := range lifecycleRules {
12891294
r := lifecycleRule.(map[string]interface{})
12901295
rule := &s3.LifecycleRule{}
1291-
rule.Status = aws.String(s3.ExpirationStatusEnabled)
1296+
id, ok := r["id"].(string)
1297+
if ok {
1298+
rule.ID = &id
1299+
}
1300+
rule.Status = helper.String(s3.ExpirationStatusEnabled)
12921301
prefix := r["filter_prefix"].(string)
12931302
rule.Filter = &s3.LifecycleRuleFilter{
12941303
Prefix: &prefix,
@@ -1324,7 +1333,7 @@ func resourceTencentCloudCosBucketLifecycleUpdate(ctx context.Context, client *s
13241333
expiration := expirations[0].(map[string]interface{})
13251334
e := &s3.LifecycleExpiration{}
13261335

1327-
if val, ok := expiration["data"].(string); ok && val != "" {
1336+
if val, ok := expiration["date"].(string); ok && val != "" {
13281337
date, err := time.Parse(time.RFC3339, fmt.Sprintf("%sT00:00:00Z", val))
13291338
if err != nil {
13301339
return fmt.Errorf("parsing cos bucket lifecycle expiration data(%s) error: %s", val, err.Error())
@@ -1334,6 +1343,10 @@ func resourceTencentCloudCosBucketLifecycleUpdate(ctx context.Context, client *s
13341343
e.Days = aws.Int64(int64(val))
13351344
}
13361345

1346+
if val, ok := expiration["delete_marker"].(bool); ok && val {
1347+
e.ExpiredObjectDeleteMarker = helper.Bool(true)
1348+
}
1349+
13371350
rule.Expiration = e
13381351
}
13391352

tencentcloud/resource_tc_cos_bucket_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,7 @@ func TestAccTencentCloudCosBucket_lifecycle(t *testing.T) {
225225
Check: resource.ComposeAggregateTestCheckFunc(
226226
testAccCheckCosBucketExists("tencentcloud_cos_bucket.bucket_lifecycle"),
227227
resource.TestCheckResourceAttr("tencentcloud_cos_bucket.bucket_lifecycle", "lifecycle_rules.#", "1"),
228+
resource.TestCheckResourceAttr("tencentcloud_cos_bucket.bucket_lifecycle", "lifecycle_rules.0.id", "rule1"),
228229
resource.TestCheckResourceAttr("tencentcloud_cos_bucket.bucket_lifecycle", "lifecycle_rules.0.filter_prefix", "test/"),
229230
resource.TestCheckResourceAttr("tencentcloud_cos_bucket.bucket_lifecycle", "lifecycle_rules.0.expiration.#", "1"),
230231
resource.TestCheckResourceAttr("tencentcloud_cos_bucket.bucket_lifecycle", "lifecycle_rules.0.expiration.3672460294.days", "365"),
@@ -654,7 +655,9 @@ func testAccBucket_lifecycle(appid string) string {
654655
resource "tencentcloud_cos_bucket" "bucket_lifecycle" {
655656
bucket = "tf-bucket-lifecycle-%s"
656657
acl = "public-read"
658+
versioning_enable = true
657659
lifecycle_rules {
660+
id = "rule1"
658661
filter_prefix = "test/"
659662
expiration {
660663
days = 365
@@ -677,7 +680,9 @@ func testAccBucket_lifecycleUpdate(appid string) string {
677680
resource "tencentcloud_cos_bucket" "bucket_lifecycle" {
678681
bucket = "tf-bucket-lifecycle-%s"
679682
acl = "public-read"
683+
versioning_enable = true
680684
lifecycle_rules {
685+
id = "rule1"
681686
filter_prefix = "test/"
682687
expiration {
683688
days = 300

tencentcloud/service_tencentcloud_cos.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,10 @@ func (me *CosService) GetBucketLifecycle(ctx context.Context, bucket string) (li
340340
for _, value := range response.Rules {
341341
rule := make(map[string]interface{})
342342

343+
if value.ID != nil {
344+
rule["id"] = *value.ID
345+
}
346+
343347
// filter_prefix
344348
if value.Filter != nil {
345349
if value.Filter.And != nil && value.Filter.And.Prefix != nil &&
@@ -376,6 +380,9 @@ func (me *CosService) GetBucketLifecycle(ctx context.Context, bucket string) (li
376380
if value.Expiration.Days != nil {
377381
e["days"] = int(*value.Expiration.Days)
378382
}
383+
if value.Expiration.ExpiredObjectDeleteMarker != nil {
384+
e["delete_marker"] = *value.Expiration.ExpiredObjectDeleteMarker
385+
}
379386
rule["expiration"] = schema.NewSet(expirationHash, []interface{}{e})
380387
}
381388

website/docs/r/cos_bucket.html.markdown

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,7 @@ The `expiration` object supports the following:
266266

267267
* `date` - (Optional) Specifies the date after which you want the corresponding action to take effect.
268268
* `days` - (Optional) Specifies the number of days after object creation when the specific rule action takes effect.
269+
* `delete_marker` - (Optional) Indicates whether the delete marker of an expired object will be removed.
269270

270271
The `lifecycle_rules` object supports the following:
271272

0 commit comments

Comments
 (0)