@@ -63,24 +63,34 @@ func ResourceTencentCloudClsTopic() *schema.Resource {
63
63
Optional : true ,
64
64
Computed : true ,
65
65
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." ,
67
67
},
68
68
"period" : {
69
69
Type : schema .TypeInt ,
70
70
Optional : true ,
71
71
Computed : true ,
72
72
Description : "Lifecycle in days. Value range: 1~366. Default value: 30." ,
73
73
},
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
+ },
74
85
},
75
86
}
76
87
}
77
88
78
89
func resourceTencentCloudClsTopicCreate (d * schema.ResourceData , meta interface {}) error {
79
90
defer tccommon .LogElapsed ("resource.tencentcloud_cls_topic.create" )()
80
91
81
- logId := tccommon .GetLogId (tccommon .ContextNil )
82
-
83
92
var (
93
+ logId = tccommon .GetLogId (tccommon .ContextNil )
84
94
request = cls .NewCreateTopicRequest ()
85
95
response * cls.CreateTopicResponse
86
96
)
@@ -93,7 +103,7 @@ func resourceTencentCloudClsTopicCreate(d *schema.ResourceData, meta interface{}
93
103
request .TopicName = helper .String (v .(string ))
94
104
}
95
105
96
- if v , ok := d .GetOk ("partition_count" ); ok {
106
+ if v , ok := d .GetOkExists ("partition_count" ); ok {
97
107
request .PartitionCount = helper .IntInt64 (v .(int ))
98
108
}
99
109
@@ -112,18 +122,28 @@ func resourceTencentCloudClsTopicCreate(d *schema.ResourceData, meta interface{}
112
122
request .AutoSplit = helper .Bool (v .(bool ))
113
123
}
114
124
115
- if v , ok := d .GetOk ("max_split_partitions" ); ok {
125
+ if v , ok := d .GetOkExists ("max_split_partitions" ); ok {
116
126
request .MaxSplitPartitions = helper .IntInt64 (v .(int ))
117
127
}
118
128
119
129
if v , ok := d .GetOk ("storage_type" ); ok {
120
130
request .StorageType = helper .String (v .(string ))
121
131
}
122
132
123
- if v , ok := d .GetOk ("period" ); ok {
133
+ if v , ok := d .GetOkExists ("period" ); ok {
124
134
request .Period = helper .IntInt64 (v .(int ))
125
135
}
126
136
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
+
127
147
err := resource .Retry (tccommon .WriteRetryTimeout , func () * resource.RetryError {
128
148
result , e := meta .(tccommon.ProviderMeta ).GetAPIV3Conn ().UseClsClient ().CreateTopic (request )
129
149
if e != nil {
@@ -132,6 +152,12 @@ func resourceTencentCloudClsTopicCreate(d *schema.ResourceData, meta interface{}
132
152
log .Printf ("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n " ,
133
153
logId , request .GetAction (), request .ToJsonString (), result .ToJsonString ())
134
154
}
155
+
156
+ if result == nil {
157
+ e = fmt .Errorf ("create cls topic failed" )
158
+ return resource .NonRetryableError (e )
159
+ }
160
+
135
161
response = result
136
162
return nil
137
163
})
@@ -150,14 +176,14 @@ func resourceTencentCloudClsTopicRead(d *schema.ResourceData, meta interface{})
150
176
defer tccommon .LogElapsed ("resource.tencentcloud_cls_topic.read" )()
151
177
defer tccommon .InconsistentCheck (d , meta )()
152
178
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
+ )
158
185
159
186
topic , err := service .DescribeClsTopicById (ctx , id )
160
-
161
187
if err != nil {
162
188
return err
163
189
}
@@ -175,36 +201,42 @@ func resourceTencentCloudClsTopicRead(d *schema.ResourceData, meta interface{})
175
201
for _ , tag := range topic .Tags {
176
202
tags [* tag .Key ] = * tag .Value
177
203
}
204
+
178
205
_ = d .Set ("tags" , tags )
179
206
_ = d .Set ("auto_split" , topic .AutoSplit )
180
207
_ = d .Set ("max_split_partitions" , topic .MaxSplitPartitions )
181
208
_ = d .Set ("storage_type" , topic .StorageType )
182
209
_ = d .Set ("period" , topic .Period )
210
+ _ = d .Set ("hot_period" , topic .HotPeriod )
211
+ _ = d .Set ("describes" , topic .Describes )
183
212
184
213
return nil
185
214
}
186
215
187
216
func resourceTencentCloudClsTopicUpdate (d * schema.ResourceData , meta interface {}) error {
188
217
defer tccommon .LogElapsed ("resource.tencentcloud_cls_topic.update" )()
189
- logId := tccommon .GetLogId (tccommon .ContextNil )
190
- request := cls .NewModifyTopicRequest ()
191
218
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" }
193
226
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
+ }
196
231
}
197
232
198
- if d .HasChange ("storage_type" ) {
199
- return fmt .Errorf ("`storage_type` do not support change now." )
200
- }
233
+ request .TopicId = helper .String (id )
201
234
202
235
if d .HasChange ("topic_name" ) {
203
236
request .TopicName = helper .String (d .Get ("topic_name" ).(string ))
204
237
}
205
238
206
239
if d .HasChange ("tags" ) {
207
-
208
240
tags := d .Get ("tags" ).(map [string ]interface {})
209
241
request .Tags = make ([]* cls.Tag , 0 , len (tags ))
210
242
for k , v := range tags {
@@ -229,6 +261,14 @@ func resourceTencentCloudClsTopicUpdate(d *schema.ResourceData, meta interface{}
229
261
request .Period = helper .IntInt64 (d .Get ("period" ).(int ))
230
262
}
231
263
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
+
232
272
err := resource .Retry (tccommon .WriteRetryTimeout , func () * resource.RetryError {
233
273
result , e := meta .(tccommon.ProviderMeta ).GetAPIV3Conn ().UseClsClient ().ModifyTopic (request )
234
274
if e != nil {
@@ -237,6 +277,7 @@ func resourceTencentCloudClsTopicUpdate(d *schema.ResourceData, meta interface{}
237
277
log .Printf ("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n " ,
238
278
logId , request .GetAction (), request .ToJsonString (), result .ToJsonString ())
239
279
}
280
+
240
281
return nil
241
282
})
242
283
@@ -250,10 +291,12 @@ func resourceTencentCloudClsTopicUpdate(d *schema.ResourceData, meta interface{}
250
291
func resourceTencentCloudClsTopicDelete (d * schema.ResourceData , meta interface {}) error {
251
292
defer tccommon .LogElapsed ("resource.tencentcloud_cls_topic.delete" )()
252
293
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
+ )
257
300
258
301
if err := service .DeleteClsTopic (ctx , id ); err != nil {
259
302
return err
0 commit comments