@@ -91,7 +91,6 @@ func ResourceTencentCloudClsTopic() *schema.Resource {
91
91
"extends" : {
92
92
Type : schema .TypeList ,
93
93
Optional : true ,
94
- Computed : true ,
95
94
MaxItems : 1 ,
96
95
Description : "Log Subject Extension Information." ,
97
96
Elem : & schema.Resource {
@@ -147,9 +146,10 @@ func resourceTencentCloudClsTopicCreate(d *schema.ResourceData, meta interface{}
147
146
defer tccommon .LogElapsed ("resource.tencentcloud_cls_topic.create" )()
148
147
149
148
var (
150
- logId = tccommon .GetLogId (tccommon .ContextNil )
151
- request = cls .NewCreateTopicRequest ()
152
- response * cls.CreateTopicResponse
149
+ logId = tccommon .GetLogId (tccommon .ContextNil )
150
+ request = cls .NewCreateTopicRequest ()
151
+ response * cls.CreateTopicResponse
152
+ isWebTracking bool
153
153
)
154
154
155
155
if v , ok := d .GetOk ("logset_id" ); ok {
@@ -203,45 +203,52 @@ func resourceTencentCloudClsTopicCreate(d *schema.ResourceData, meta interface{}
203
203
204
204
if v , ok := d .GetOkExists ("is_web_tracking" ); ok {
205
205
request .IsWebTracking = helper .Bool (v .(bool ))
206
+ isWebTracking = v .(bool )
206
207
}
207
208
208
- if dMap , ok := helper .InterfacesHeadMap (d , "extends" ); ok {
209
- topicExtendInfo := cls.TopicExtendInfo {}
210
- if anonymousAccessMap , ok := helper .InterfaceToMap (dMap , "anonymous_access" ); ok {
211
- anonymousInfo := cls.AnonymousInfo {}
212
- if v , ok := anonymousAccessMap ["operations" ]; ok {
213
- tmpList := make ([]* string , 0 )
214
- for _ , operation := range v .([]interface {}) {
215
- tmpList = append (tmpList , helper .String (operation .(string )))
209
+ if isWebTracking {
210
+ if dMap , ok := helper .InterfacesHeadMap (d , "extends" ); ok {
211
+ topicExtendInfo := cls.TopicExtendInfo {}
212
+ if anonymousAccessMap , ok := helper .InterfaceToMap (dMap , "anonymous_access" ); ok {
213
+ anonymousInfo := cls.AnonymousInfo {}
214
+ if v , ok := anonymousAccessMap ["operations" ]; ok {
215
+ tmpList := make ([]* string , 0 )
216
+ for _ , operation := range v .([]interface {}) {
217
+ tmpList = append (tmpList , helper .String (operation .(string )))
218
+ }
219
+
220
+ anonymousInfo .Operations = tmpList
216
221
}
217
222
218
- anonymousInfo .Operations = tmpList
219
- }
223
+ if v , ok := anonymousAccessMap ["conditions" ]; ok {
224
+ for _ , condition := range v .([]interface {}) {
225
+ conditionMap := condition .(map [string ]interface {})
226
+ conditionInfo := cls.ConditionInfo {}
227
+ if v , ok := conditionMap ["attributes" ]; ok {
228
+ conditionInfo .Attributes = helper .String (v .(string ))
229
+ }
220
230
221
- if v , ok := anonymousAccessMap ["conditions" ]; ok {
222
- for _ , condition := range v .([]interface {}) {
223
- conditionMap := condition .(map [string ]interface {})
224
- conditionInfo := cls.ConditionInfo {}
225
- if v , ok := conditionMap ["attributes" ]; ok {
226
- conditionInfo .Attributes = helper .String (v .(string ))
227
- }
231
+ if v , ok := conditionMap ["rule" ]; ok {
232
+ conditionInfo .Rule = helper .IntUint64 (v .(int ))
233
+ }
228
234
229
- if v , ok := conditionMap ["rule " ]; ok {
230
- conditionInfo .Rule = helper .IntUint64 (v .(int ))
231
- }
235
+ if v , ok := conditionMap ["condition_value " ]; ok {
236
+ conditionInfo .ConditionValue = helper .String (v .(string ))
237
+ }
232
238
233
- if v , ok := conditionMap ["condition_value" ]; ok {
234
- conditionInfo .ConditionValue = helper .String (v .(string ))
239
+ anonymousInfo .Conditions = append (anonymousInfo .Conditions , & conditionInfo )
235
240
}
236
-
237
- anonymousInfo .Conditions = append (anonymousInfo .Conditions , & conditionInfo )
238
241
}
242
+
243
+ topicExtendInfo .AnonymousAccess = & anonymousInfo
239
244
}
240
245
241
- topicExtendInfo .AnonymousAccess = & anonymousInfo
246
+ request .Extends = & topicExtendInfo
247
+ }
248
+ } else {
249
+ if _ , ok := helper .InterfacesHeadMap (d , "extends" ); ok {
250
+ return fmt .Errorf ("If `is_web_tracking` is false, Not support set `extends`.\n ." )
242
251
}
243
-
244
- request .Extends = & topicExtendInfo
245
252
}
246
253
247
254
err := resource .Retry (tccommon .WriteRetryTimeout , func () * resource.RetryError {
@@ -311,45 +318,47 @@ func resourceTencentCloudClsTopicRead(d *schema.ResourceData, meta interface{})
311
318
_ = d .Set ("describes" , topic .Describes )
312
319
_ = d .Set ("is_web_tracking" , topic .IsWebTracking )
313
320
314
- if topic .Extends != nil {
315
- extendMap := map [string ]interface {}{}
316
- if topic .Extends .AnonymousAccess != nil {
317
- anonymousAccessMap := map [string ]interface {}{}
318
- if topic .Extends .AnonymousAccess .Operations != nil {
319
- operationList := make ([]string , 0 , len (topic .Extends .AnonymousAccess .Operations ))
320
- for _ , v := range topic .Extends .AnonymousAccess .Operations {
321
- operationList = append (operationList , * v )
321
+ if * topic .IsWebTracking {
322
+ if topic .Extends != nil {
323
+ extendMap := map [string ]interface {}{}
324
+ if topic .Extends .AnonymousAccess != nil {
325
+ anonymousAccessMap := map [string ]interface {}{}
326
+ if topic .Extends .AnonymousAccess .Operations != nil {
327
+ operationList := make ([]string , 0 , len (topic .Extends .AnonymousAccess .Operations ))
328
+ for _ , v := range topic .Extends .AnonymousAccess .Operations {
329
+ operationList = append (operationList , * v )
330
+ }
331
+
332
+ anonymousAccessMap ["operations" ] = operationList
322
333
}
323
334
324
- anonymousAccessMap ["operations" ] = operationList
325
- }
335
+ if topic .Extends .AnonymousAccess .Conditions != nil {
336
+ conditionList := []interface {}{}
337
+ for _ , v := range topic .Extends .AnonymousAccess .Conditions {
338
+ conditionMap := map [string ]interface {}{}
339
+ if v .Attributes != nil {
340
+ conditionMap ["attributes" ] = * v .Attributes
341
+ }
326
342
327
- if topic .Extends .AnonymousAccess .Conditions != nil {
328
- conditionList := []interface {}{}
329
- for _ , v := range topic .Extends .AnonymousAccess .Conditions {
330
- conditionMap := map [string ]interface {}{}
331
- if v .Attributes != nil {
332
- conditionMap ["attributes" ] = * v .Attributes
333
- }
343
+ if v .Rule != nil {
344
+ conditionMap ["rule" ] = * v .Rule
345
+ }
334
346
335
- if v .Rule != nil {
336
- conditionMap ["rule " ] = * v .Rule
337
- }
347
+ if v .ConditionValue != nil {
348
+ conditionMap ["condition_value " ] = * v .ConditionValue
349
+ }
338
350
339
- if v .ConditionValue != nil {
340
- conditionMap ["condition_value" ] = * v .ConditionValue
351
+ conditionList = append (conditionList , conditionMap )
341
352
}
342
353
343
- conditionList = append ( conditionList , conditionMap )
354
+ anonymousAccessMap [ "conditions" ] = conditionList
344
355
}
345
356
346
- anonymousAccessMap [ "conditions " ] = conditionList
357
+ extendMap [ "anonymous_access " ] = [] interface {}{ anonymousAccessMap }
347
358
}
348
359
349
- extendMap [ "anonymous_access" ] = []interface {}{anonymousAccessMap }
360
+ _ = d . Set ( "extends" , []interface {}{extendMap })
350
361
}
351
-
352
- _ = d .Set ("extends" , []interface {}{extendMap })
353
362
}
354
363
355
364
return nil
@@ -359,9 +368,10 @@ func resourceTencentCloudClsTopicUpdate(d *schema.ResourceData, meta interface{}
359
368
defer tccommon .LogElapsed ("resource.tencentcloud_cls_topic.update" )()
360
369
361
370
var (
362
- logId = tccommon .GetLogId (tccommon .ContextNil )
363
- request = cls .NewModifyTopicRequest ()
364
- id = d .Id ()
371
+ logId = tccommon .GetLogId (tccommon .ContextNil )
372
+ request = cls .NewModifyTopicRequest ()
373
+ id = d .Id ()
374
+ isWebTracking bool
365
375
)
366
376
367
377
immutableArgs := []string {"partition_count" , "storage_type" }
@@ -411,16 +421,15 @@ func resourceTencentCloudClsTopicUpdate(d *schema.ResourceData, meta interface{}
411
421
request .Describes = helper .String (d .Get ("describes" ).(string ))
412
422
}
413
423
414
- if d .HasChange ("is_web_tracking" ) {
415
- if v , ok := d .GetOkExists ("is_web_tracking" ); ok {
416
- request .IsWebTracking = helper .Bool (v .(bool ))
417
- }
424
+ if v , ok := d .GetOkExists ("is_web_tracking" ); ok {
425
+ request .IsWebTracking = helper .Bool (v .(bool ))
426
+ isWebTracking = v .(bool )
418
427
}
419
428
420
- if d . HasChange ( "extends" ) {
429
+ if isWebTracking {
421
430
if dMap , ok := helper .InterfacesHeadMap (d , "extends" ); ok {
422
- topicExtendInfo := cls.TopicExtendInfo {}
423
431
if anonymousAccessMap , ok := helper .InterfaceToMap (dMap , "anonymous_access" ); ok {
432
+ topicExtendInfo := cls.TopicExtendInfo {}
424
433
anonymousInfo := cls.AnonymousInfo {}
425
434
if v , ok := anonymousAccessMap ["operations" ]; ok {
426
435
tmpList := make ([]* string , 0 )
@@ -452,9 +461,14 @@ func resourceTencentCloudClsTopicUpdate(d *schema.ResourceData, meta interface{}
452
461
}
453
462
454
463
topicExtendInfo .AnonymousAccess = & anonymousInfo
464
+ request .Extends = & topicExtendInfo
455
465
}
456
-
457
- request .Extends = & topicExtendInfo
466
+ } else {
467
+ return fmt .Errorf ("If `is_web_tracking` is true, Must set `extends` params.\n ." )
468
+ }
469
+ } else {
470
+ if _ , ok := helper .InterfacesHeadMap (d , "extends" ); ok {
471
+ return fmt .Errorf ("If `is_web_tracking` is false, Not support set `extends` params.\n ." )
458
472
}
459
473
}
460
474
0 commit comments