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 diff --git a/tencentcloud/services/cls/resource_tc_cls_cos_shipper.go b/tencentcloud/services/cls/resource_tc_cls_cos_shipper.go index 0870a58f5e..d54eda97d4 100644 --- a/tencentcloud/services/cls/resource_tc_cls_cos_shipper.go +++ b/tencentcloud/services/cls/resource_tc_cls_cos_shipper.go @@ -171,6 +171,27 @@ 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, + 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": { + 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 +222,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 +313,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 +336,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, Response is nil.")) + } + response = result return nil }) @@ -309,6 +350,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 +438,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 +463,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 +491,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 +593,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/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 5d752445ef..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" @@ -52,10 +83,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: @@ -100,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 ```