Skip to content

fix(cls): [116280037]support hot_period, describes params #2545

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 1, 2024
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/2545.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
resource/tencentcloud_cls_topic: support hot_period, describes params
```
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ require (
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/ckafka v1.0.748
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/clb v1.0.860
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cloudaudit v1.0.544
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cls v1.0.711
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.860
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cls v1.0.865
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.865
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm v1.0.624
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cwp v1.0.762
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cynosdb v1.0.692
Expand Down Expand Up @@ -82,7 +82,7 @@ require (
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/ssl v1.0.822
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/ssm v1.0.691
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/sts v1.0.524
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tag v1.0.677
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tag v1.0.865
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tat v1.0.634
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tcaplusdb v1.0.199
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tcm v1.0.547
Expand Down
6 changes: 6 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -874,6 +874,8 @@ github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cloudaudit v1.0.544 h1:
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cloudaudit v1.0.544/go.mod h1:c37rIdL3LrJXYwrfp9c8L4MabTqKIZUe1xvnWhN75oc=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cls v1.0.711 h1:v6ffPkv3kmT6bC0d3JLVVJsh61zdvaLJZ5RHwmKNBHk=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cls v1.0.711/go.mod h1:oArXkl0Gm9hpK+mfoIjSGEuG8FLkcOAEeB0LfyIQq/Y=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cls v1.0.865 h1:ZdUE7EeBF4NlkB/WtllEQJTmrC9AJK67C+csBzmlHYk=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cls v1.0.865/go.mod h1:SKeQkoAkTqqqCLjNtzCagsCiaCVwvcHdjkH6S0RJluo=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.414/go.mod h1:7sCQWVkxcsR38nffDW057DRGk8mUjK1Ing/EFOK8s8Y=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.486/go.mod h1:7sCQWVkxcsR38nffDW057DRGk8mUjK1Ing/EFOK8s8Y=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.524/go.mod h1:7sCQWVkxcsR38nffDW057DRGk8mUjK1Ing/EFOK8s8Y=
Expand Down Expand Up @@ -965,6 +967,8 @@ github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.859 h1:XXpy
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.859/go.mod h1:r5r4xbfxSaeR04b166HGsBa/R4U3SueirEUpXGuw+Q0=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.860 h1:d5/YwGX6b5YgFU/0thsbs5aBp4aJJXBi7JyU1JHAaw0=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.860/go.mod h1:r5r4xbfxSaeR04b166HGsBa/R4U3SueirEUpXGuw+Q0=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.865 h1:LcUqBlKC4j15LhT303yQDX/XxyHG4haEQqbHgZZA4SY=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.865/go.mod h1:r5r4xbfxSaeR04b166HGsBa/R4U3SueirEUpXGuw+Q0=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm v1.0.624 h1:nEZqsoqt1pEoaP9JjkHQy3/H00suCfzlHW1qOm2nYD8=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm v1.0.624/go.mod h1:+TXSVyeKwt1IhZRqKPbTREteBcP+K07Q846/ilNzLWA=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cwp v1.0.762 h1:2egy69SP/wPsmnfozcQVZ6tUY6F6N/TpEe/7xtXrc/8=
Expand Down Expand Up @@ -1051,6 +1055,8 @@ github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/sts v1.0.524 h1:Hda8mBE
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/sts v1.0.524/go.mod h1:DkzQ5MJmuv5iHgQotrsSzfvP4D1zwiWLRR4gqLK/i/w=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tag v1.0.677 h1:dQDIafZauF/YoQQaY8qk5YCIBFZmLPb1kUgCc+WK7wo=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tag v1.0.677/go.mod h1:IAEAhNq0rp2Wyrjvti/MQeDPuPQ5ohriltA9ZSDxeMM=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tag v1.0.865 h1:ciRqMS/za/SA4V089eMdp4LeWlY+GRcfSh+6danS+2Q=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tag v1.0.865/go.mod h1:w1XYi8mvbVbFulWAvWFGmFiYIVASBBmyBis70tK4wIU=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tat v1.0.634 h1:GJDzXxKloZeM8fN+qlIspPnZbUw1lOZGe7jGqfFbQMM=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tat v1.0.634/go.mod h1:yX1elLeYvjmtPvgBVCOyYxyy1u2XEKfXaEiZXIWRCKw=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tcaplusdb v1.0.199 h1:i17zUWDw6iN7EMkQMGDXIXpur73vwUvbZrX4M5S0xhQ=
Expand Down
93 changes: 68 additions & 25 deletions tencentcloud/services/cls/resource_tc_cls_topic.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,24 +63,34 @@ func ResourceTencentCloudClsTopic() *schema.Resource {
Optional: true,
Computed: true,
Description: "Log topic storage class. Valid values: hot: real-time storage; cold: offline storage. Default value: hot. If cold is passed in, " +
"please contact the customer service to add the log topic to the allowlist first..",
"please contact the customer service to add the log topic to the allowlist first.",
},
"period": {
Type: schema.TypeInt,
Optional: true,
Computed: true,
Description: "Lifecycle in days. Value range: 1~366. Default value: 30.",
},
"hot_period": {
Copy link
Collaborator

Choose a reason for hiding this comment

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

这里为啥要加 Computed 属性呢

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

因为这个参数不设置产品会返回0,不加computed会出现changed

Type: schema.TypeInt,
Optional: true,
Computed: true,
Description: "0: Turn off log sinking. Non 0: The number of days of standard storage after enabling log settling. HotPeriod needs to be greater than or equal to 7 and less than Period. Only effective when StorageType is hot.",
},
"describes": {
Type: schema.TypeString,
Optional: true,
Description: "Log Topic Description.",
},
},
}
}

func resourceTencentCloudClsTopicCreate(d *schema.ResourceData, meta interface{}) error {
defer tccommon.LogElapsed("resource.tencentcloud_cls_topic.create")()

logId := tccommon.GetLogId(tccommon.ContextNil)

var (
logId = tccommon.GetLogId(tccommon.ContextNil)
request = cls.NewCreateTopicRequest()
response *cls.CreateTopicResponse
)
Expand All @@ -93,7 +103,7 @@ func resourceTencentCloudClsTopicCreate(d *schema.ResourceData, meta interface{}
request.TopicName = helper.String(v.(string))
}

if v, ok := d.GetOk("partition_count"); ok {
if v, ok := d.GetOkExists("partition_count"); ok {
request.PartitionCount = helper.IntInt64(v.(int))
}

Expand All @@ -112,18 +122,28 @@ func resourceTencentCloudClsTopicCreate(d *schema.ResourceData, meta interface{}
request.AutoSplit = helper.Bool(v.(bool))
}

if v, ok := d.GetOk("max_split_partitions"); ok {
if v, ok := d.GetOkExists("max_split_partitions"); ok {
request.MaxSplitPartitions = helper.IntInt64(v.(int))
}

if v, ok := d.GetOk("storage_type"); ok {
request.StorageType = helper.String(v.(string))
}

if v, ok := d.GetOk("period"); ok {
if v, ok := d.GetOkExists("period"); ok {
request.Period = helper.IntInt64(v.(int))
}

if v, ok := d.GetOkExists("hot_period"); ok {
request.HotPeriod = helper.IntUint64(v.(int))
}

if v, ok := d.GetOk("describes"); ok {
request.Describes = helper.String(v.(string))
} else {
request.Describes = helper.String("")
}

err := resource.Retry(tccommon.WriteRetryTimeout, func() *resource.RetryError {
result, e := meta.(tccommon.ProviderMeta).GetAPIV3Conn().UseClsClient().CreateTopic(request)
if e != nil {
Expand All @@ -132,6 +152,12 @@ func resourceTencentCloudClsTopicCreate(d *schema.ResourceData, meta interface{}
log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n",
logId, request.GetAction(), request.ToJsonString(), result.ToJsonString())
}

if result == nil {
e = fmt.Errorf("create cls topic failed")
return resource.NonRetryableError(e)
}

response = result
return nil
})
Expand All @@ -150,14 +176,14 @@ func resourceTencentCloudClsTopicRead(d *schema.ResourceData, meta interface{})
defer tccommon.LogElapsed("resource.tencentcloud_cls_topic.read")()
defer tccommon.InconsistentCheck(d, meta)()

logId := tccommon.GetLogId(tccommon.ContextNil)
ctx := context.WithValue(context.TODO(), tccommon.LogIdKey, logId)
service := ClsService{client: meta.(tccommon.ProviderMeta).GetAPIV3Conn()}

id := d.Id()
var (
logId = tccommon.GetLogId(tccommon.ContextNil)
ctx = context.WithValue(context.TODO(), tccommon.LogIdKey, logId)
service = ClsService{client: meta.(tccommon.ProviderMeta).GetAPIV3Conn()}
id = d.Id()
)

topic, err := service.DescribeClsTopicById(ctx, id)

if err != nil {
return err
}
Expand All @@ -175,36 +201,42 @@ func resourceTencentCloudClsTopicRead(d *schema.ResourceData, meta interface{})
for _, tag := range topic.Tags {
tags[*tag.Key] = *tag.Value
}

_ = d.Set("tags", tags)
_ = d.Set("auto_split", topic.AutoSplit)
_ = d.Set("max_split_partitions", topic.MaxSplitPartitions)
_ = d.Set("storage_type", topic.StorageType)
_ = d.Set("period", topic.Period)
_ = d.Set("hot_period", topic.HotPeriod)
_ = d.Set("describes", topic.Describes)

return nil
}

func resourceTencentCloudClsTopicUpdate(d *schema.ResourceData, meta interface{}) error {
defer tccommon.LogElapsed("resource.tencentcloud_cls_topic.update")()
logId := tccommon.GetLogId(tccommon.ContextNil)
request := cls.NewModifyTopicRequest()

request.TopicId = helper.String(d.Id())
var (
logId = tccommon.GetLogId(tccommon.ContextNil)
request = cls.NewModifyTopicRequest()
id = d.Id()
)

immutableArgs := []string{"partition_count", "storage_type"}

if d.HasChange("partition_count") {
return fmt.Errorf("`partition_count` do not support change now.")
for _, v := range immutableArgs {
if d.HasChange(v) {
return fmt.Errorf("argument `%s` cannot be changed", v)
}
}

if d.HasChange("storage_type") {
return fmt.Errorf("`storage_type` do not support change now.")
}
request.TopicId = helper.String(id)

if d.HasChange("topic_name") {
request.TopicName = helper.String(d.Get("topic_name").(string))
}

if d.HasChange("tags") {

tags := d.Get("tags").(map[string]interface{})
request.Tags = make([]*cls.Tag, 0, len(tags))
for k, v := range tags {
Expand All @@ -229,6 +261,14 @@ func resourceTencentCloudClsTopicUpdate(d *schema.ResourceData, meta interface{}
request.Period = helper.IntInt64(d.Get("period").(int))
}

if d.HasChange("hot_period") {
request.HotPeriod = helper.IntUint64(d.Get("hot_period").(int))
}

if d.HasChange("describes") {
request.Describes = helper.String(d.Get("describes").(string))
}

err := resource.Retry(tccommon.WriteRetryTimeout, func() *resource.RetryError {
result, e := meta.(tccommon.ProviderMeta).GetAPIV3Conn().UseClsClient().ModifyTopic(request)
if e != nil {
Expand All @@ -237,6 +277,7 @@ func resourceTencentCloudClsTopicUpdate(d *schema.ResourceData, meta interface{}
log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n",
logId, request.GetAction(), request.ToJsonString(), result.ToJsonString())
}

return nil
})

Expand All @@ -250,10 +291,12 @@ func resourceTencentCloudClsTopicUpdate(d *schema.ResourceData, meta interface{}
func resourceTencentCloudClsTopicDelete(d *schema.ResourceData, meta interface{}) error {
defer tccommon.LogElapsed("resource.tencentcloud_cls_topic.delete")()

logId := tccommon.GetLogId(tccommon.ContextNil)
ctx := context.WithValue(context.TODO(), tccommon.LogIdKey, logId)
service := ClsService{client: meta.(tccommon.ProviderMeta).GetAPIV3Conn()}
id := d.Id()
var (
logId = tccommon.GetLogId(tccommon.ContextNil)
ctx = context.WithValue(context.TODO(), tccommon.LogIdKey, logId)
service = ClsService{client: meta.(tccommon.ProviderMeta).GetAPIV3Conn()}
id = d.Id()
)

if err := service.DeleteClsTopic(ctx, id); err != nil {
return err
Expand Down
19 changes: 14 additions & 5 deletions tencentcloud/services/cls/resource_tc_cls_topic.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,23 @@ Provides a resource to create a cls topic.
Example Usage

```hcl
resource "tencentcloud_cls_topic" "topic" {
topic_name = "topic"
logset_id = "5cd3a17e-fb0b-418c-afd7-77b365397426"
resource "tencentcloud_cls_logset" "example" {
logset_name = "tf_example"
tags = {
"demo" = "test"
}
}

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
period = 30
storage_type = "hot"
describes = "Test Demo."
hot_period = 10
tags = {
"test" = "test",
}
Expand All @@ -22,5 +31,5 @@ Import
cls topic can be imported using the id, e.g.

```
$ terraform import tencentcloud_cls_topic.topic 2f5764c1-c833-44c5-84c7-950979b2a278
$ terraform import tencentcloud_cls_topic.example 2f5764c1-c833-44c5-84c7-950979b2a278
```
22 changes: 12 additions & 10 deletions tencentcloud/services/cls/resource_tc_cls_topic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func TestAccTencentCloudClsTopic_basic(t *testing.T) {
Config: testAccClsTopic,
Check: resource.ComposeTestCheckFunc(
testAccCheckClsTopicExists("tencentcloud_cls_topic.topic"),
resource.TestCheckResourceAttr("tencentcloud_cls_topic.topic", "topic_name", "tf-topic-test"),
resource.TestCheckResourceAttr("tencentcloud_cls_topic.topic", "topic_name", "tf_example"),
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.

没有覆盖修改 这里我更新下

),
},
{
Expand Down Expand Up @@ -129,23 +129,25 @@ func testAccCheckClsTopicExists(n string) resource.TestCheckFunc {
}

const testAccClsTopic = `
resource "tencentcloud_cls_logset" "logset" {
logset_name = "tf-topic-test"
resource "tencentcloud_cls_logset" "example" {
logset_name = "tf_example"
tags = {
"test" = "test"
"demo" = "test"
}
}

resource "tencentcloud_cls_topic" "topic" {
auto_split = true
logset_id = tencentcloud_cls_logset.logset.id
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
period = 30
storage_type = "hot"
describes = "Test Demo."
hot_period = 10
tags = {
"test" = "test"
"test" = "test",
}
topic_name = "tf-topic-test"
}
`
Loading