Skip to content

Commit f206f94

Browse files
authored
fix(cls): [122484242] tencentcloud_cls_cos_shipper support new params (#3231)
* add * add * add * Update resource_tc_cls_cos_shipper.go
1 parent cf26b17 commit f206f94

File tree

4 files changed

+163
-13
lines changed

4 files changed

+163
-13
lines changed

.changelog/3231.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
resource/tencentcloud_cls_cos_shipper: support new params
3+
```

tencentcloud/services/cls/resource_tc_cls_cos_shipper.go

Lines changed: 85 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,27 @@ func ResourceTencentCloudClsCosShipper() *schema.Resource {
171171
},
172172
},
173173
},
174+
"filename_mode": {
175+
Type: schema.TypeInt,
176+
Optional: true,
177+
Description: "Naming a shipping file. Valid values: 0 (by random number); 1 (by shipping time). Default value: 0.",
178+
},
179+
"start_time": {
180+
Type: schema.TypeInt,
181+
Optional: true,
182+
Computed: true,
183+
Description: "Start time for data shipping, which cannot be earlier than the lifecycle start time of the log topic. If you do not specify this parameter, it will be set to the time when you create the data shipping task.",
184+
},
185+
"end_time": {
186+
Type: schema.TypeInt,
187+
Optional: true,
188+
Description: "End time for data shipping, which cannot be set to a future time. If you do not specify this parameter, it indicates continuous data shipping.",
189+
},
190+
"storage_type": {
191+
Type: schema.TypeString,
192+
Optional: true,
193+
Description: "COS bucket storage type. support: STANDARD_IA, ARCHIVE, DEEP_ARCHIVE, STANDARD, MAZ_STANDARD, MAZ_STANDARD_IA, INTELLIGENT_TIERING.",
194+
},
174195
},
175196
}
176197
}
@@ -201,11 +222,11 @@ func resourceTencentCloudClsCosShipperCreate(d *schema.ResourceData, meta interf
201222
request.ShipperName = helper.String(v.(string))
202223
}
203224

204-
if v, ok := d.GetOk("interval"); ok {
225+
if v, ok := d.GetOkExists("interval"); ok {
205226
request.Interval = helper.IntUint64(v.(int))
206227
}
207228

208-
if v, ok := d.GetOk("max_size"); ok {
229+
if v, ok := d.GetOkExists("max_size"); ok {
209230
request.MaxSize = helper.IntUint64(v.(int))
210231
}
211232

@@ -292,6 +313,21 @@ func resourceTencentCloudClsCosShipperCreate(d *schema.ResourceData, meta interf
292313
request.Content = contents[0]
293314
}
294315

316+
if v, ok := d.GetOkExists("filename_mode"); ok {
317+
request.FilenameMode = helper.IntUint64(v.(int))
318+
}
319+
320+
if v, ok := d.GetOkExists("start_time"); ok {
321+
request.StartTime = helper.IntInt64(v.(int))
322+
}
323+
if v, ok := d.GetOkExists("end_time"); ok {
324+
request.EndTime = helper.IntInt64(v.(int))
325+
}
326+
327+
if v, ok := d.GetOk("storage_type"); ok {
328+
request.StorageType = helper.String(v.(string))
329+
}
330+
295331
err := resource.Retry(tccommon.WriteRetryTimeout, func() *resource.RetryError {
296332
result, e := meta.(tccommon.ProviderMeta).GetAPIV3Conn().UseClsClient().CreateShipper(request)
297333
if e != nil {
@@ -300,6 +336,11 @@ func resourceTencentCloudClsCosShipperCreate(d *schema.ResourceData, meta interf
300336
log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n",
301337
logId, request.GetAction(), request.ToJsonString(), result.ToJsonString())
302338
}
339+
340+
if result == nil || result.Response == nil {
341+
return resource.NonRetryableError(fmt.Errorf("Create cls cos shipper failed, Response is nil."))
342+
}
343+
303344
response = result
304345
return nil
305346
})
@@ -309,6 +350,10 @@ func resourceTencentCloudClsCosShipperCreate(d *schema.ResourceData, meta interf
309350
return err
310351
}
311352

353+
if response.Response.ShipperId == nil {
354+
return fmt.Errorf("ShipperId is nil.")
355+
}
356+
312357
id := *response.Response.ShipperId
313358
d.SetId(id)
314359
return resourceTencentCloudClsCosShipperRead(d, meta)
@@ -393,6 +438,23 @@ func resourceTencentCloudClsCosShipperRead(d *schema.ResourceData, meta interfac
393438
}
394439
_ = d.Set("content", []interface{}{content})
395440
}
441+
442+
if shipper.FilenameMode != nil {
443+
_ = d.Set("filename_mode", shipper.FilenameMode)
444+
}
445+
446+
if shipper.StartTime != nil {
447+
_ = d.Set("start_time", shipper.StartTime)
448+
}
449+
450+
if shipper.EndTime != nil {
451+
_ = d.Set("end_time", shipper.EndTime)
452+
}
453+
454+
if shipper.StorageType != nil {
455+
_ = d.Set("storage_type", shipper.StorageType)
456+
}
457+
396458
return nil
397459
}
398460

@@ -401,6 +463,13 @@ func resourceTencentCloudClsCosShipperUpdate(d *schema.ResourceData, meta interf
401463
logId := tccommon.GetLogId(tccommon.ContextNil)
402464
request := cls.NewModifyShipperRequest()
403465

466+
immutableArgs := []string{"start_time", "end_time"}
467+
for _, v := range immutableArgs {
468+
if d.HasChange(v) {
469+
return fmt.Errorf("argument `%s` cannot be changed", v)
470+
}
471+
}
472+
404473
request.ShipperId = helper.String(d.Id())
405474

406475
if d.HasChange("bucket") {
@@ -422,13 +491,13 @@ func resourceTencentCloudClsCosShipperUpdate(d *schema.ResourceData, meta interf
422491
}
423492

424493
if d.HasChange("interval") {
425-
if v, ok := d.GetOk("interval"); ok {
494+
if v, ok := d.GetOkExists("interval"); ok {
426495
request.Interval = helper.IntUint64(v.(int))
427496
}
428497
}
429498

430499
if d.HasChange("max_size") {
431-
if v, ok := d.GetOk("max_size"); ok {
500+
if v, ok := d.GetOkExists("max_size"); ok {
432501
request.MaxSize = helper.IntUint64(v.(int))
433502
}
434503
}
@@ -524,6 +593,18 @@ func resourceTencentCloudClsCosShipperUpdate(d *schema.ResourceData, meta interf
524593
}
525594
}
526595

596+
if d.HasChange("filename_mode") {
597+
if v, ok := d.GetOkExists("filename_mode"); ok {
598+
request.FilenameMode = helper.IntUint64(v.(int))
599+
}
600+
}
601+
602+
if d.HasChange("storage_type") {
603+
if v, ok := d.GetOk("storage_type"); ok {
604+
request.StorageType = helper.String(v.(string))
605+
}
606+
}
607+
527608
err := resource.Retry(tccommon.WriteRetryTimeout, func() *resource.RetryError {
528609
result, e := meta.(tccommon.ProviderMeta).GetAPIV3Conn().UseClsClient().ModifyShipper(request)
529610
if e != nil {

tencentcloud/services/cls/resource_tc_cls_cos_shipper.md

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,45 @@ Provides a resource to create a cls cos shipper.
33
Example Usage
44

55
```hcl
6-
resource "tencentcloud_cls_cos_shipper" "shipper" {
7-
bucket = "preset-scf-bucket-1308919341"
6+
data "tencentcloud_user_info" "info" {}
7+
8+
locals {
9+
app_id = data.tencentcloud_user_info.info.app_id
10+
}
11+
12+
resource "tencentcloud_cos_bucket" "example" {
13+
bucket = "private-bucket-${local.app_id}"
14+
acl = "private"
15+
}
16+
17+
resource "tencentcloud_cls_logset" "example" {
18+
logset_name = "tf-example"
19+
tags = {
20+
createBy = "Terraform"
21+
}
22+
}
23+
24+
resource "tencentcloud_cls_topic" "example" {
25+
topic_name = "tf-example"
26+
logset_id = tencentcloud_cls_logset.example.id
27+
auto_split = false
28+
max_split_partitions = 20
29+
partition_count = 1
30+
period = 10
31+
storage_type = "hot"
32+
tags = {
33+
createBy = "Terraform"
34+
}
35+
}
36+
37+
resource "tencentcloud_cls_cos_shipper" "example" {
38+
bucket = tencentcloud_cos_bucket.example.id
39+
topic_id = tencentcloud_cls_topic.example.id
840
interval = 300
941
max_size = 200
1042
partition = "/%Y/%m/%d/%H/"
1143
prefix = "ap-guangzhou-fffsasad-1649734752"
1244
shipper_name = "ap-guangzhou-fffsasad-1649734752"
13-
topic_id = "4d07fba0-b93e-4e0b-9a7f-d58542560bbb"
1445
1546
compress {
1647
format = "lzop"
@@ -20,7 +51,7 @@ resource "tencentcloud_cls_cos_shipper" "shipper" {
2051
format = "json"
2152
2253
json {
23-
enable_tag = true
54+
enable_tag = true
2455
meta_fields = [
2556
"__FILENAME__",
2657
"__SOURCE__",
@@ -36,5 +67,5 @@ Import
3667
cls cos shipper can be imported using the id, e.g.
3768

3869
```
39-
$ terraform import tencentcloud_cls_cos_shipper.shipper 5d1b7b2a-c163-4c48-bb01-9ee00584d761
70+
$ terraform import tencentcloud_cls_cos_shipper.example 5d1b7b2a-c163-4c48-bb01-9ee00584d761
4071
```

website/docs/r/cls_cos_shipper.html.markdown

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,45 @@ Provides a resource to create a cls cos shipper.
1414
## Example Usage
1515

1616
```hcl
17-
resource "tencentcloud_cls_cos_shipper" "shipper" {
18-
bucket = "preset-scf-bucket-1308919341"
17+
data "tencentcloud_user_info" "info" {}
18+
19+
locals {
20+
app_id = data.tencentcloud_user_info.info.app_id
21+
}
22+
23+
resource "tencentcloud_cos_bucket" "example" {
24+
bucket = "private-bucket-${local.app_id}"
25+
acl = "private"
26+
}
27+
28+
resource "tencentcloud_cls_logset" "example" {
29+
logset_name = "tf-example"
30+
tags = {
31+
createBy = "Terraform"
32+
}
33+
}
34+
35+
resource "tencentcloud_cls_topic" "example" {
36+
topic_name = "tf-example"
37+
logset_id = tencentcloud_cls_logset.example.id
38+
auto_split = false
39+
max_split_partitions = 20
40+
partition_count = 1
41+
period = 10
42+
storage_type = "hot"
43+
tags = {
44+
createBy = "Terraform"
45+
}
46+
}
47+
48+
resource "tencentcloud_cls_cos_shipper" "example" {
49+
bucket = tencentcloud_cos_bucket.example.id
50+
topic_id = tencentcloud_cls_topic.example.id
1951
interval = 300
2052
max_size = 200
2153
partition = "/%Y/%m/%d/%H/"
2254
prefix = "ap-guangzhou-fffsasad-1649734752"
2355
shipper_name = "ap-guangzhou-fffsasad-1649734752"
24-
topic_id = "4d07fba0-b93e-4e0b-9a7f-d58542560bbb"
2556
2657
compress {
2758
format = "lzop"
@@ -52,10 +83,14 @@ The following arguments are supported:
5283
* `topic_id` - (Required, String) ID of the log topic to which the shipping rule to be created belongs.
5384
* `compress` - (Optional, List) Compression configuration of shipped log.
5485
* `content` - (Optional, List) Format configuration of shipped log content.
86+
* `end_time` - (Optional, Int) End time for data shipping, which cannot be set to a future time. If you do not specify this parameter, it indicates continuous data shipping.
87+
* `filename_mode` - (Optional, Int) Naming a shipping file. Valid values: 0 (by random number); 1 (by shipping time). Default value: 0.
5588
* `filter_rules` - (Optional, List) Filter rules for shipped logs. Only logs matching the rules can be shipped. All rules are in the AND relationship, and up to five rules can be added. If the array is empty, no filtering will be performed, and all logs will be shipped.
5689
* `interval` - (Optional, Int) Shipping time interval in seconds. Default value: 300. Value range: 300~900.
5790
* `max_size` - (Optional, Int) Maximum size of a file to be shipped, in MB. Default value: 256. Value range: 100~256.
5891
* `partition` - (Optional, String) Partition rule of shipped log, which can be represented in strftime time format.
92+
* `start_time` - (Optional, Int) Start time for data shipping, which cannot be earlier than the lifecycle start time of the log topic. If you do not specify this parameter, it will be set to the time when you create the data shipping task.
93+
* `storage_type` - (Optional, String) COS bucket storage type. support: STANDARD_IA, ARCHIVE, DEEP_ARCHIVE, STANDARD, MAZ_STANDARD, MAZ_STANDARD_IA, INTELLIGENT_TIERING.
5994

6095
The `compress` object supports the following:
6196

@@ -100,6 +135,6 @@ In addition to all arguments above, the following attributes are exported:
100135
cls cos shipper can be imported using the id, e.g.
101136

102137
```
103-
$ terraform import tencentcloud_cls_cos_shipper.shipper 5d1b7b2a-c163-4c48-bb01-9ee00584d761
138+
$ terraform import tencentcloud_cls_cos_shipper.example 5d1b7b2a-c163-4c48-bb01-9ee00584d761
104139
```
105140

0 commit comments

Comments
 (0)