Skip to content

fix(cls): [122484242] tencentcloud_cls_cos_shipper support new params #3231

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 21, 2025
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/3231.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
resource/tencentcloud_cls_cos_shipper: support new params
```
89 changes: 85 additions & 4 deletions tencentcloud/services/cls/resource_tc_cls_cos_shipper.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,27 @@
},
},
},
"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.",
},
},
}
}
Expand Down Expand Up @@ -201,11 +222,11 @@
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))
}

Expand Down Expand Up @@ -292,6 +313,21 @@
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 {
Expand All @@ -300,6 +336,11 @@
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."))

Check failure on line 341 in tencentcloud/services/cls/resource_tc_cls_cos_shipper.go

View workflow job for this annotation

GitHub Actions / golangci-lint

`Reponse` is a misspelling of `Response` (misspell)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

拼写有问题

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

}

response = result
return nil
})
Expand All @@ -309,6 +350,10 @@
return err
}

if response.Response.ShipperId == nil {
return fmt.Errorf("ShipperId is nil.")
}

id := *response.Response.ShipperId
d.SetId(id)
return resourceTencentCloudClsCosShipperRead(d, meta)
Expand Down Expand Up @@ -393,6 +438,23 @@
}
_ = 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
}

Expand All @@ -401,6 +463,13 @@
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") {
Expand All @@ -422,13 +491,13 @@
}

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))
}
}
Expand Down Expand Up @@ -524,6 +593,18 @@
}
}

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 {
Expand Down
41 changes: 36 additions & 5 deletions tencentcloud/services/cls/resource_tc_cls_cos_shipper.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -20,7 +51,7 @@ resource "tencentcloud_cls_cos_shipper" "shipper" {
format = "json"

json {
enable_tag = true
enable_tag = true
meta_fields = [
"__FILENAME__",
"__SOURCE__",
Expand All @@ -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
```
43 changes: 39 additions & 4 deletions website/docs/r/cls_cos_shipper.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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:

Expand Down Expand Up @@ -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
```

Loading