@@ -15,10 +15,13 @@ package tencentcloud
1515import (
1616 "context"
1717 "log"
18+ "sync"
1819
1920 "github.com/hashicorp/terraform-plugin-sdk/helper/schema"
2021)
2122
23+ var clsActionMu = & sync.Mutex {}
24+
2225func resourceTencentCloudClbInstanceTopic () * schema.Resource {
2326 return & schema.Resource {
2427 Create : resourceTencentCloudClbInstanceTopicCreate ,
@@ -41,21 +44,76 @@ func resourceTencentCloudClbInstanceTopic() *schema.Resource {
4144 ValidateFunc : validateIntegerInRange (1 , 10 ),
4245 Description : "Topic partition count of CLB instance.(Default 1)." ,
4346 },
47+ "limit" : {
48+ Type : schema .TypeInt ,
49+ Optional : true ,
50+ Description : "Fetch topic info pagination limit." ,
51+ },
52+ "offset" : {
53+ Type : schema .TypeInt ,
54+ Optional : true ,
55+ Description : "Fetch topic info pagination offset." ,
56+ },
4457 },
4558 }
4659}
4760
4861func resourceTencentCloudClbInstanceTopicRead (d * schema.ResourceData , meta interface {}) error {
62+ clsActionMu .Lock ()
63+ defer clsActionMu .Unlock ()
64+ logId := getLogId (contextNil )
65+ ctx := context .WithValue (context .TODO (), logIdKey , logId )
66+ var topicName string
67+ if value , ok := d .GetOk ("topic_name" ); ok {
68+ topicName = value .(string )
69+ }
70+ clsService := ClsService {
71+ client : meta .(* TencentCloudClient ).apiV3Conn ,
72+ }
73+ res , ok := clsService .DescribeTopicsByTopicName (ctx , topicName )
74+ if ok != nil {
75+ return ok
76+ }
77+ _ = d .Set ("logset_id" , res .LogsetId )
78+ _ = d .Set ("topic_id" , res .TopicId )
79+ _ = d .Set ("topic_name" , res .TopicName )
80+ _ = d .Set ("partition_count" , res .PartitionCount )
81+ _ = d .Set ("index" , res .Index )
82+ _ = d .Set ("create_time" , res .CreateTime )
83+ _ = d .Set ("status" , res .Status )
84+ _ = d .Set ("tags" , res .Tags )
85+ _ = d .Set ("auto_split" , res .AutoSplit )
86+ _ = d .Set ("max_split_partitions" , res .MaxSplitPartitions )
87+ _ = d .Set ("storage_type" , res .StorageType )
88+ _ = d .Set ("period" , res .Period )
4989 return nil
90+
5091}
92+
5193func resourceTencentCloudClbInstanceTopicUpdate (d * schema.ResourceData , meta interface {}) error {
5294 return nil
5395}
96+
5497func resourceTencentCloudClbInstanceTopicDelete (d * schema.ResourceData , meta interface {}) error {
98+ clsActionMu .Lock ()
99+ defer clsActionMu .Unlock ()
100+ logId := getLogId (contextNil )
101+ ctx := context .WithValue (context .TODO (), logIdKey , logId )
102+ var topicName string
103+ if value , ok := d .GetOk ("topic_name" ); ok {
104+ topicName = value .(string )
105+ }
106+ clsService := ClsService {
107+ client : meta .(* TencentCloudClient ).apiV3Conn ,
108+ }
109+ _ , ok := clsService .DeleteTopicsByTopicName (ctx , topicName )
110+ if ok != nil {
111+ return ok
112+ }
55113 return nil
56114}
57- func resourceTencentCloudClbInstanceTopicCreate (d * schema.ResourceData , meta interface {}) error {
58115
116+ func resourceTencentCloudClbInstanceTopicCreate (d * schema.ResourceData , meta interface {}) error {
59117 logId := getLogId (contextNil )
60118 ctx := context .WithValue (context .TODO (), logIdKey , logId )
61119 params := make (map [string ]interface {})
@@ -68,10 +126,11 @@ func resourceTencentCloudClbInstanceTopicCreate(d *schema.ResourceData, meta int
68126 clbService := ClbService {
69127 client : meta .(* TencentCloudClient ).apiV3Conn ,
70128 }
71- err := clbService .CreateTopic (ctx , params )
129+ resp , err := clbService .CreateTopic (ctx , params )
130+ d .SetId (* resp .Response .TopicId )
72131 if err != nil {
73132 log .Printf ("[CRITAL]%s create CLB topic failed, reason:%+v" , logId , err )
74133 return err
75134 }
76- return nil
135+ return resourceTencentCloudClbInstanceTopicRead ( d , meta )
77136}
0 commit comments