From 07666d9667d78caf1b620148447a3e486d706bc1 Mon Sep 17 00:00:00 2001 From: SevenEarth <391613297@qq.com> Date: Fri, 21 Mar 2025 14:22:55 +0800 Subject: [PATCH 1/4] add --- .../cls/resource_tc_cls_cos_shipper.go | 88 ++++++++++++++++++- website/docs/r/cls_cos_shipper.html.markdown | 4 + 2 files changed, 88 insertions(+), 4 deletions(-) diff --git a/tencentcloud/services/cls/resource_tc_cls_cos_shipper.go b/tencentcloud/services/cls/resource_tc_cls_cos_shipper.go index 0870a58f5e..46bfe8a028 100644 --- a/tencentcloud/services/cls/resource_tc_cls_cos_shipper.go +++ b/tencentcloud/services/cls/resource_tc_cls_cos_shipper.go @@ -171,6 +171,26 @@ func ResourceTencentCloudClsCosShipper() *schema.Resource { }, }, }, + "filename_mode": { + Type: schema.TypeInt, + Optional: true, + Description: "Naming a shipping file. Valid values: 0 (by random number); 1 (by shipping time). Default value: 0.", + }, + "start_time": { + Type: schema.TypeInt, + Optional: true, + 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.", + }, + "end_time": { + Type: schema.TypeInt, + Optional: true, + 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.", + }, + "storage_type": { + Type: schema.TypeString, + Optional: true, + Description: "COS bucket storage type. support: STANDARD_IA, ARCHIVE, DEEP_ARCHIVE, STANDARD, MAZ_STANDARD, MAZ_STANDARD_IA, INTELLIGENT_TIERING.", + }, }, } } @@ -201,11 +221,11 @@ func resourceTencentCloudClsCosShipperCreate(d *schema.ResourceData, meta interf request.ShipperName = helper.String(v.(string)) } - if v, ok := d.GetOk("interval"); ok { + if v, ok := d.GetOkExists("interval"); ok { request.Interval = helper.IntUint64(v.(int)) } - if v, ok := d.GetOk("max_size"); ok { + if v, ok := d.GetOkExists("max_size"); ok { request.MaxSize = helper.IntUint64(v.(int)) } @@ -292,6 +312,21 @@ func resourceTencentCloudClsCosShipperCreate(d *schema.ResourceData, meta interf request.Content = contents[0] } + if v, ok := d.GetOkExists("filename_mode"); ok { + request.FilenameMode = helper.IntUint64(v.(int)) + } + + if v, ok := d.GetOkExists("start_time"); ok { + request.StartTime = helper.IntInt64(v.(int)) + } + if v, ok := d.GetOkExists("end_time"); ok { + request.EndTime = helper.IntInt64(v.(int)) + } + + if v, ok := d.GetOk("storage_type"); ok { + request.StorageType = helper.String(v.(string)) + } + err := resource.Retry(tccommon.WriteRetryTimeout, func() *resource.RetryError { result, e := meta.(tccommon.ProviderMeta).GetAPIV3Conn().UseClsClient().CreateShipper(request) if e != nil { @@ -300,6 +335,11 @@ func resourceTencentCloudClsCosShipperCreate(d *schema.ResourceData, meta interf log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", logId, request.GetAction(), request.ToJsonString(), result.ToJsonString()) } + + if result == nil || result.Response == nil { + return resource.NonRetryableError(fmt.Errorf("Create cls cos shipper failed, Reponse is nil.")) + } + response = result return nil }) @@ -309,6 +349,10 @@ func resourceTencentCloudClsCosShipperCreate(d *schema.ResourceData, meta interf return err } + if response.Response.ShipperId == nil { + return fmt.Errorf("ShipperId is nil.") + } + id := *response.Response.ShipperId d.SetId(id) return resourceTencentCloudClsCosShipperRead(d, meta) @@ -393,6 +437,23 @@ func resourceTencentCloudClsCosShipperRead(d *schema.ResourceData, meta interfac } _ = d.Set("content", []interface{}{content}) } + + if shipper.FilenameMode != nil { + _ = d.Set("filename_mode", shipper.FilenameMode) + } + + if shipper.StartTime != nil { + _ = d.Set("start_time", shipper.StartTime) + } + + if shipper.EndTime != nil { + _ = d.Set("end_time", shipper.EndTime) + } + + if shipper.StorageType != nil { + _ = d.Set("storage_type", shipper.StorageType) + } + return nil } @@ -401,6 +462,13 @@ func resourceTencentCloudClsCosShipperUpdate(d *schema.ResourceData, meta interf logId := tccommon.GetLogId(tccommon.ContextNil) request := cls.NewModifyShipperRequest() + immutableArgs := []string{"start_time", "end_time"} + for _, v := range immutableArgs { + if d.HasChange(v) { + return fmt.Errorf("argument `%s` cannot be changed", v) + } + } + request.ShipperId = helper.String(d.Id()) if d.HasChange("bucket") { @@ -422,13 +490,13 @@ func resourceTencentCloudClsCosShipperUpdate(d *schema.ResourceData, meta interf } if d.HasChange("interval") { - if v, ok := d.GetOk("interval"); ok { + if v, ok := d.GetOkExists("interval"); ok { request.Interval = helper.IntUint64(v.(int)) } } if d.HasChange("max_size") { - if v, ok := d.GetOk("max_size"); ok { + if v, ok := d.GetOkExists("max_size"); ok { request.MaxSize = helper.IntUint64(v.(int)) } } @@ -524,6 +592,18 @@ func resourceTencentCloudClsCosShipperUpdate(d *schema.ResourceData, meta interf } } + if d.HasChange("filename_mode") { + if v, ok := d.GetOkExists("filename_mode"); ok { + request.FilenameMode = helper.IntUint64(v.(int)) + } + } + + if d.HasChange("storage_type") { + if v, ok := d.GetOk("storage_type"); ok { + request.StorageType = helper.String(v.(string)) + } + } + err := resource.Retry(tccommon.WriteRetryTimeout, func() *resource.RetryError { result, e := meta.(tccommon.ProviderMeta).GetAPIV3Conn().UseClsClient().ModifyShipper(request) if e != nil { diff --git a/website/docs/r/cls_cos_shipper.html.markdown b/website/docs/r/cls_cos_shipper.html.markdown index 5d752445ef..bf89a63812 100644 --- a/website/docs/r/cls_cos_shipper.html.markdown +++ b/website/docs/r/cls_cos_shipper.html.markdown @@ -52,10 +52,14 @@ The following arguments are supported: * `topic_id` - (Required, String) ID of the log topic to which the shipping rule to be created belongs. * `compress` - (Optional, List) Compression configuration of shipped log. * `content` - (Optional, List) Format configuration of shipped log content. +* `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. +* `filename_mode` - (Optional, Int) Naming a shipping file. Valid values: 0 (by random number); 1 (by shipping time). Default value: 0. * `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. * `interval` - (Optional, Int) Shipping time interval in seconds. Default value: 300. Value range: 300~900. * `max_size` - (Optional, Int) Maximum size of a file to be shipped, in MB. Default value: 256. Value range: 100~256. * `partition` - (Optional, String) Partition rule of shipped log, which can be represented in strftime time format. +* `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. +* `storage_type` - (Optional, String) COS bucket storage type. support: STANDARD_IA, ARCHIVE, DEEP_ARCHIVE, STANDARD, MAZ_STANDARD, MAZ_STANDARD_IA, INTELLIGENT_TIERING. The `compress` object supports the following: From d7df13c3aa1becf66e33ec9df5bfddea0a60649d Mon Sep 17 00:00:00 2001 From: SevenEarth <391613297@qq.com> Date: Fri, 21 Mar 2025 14:24:54 +0800 Subject: [PATCH 2/4] add --- .changelog/3231.txt | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .changelog/3231.txt diff --git a/.changelog/3231.txt b/.changelog/3231.txt new file mode 100644 index 0000000000..f3ddba43f8 --- /dev/null +++ b/.changelog/3231.txt @@ -0,0 +1,3 @@ +```release-note:enhancement +resource/tencentcloud_cls_cos_shipper: support new params +``` \ No newline at end of file From fcea3c00febefd6d02c1452811c6fa998afdaebe Mon Sep 17 00:00:00 2001 From: SevenEarth <391613297@qq.com> Date: Fri, 21 Mar 2025 14:34:10 +0800 Subject: [PATCH 3/4] add --- .../cls/resource_tc_cls_cos_shipper.go | 1 + .../cls/resource_tc_cls_cos_shipper.md | 41 ++++++++++++++++--- website/docs/r/cls_cos_shipper.html.markdown | 39 ++++++++++++++++-- 3 files changed, 72 insertions(+), 9 deletions(-) diff --git a/tencentcloud/services/cls/resource_tc_cls_cos_shipper.go b/tencentcloud/services/cls/resource_tc_cls_cos_shipper.go index 46bfe8a028..c34c7fd29f 100644 --- a/tencentcloud/services/cls/resource_tc_cls_cos_shipper.go +++ b/tencentcloud/services/cls/resource_tc_cls_cos_shipper.go @@ -179,6 +179,7 @@ func ResourceTencentCloudClsCosShipper() *schema.Resource { "start_time": { Type: schema.TypeInt, Optional: true, + Computed: true, 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.", }, "end_time": { diff --git a/tencentcloud/services/cls/resource_tc_cls_cos_shipper.md b/tencentcloud/services/cls/resource_tc_cls_cos_shipper.md index 7ba288b95b..3bf790133e 100644 --- a/tencentcloud/services/cls/resource_tc_cls_cos_shipper.md +++ b/tencentcloud/services/cls/resource_tc_cls_cos_shipper.md @@ -3,14 +3,45 @@ Provides a resource to create a cls cos shipper. Example Usage ```hcl -resource "tencentcloud_cls_cos_shipper" "shipper" { - bucket = "preset-scf-bucket-1308919341" +data "tencentcloud_user_info" "info" {} + +locals { + app_id = data.tencentcloud_user_info.info.app_id +} + +resource "tencentcloud_cos_bucket" "example" { + bucket = "private-bucket-${local.app_id}" + acl = "private" +} + +resource "tencentcloud_cls_logset" "example" { + logset_name = "tf-example" + tags = { + createBy = "Terraform" + } +} + +resource "tencentcloud_cls_topic" "example" { + topic_name = "tf-example" + logset_id = tencentcloud_cls_logset.example.id + auto_split = false + max_split_partitions = 20 + partition_count = 1 + period = 10 + storage_type = "hot" + tags = { + createBy = "Terraform" + } +} + +resource "tencentcloud_cls_cos_shipper" "example" { + bucket = tencentcloud_cos_bucket.example.id + topic_id = tencentcloud_cls_topic.example.id interval = 300 max_size = 200 partition = "/%Y/%m/%d/%H/" prefix = "ap-guangzhou-fffsasad-1649734752" shipper_name = "ap-guangzhou-fffsasad-1649734752" - topic_id = "4d07fba0-b93e-4e0b-9a7f-d58542560bbb" compress { format = "lzop" @@ -20,7 +51,7 @@ resource "tencentcloud_cls_cos_shipper" "shipper" { format = "json" json { - enable_tag = true + enable_tag = true meta_fields = [ "__FILENAME__", "__SOURCE__", @@ -36,5 +67,5 @@ Import cls cos shipper can be imported using the id, e.g. ``` -$ terraform import tencentcloud_cls_cos_shipper.shipper 5d1b7b2a-c163-4c48-bb01-9ee00584d761 +$ terraform import tencentcloud_cls_cos_shipper.example 5d1b7b2a-c163-4c48-bb01-9ee00584d761 ``` \ No newline at end of file diff --git a/website/docs/r/cls_cos_shipper.html.markdown b/website/docs/r/cls_cos_shipper.html.markdown index bf89a63812..e28c5b3b1a 100644 --- a/website/docs/r/cls_cos_shipper.html.markdown +++ b/website/docs/r/cls_cos_shipper.html.markdown @@ -14,14 +14,45 @@ Provides a resource to create a cls cos shipper. ## Example Usage ```hcl -resource "tencentcloud_cls_cos_shipper" "shipper" { - bucket = "preset-scf-bucket-1308919341" +data "tencentcloud_user_info" "info" {} + +locals { + app_id = data.tencentcloud_user_info.info.app_id +} + +resource "tencentcloud_cos_bucket" "example" { + bucket = "private-bucket-${local.app_id}" + acl = "private" +} + +resource "tencentcloud_cls_logset" "example" { + logset_name = "tf-example" + tags = { + createBy = "Terraform" + } +} + +resource "tencentcloud_cls_topic" "example" { + topic_name = "tf-example" + logset_id = tencentcloud_cls_logset.example.id + auto_split = false + max_split_partitions = 20 + partition_count = 1 + period = 10 + storage_type = "hot" + tags = { + createBy = "Terraform" + } +} + +resource "tencentcloud_cls_cos_shipper" "example" { + bucket = tencentcloud_cos_bucket.example.id + topic_id = tencentcloud_cls_topic.example.id interval = 300 max_size = 200 partition = "/%Y/%m/%d/%H/" prefix = "ap-guangzhou-fffsasad-1649734752" shipper_name = "ap-guangzhou-fffsasad-1649734752" - topic_id = "4d07fba0-b93e-4e0b-9a7f-d58542560bbb" compress { format = "lzop" @@ -104,6 +135,6 @@ In addition to all arguments above, the following attributes are exported: cls cos shipper can be imported using the id, e.g. ``` -$ terraform import tencentcloud_cls_cos_shipper.shipper 5d1b7b2a-c163-4c48-bb01-9ee00584d761 +$ terraform import tencentcloud_cls_cos_shipper.example 5d1b7b2a-c163-4c48-bb01-9ee00584d761 ``` From 9a1a4d9f9a037c7eb1cb06d13aa42aa95e844c88 Mon Sep 17 00:00:00 2001 From: SevenEarth <45937856+SevenEarth@users.noreply.github.com> Date: Fri, 21 Mar 2025 16:25:33 +0800 Subject: [PATCH 4/4] Update resource_tc_cls_cos_shipper.go --- tencentcloud/services/cls/resource_tc_cls_cos_shipper.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tencentcloud/services/cls/resource_tc_cls_cos_shipper.go b/tencentcloud/services/cls/resource_tc_cls_cos_shipper.go index c34c7fd29f..d54eda97d4 100644 --- a/tencentcloud/services/cls/resource_tc_cls_cos_shipper.go +++ b/tencentcloud/services/cls/resource_tc_cls_cos_shipper.go @@ -338,7 +338,7 @@ func resourceTencentCloudClsCosShipperCreate(d *schema.ResourceData, meta interf } if result == nil || result.Response == nil { - return resource.NonRetryableError(fmt.Errorf("Create cls cos shipper failed, Reponse is nil.")) + return resource.NonRetryableError(fmt.Errorf("Create cls cos shipper failed, Response is nil.")) } response = result