@@ -63,24 +63,34 @@ func ResourceTencentCloudClsTopic() *schema.Resource {
6363 Optional : true ,
6464 Computed : true ,
6565 Description : "Log topic storage class. Valid values: hot: real-time storage; cold: offline storage. Default value: hot. If cold is passed in, " +
66- "please contact the customer service to add the log topic to the allowlist first.. " ,
66+ "please contact the customer service to add the log topic to the allowlist first." ,
6767 },
6868 "period" : {
6969 Type : schema .TypeInt ,
7070 Optional : true ,
7171 Computed : true ,
7272 Description : "Lifecycle in days. Value range: 1~366. Default value: 30." ,
7373 },
74+ "hot_period" : {
75+ Type : schema .TypeInt ,
76+ Optional : true ,
77+ Computed : true ,
78+ 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." ,
79+ },
80+ "describes" : {
81+ Type : schema .TypeString ,
82+ Optional : true ,
83+ Description : "Log Topic Description." ,
84+ },
7485 },
7586 }
7687}
7788
7889func resourceTencentCloudClsTopicCreate (d * schema.ResourceData , meta interface {}) error {
7990 defer tccommon .LogElapsed ("resource.tencentcloud_cls_topic.create" )()
8091
81- logId := tccommon .GetLogId (tccommon .ContextNil )
82-
8392 var (
93+ logId = tccommon .GetLogId (tccommon .ContextNil )
8494 request = cls .NewCreateTopicRequest ()
8595 response * cls.CreateTopicResponse
8696 )
@@ -93,7 +103,7 @@ func resourceTencentCloudClsTopicCreate(d *schema.ResourceData, meta interface{}
93103 request .TopicName = helper .String (v .(string ))
94104 }
95105
96- if v , ok := d .GetOk ("partition_count" ); ok {
106+ if v , ok := d .GetOkExists ("partition_count" ); ok {
97107 request .PartitionCount = helper .IntInt64 (v .(int ))
98108 }
99109
@@ -112,18 +122,28 @@ func resourceTencentCloudClsTopicCreate(d *schema.ResourceData, meta interface{}
112122 request .AutoSplit = helper .Bool (v .(bool ))
113123 }
114124
115- if v , ok := d .GetOk ("max_split_partitions" ); ok {
125+ if v , ok := d .GetOkExists ("max_split_partitions" ); ok {
116126 request .MaxSplitPartitions = helper .IntInt64 (v .(int ))
117127 }
118128
119129 if v , ok := d .GetOk ("storage_type" ); ok {
120130 request .StorageType = helper .String (v .(string ))
121131 }
122132
123- if v , ok := d .GetOk ("period" ); ok {
133+ if v , ok := d .GetOkExists ("period" ); ok {
124134 request .Period = helper .IntInt64 (v .(int ))
125135 }
126136
137+ if v , ok := d .GetOkExists ("hot_period" ); ok {
138+ request .HotPeriod = helper .IntUint64 (v .(int ))
139+ }
140+
141+ if v , ok := d .GetOk ("describes" ); ok {
142+ request .Describes = helper .String (v .(string ))
143+ } else {
144+ request .Describes = helper .String ("" )
145+ }
146+
127147 err := resource .Retry (tccommon .WriteRetryTimeout , func () * resource.RetryError {
128148 result , e := meta .(tccommon.ProviderMeta ).GetAPIV3Conn ().UseClsClient ().CreateTopic (request )
129149 if e != nil {
@@ -132,6 +152,12 @@ func resourceTencentCloudClsTopicCreate(d *schema.ResourceData, meta interface{}
132152 log .Printf ("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n " ,
133153 logId , request .GetAction (), request .ToJsonString (), result .ToJsonString ())
134154 }
155+
156+ if result == nil {
157+ e = fmt .Errorf ("create cls topic failed" )
158+ return resource .NonRetryableError (e )
159+ }
160+
135161 response = result
136162 return nil
137163 })
@@ -150,14 +176,14 @@ func resourceTencentCloudClsTopicRead(d *schema.ResourceData, meta interface{})
150176 defer tccommon .LogElapsed ("resource.tencentcloud_cls_topic.read" )()
151177 defer tccommon .InconsistentCheck (d , meta )()
152178
153- logId := tccommon .GetLogId (tccommon .ContextNil )
154- ctx := context .WithValue (context .TODO (), tccommon .LogIdKey , logId )
155- service := ClsService {client : meta .(tccommon.ProviderMeta ).GetAPIV3Conn ()}
156-
157- id := d .Id ()
179+ var (
180+ logId = tccommon .GetLogId (tccommon .ContextNil )
181+ ctx = context .WithValue (context .TODO (), tccommon .LogIdKey , logId )
182+ service = ClsService {client : meta .(tccommon.ProviderMeta ).GetAPIV3Conn ()}
183+ id = d .Id ()
184+ )
158185
159186 topic , err := service .DescribeClsTopicById (ctx , id )
160-
161187 if err != nil {
162188 return err
163189 }
@@ -175,36 +201,42 @@ func resourceTencentCloudClsTopicRead(d *schema.ResourceData, meta interface{})
175201 for _ , tag := range topic .Tags {
176202 tags [* tag .Key ] = * tag .Value
177203 }
204+
178205 _ = d .Set ("tags" , tags )
179206 _ = d .Set ("auto_split" , topic .AutoSplit )
180207 _ = d .Set ("max_split_partitions" , topic .MaxSplitPartitions )
181208 _ = d .Set ("storage_type" , topic .StorageType )
182209 _ = d .Set ("period" , topic .Period )
210+ _ = d .Set ("hot_period" , topic .HotPeriod )
211+ _ = d .Set ("describes" , topic .Describes )
183212
184213 return nil
185214}
186215
187216func resourceTencentCloudClsTopicUpdate (d * schema.ResourceData , meta interface {}) error {
188217 defer tccommon .LogElapsed ("resource.tencentcloud_cls_topic.update" )()
189- logId := tccommon .GetLogId (tccommon .ContextNil )
190- request := cls .NewModifyTopicRequest ()
191218
192- request .TopicId = helper .String (d .Id ())
219+ var (
220+ logId = tccommon .GetLogId (tccommon .ContextNil )
221+ request = cls .NewModifyTopicRequest ()
222+ id = d .Id ()
223+ )
224+
225+ immutableArgs := []string {"partition_count" , "storage_type" }
193226
194- if d .HasChange ("partition_count" ) {
195- return fmt .Errorf ("`partition_count` do not support change now." )
227+ for _ , v := range immutableArgs {
228+ if d .HasChange (v ) {
229+ return fmt .Errorf ("argument `%s` cannot be changed" , v )
230+ }
196231 }
197232
198- if d .HasChange ("storage_type" ) {
199- return fmt .Errorf ("`storage_type` do not support change now." )
200- }
233+ request .TopicId = helper .String (id )
201234
202235 if d .HasChange ("topic_name" ) {
203236 request .TopicName = helper .String (d .Get ("topic_name" ).(string ))
204237 }
205238
206239 if d .HasChange ("tags" ) {
207-
208240 tags := d .Get ("tags" ).(map [string ]interface {})
209241 request .Tags = make ([]* cls.Tag , 0 , len (tags ))
210242 for k , v := range tags {
@@ -229,6 +261,14 @@ func resourceTencentCloudClsTopicUpdate(d *schema.ResourceData, meta interface{}
229261 request .Period = helper .IntInt64 (d .Get ("period" ).(int ))
230262 }
231263
264+ if d .HasChange ("hot_period" ) {
265+ request .HotPeriod = helper .IntUint64 (d .Get ("hot_period" ).(int ))
266+ }
267+
268+ if d .HasChange ("describes" ) {
269+ request .Describes = helper .String (d .Get ("describes" ).(string ))
270+ }
271+
232272 err := resource .Retry (tccommon .WriteRetryTimeout , func () * resource.RetryError {
233273 result , e := meta .(tccommon.ProviderMeta ).GetAPIV3Conn ().UseClsClient ().ModifyTopic (request )
234274 if e != nil {
@@ -237,6 +277,7 @@ func resourceTencentCloudClsTopicUpdate(d *schema.ResourceData, meta interface{}
237277 log .Printf ("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n " ,
238278 logId , request .GetAction (), request .ToJsonString (), result .ToJsonString ())
239279 }
280+
240281 return nil
241282 })
242283
@@ -250,10 +291,12 @@ func resourceTencentCloudClsTopicUpdate(d *schema.ResourceData, meta interface{}
250291func resourceTencentCloudClsTopicDelete (d * schema.ResourceData , meta interface {}) error {
251292 defer tccommon .LogElapsed ("resource.tencentcloud_cls_topic.delete" )()
252293
253- logId := tccommon .GetLogId (tccommon .ContextNil )
254- ctx := context .WithValue (context .TODO (), tccommon .LogIdKey , logId )
255- service := ClsService {client : meta .(tccommon.ProviderMeta ).GetAPIV3Conn ()}
256- id := d .Id ()
294+ var (
295+ logId = tccommon .GetLogId (tccommon .ContextNil )
296+ ctx = context .WithValue (context .TODO (), tccommon .LogIdKey , logId )
297+ service = ClsService {client : meta .(tccommon.ProviderMeta ).GetAPIV3Conn ()}
298+ id = d .Id ()
299+ )
257300
258301 if err := service .DeleteClsTopic (ctx , id ); err != nil {
259302 return err
0 commit comments