6
6
"log"
7
7
8
8
tccommon "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/common"
9
+ svctag "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/services/tag"
9
10
10
11
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
11
12
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
@@ -374,6 +375,7 @@ func resourceTencentCloudClsTopicUpdate(d *schema.ResourceData, meta interface{}
374
375
request = cls .NewModifyTopicRequest ()
375
376
id = d .Id ()
376
377
isWebTracking bool
378
+ ctx = context .WithValue (context .TODO (), tccommon .LogIdKey , logId )
377
379
)
378
380
379
381
immutableArgs := []string {"partition_count" , "storage_type" }
@@ -384,110 +386,122 @@ func resourceTencentCloudClsTopicUpdate(d *schema.ResourceData, meta interface{}
384
386
}
385
387
}
386
388
389
+ if d .HasChange ("tags" ) {
390
+ tcClient := meta .(tccommon.ProviderMeta ).GetAPIV3Conn ()
391
+ tagService := svctag .NewTagService (tcClient )
392
+ oldTags , newTags := d .GetChange ("tags" )
393
+ replaceTags , deleteTags := svctag .DiffTags (oldTags .(map [string ]interface {}), newTags .(map [string ]interface {}))
394
+ resourceName := tccommon .BuildTagResourceName ("cls" , "topic" , tcClient .Region , id )
395
+ if err := tagService .ModifyTags (ctx , resourceName , replaceTags , deleteTags ); err != nil {
396
+ return err
397
+ }
398
+ }
399
+
400
+ var hasChange bool
387
401
request .TopicId = helper .String (id )
388
402
389
403
if d .HasChange ("topic_name" ) {
390
404
request .TopicName = helper .String (d .Get ("topic_name" ).(string ))
391
- }
392
-
393
- if d .HasChange ("tags" ) {
394
- tags := d .Get ("tags" ).(map [string ]interface {})
395
- request .Tags = make ([]* cls.Tag , 0 , len (tags ))
396
- for k , v := range tags {
397
- key := k
398
- value := v
399
- request .Tags = append (request .Tags , & cls.Tag {
400
- Key : & key ,
401
- Value : helper .String (value .(string )),
402
- })
403
- }
405
+ hasChange = true
404
406
}
405
407
406
408
if d .HasChange ("auto_split" ) {
407
409
request .AutoSplit = helper .Bool (d .Get ("auto_split" ).(bool ))
410
+ hasChange = true
408
411
}
409
412
410
413
if d .HasChange ("max_split_partitions" ) {
411
414
request .MaxSplitPartitions = helper .IntInt64 (d .Get ("max_split_partitions" ).(int ))
415
+ hasChange = true
412
416
}
413
417
414
418
if d .HasChange ("period" ) {
415
419
request .Period = helper .IntInt64 (d .Get ("period" ).(int ))
420
+ hasChange = true
416
421
}
417
422
418
423
if d .HasChange ("hot_period" ) {
419
424
request .HotPeriod = helper .IntUint64 (d .Get ("hot_period" ).(int ))
425
+ hasChange = true
420
426
}
421
427
422
428
if d .HasChange ("describes" ) {
423
429
request .Describes = helper .String (d .Get ("describes" ).(string ))
430
+ hasChange = true
424
431
}
425
432
426
- if v , ok := d .GetOkExists ("is_web_tracking" ); ok {
427
- request .IsWebTracking = helper .Bool (v .(bool ))
428
- isWebTracking = v .(bool )
433
+ if d .HasChange ("is_web_tracking" ) {
434
+ if v , ok := d .GetOkExists ("is_web_tracking" ); ok {
435
+ request .IsWebTracking = helper .Bool (v .(bool ))
436
+ isWebTracking = v .(bool )
437
+ hasChange = true
438
+ }
429
439
}
440
+ if d .HasChange ("extends" ) {
441
+ if isWebTracking {
442
+ if dMap , ok := helper .InterfacesHeadMap (d , "extends" ); ok {
443
+ if anonymousAccessMap , ok := helper .InterfaceToMap (dMap , "anonymous_access" ); ok {
444
+ topicExtendInfo := cls.TopicExtendInfo {}
445
+ anonymousInfo := cls.AnonymousInfo {}
446
+ if v , ok := anonymousAccessMap ["operations" ]; ok {
447
+ tmpList := make ([]* string , 0 )
448
+ for _ , operation := range v .([]interface {}) {
449
+ tmpList = append (tmpList , helper .String (operation .(string )))
450
+ }
430
451
431
- if isWebTracking {
432
- if dMap , ok := helper .InterfacesHeadMap (d , "extends" ); ok {
433
- if anonymousAccessMap , ok := helper .InterfaceToMap (dMap , "anonymous_access" ); ok {
434
- topicExtendInfo := cls.TopicExtendInfo {}
435
- anonymousInfo := cls.AnonymousInfo {}
436
- if v , ok := anonymousAccessMap ["operations" ]; ok {
437
- tmpList := make ([]* string , 0 )
438
- for _ , operation := range v .([]interface {}) {
439
- tmpList = append (tmpList , helper .String (operation .(string )))
452
+ anonymousInfo .Operations = tmpList
440
453
}
441
454
442
- anonymousInfo .Operations = tmpList
443
- }
455
+ if v , ok := anonymousAccessMap ["conditions" ]; ok {
456
+ for _ , condition := range v .([]interface {}) {
457
+ conditionMap := condition .(map [string ]interface {})
458
+ conditionInfo := cls.ConditionInfo {}
459
+ if v , ok := conditionMap ["attributes" ]; ok {
460
+ conditionInfo .Attributes = helper .String (v .(string ))
461
+ }
444
462
445
- if v , ok := anonymousAccessMap ["conditions" ]; ok {
446
- for _ , condition := range v .([]interface {}) {
447
- conditionMap := condition .(map [string ]interface {})
448
- conditionInfo := cls.ConditionInfo {}
449
- if v , ok := conditionMap ["attributes" ]; ok {
450
- conditionInfo .Attributes = helper .String (v .(string ))
451
- }
463
+ if v , ok := conditionMap ["rule" ]; ok {
464
+ conditionInfo .Rule = helper .IntUint64 (v .(int ))
465
+ }
452
466
453
- if v , ok := conditionMap ["rule " ]; ok {
454
- conditionInfo .Rule = helper .IntUint64 (v .(int ))
455
- }
467
+ if v , ok := conditionMap ["condition_value " ]; ok {
468
+ conditionInfo .ConditionValue = helper .String (v .(string ))
469
+ }
456
470
457
- if v , ok := conditionMap ["condition_value" ]; ok {
458
- conditionInfo .ConditionValue = helper .String (v .(string ))
471
+ anonymousInfo .Conditions = append (anonymousInfo .Conditions , & conditionInfo )
459
472
}
460
-
461
- anonymousInfo .Conditions = append (anonymousInfo .Conditions , & conditionInfo )
462
473
}
463
- }
464
474
465
- topicExtendInfo .AnonymousAccess = & anonymousInfo
466
- request .Extends = & topicExtendInfo
475
+ topicExtendInfo .AnonymousAccess = & anonymousInfo
476
+ request .Extends = & topicExtendInfo
477
+ }
478
+ } else {
479
+ return fmt .Errorf ("If `is_web_tracking` is true, Must set `extends` params.\n ." )
467
480
}
468
481
} else {
469
- return fmt .Errorf ("If `is_web_tracking` is true, Must set `extends` params.\n ." )
470
- }
471
- } else {
472
- if _ , ok := helper .InterfacesHeadMap (d , "extends" ); ok {
473
- return fmt .Errorf ("If `is_web_tracking` is false, Not support set `extends` params.\n ." )
482
+ if _ , ok := helper .InterfacesHeadMap (d , "extends" ); ok {
483
+ return fmt .Errorf ("If `is_web_tracking` is false, Not support set `extends` params.\n ." )
484
+ }
474
485
}
486
+ hasChange = true
475
487
}
476
488
477
- err := resource .Retry (tccommon .WriteRetryTimeout , func () * resource.RetryError {
478
- result , e := meta .(tccommon.ProviderMeta ).GetAPIV3Conn ().UseClsClient ().ModifyTopic (request )
479
- if e != nil {
480
- return tccommon .RetryError (e )
481
- } else {
482
- log .Printf ("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n " ,
483
- logId , request .GetAction (), request .ToJsonString (), result .ToJsonString ())
484
- }
489
+ if hasChange {
490
+ err := resource .Retry (tccommon .WriteRetryTimeout , func () * resource.RetryError {
491
+ result , e := meta .(tccommon.ProviderMeta ).GetAPIV3Conn ().UseClsClient ().ModifyTopic (request )
492
+ if e != nil {
493
+ return tccommon .RetryError (e )
494
+ } else {
495
+ log .Printf ("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n " ,
496
+ logId , request .GetAction (), request .ToJsonString (), result .ToJsonString ())
497
+ }
485
498
486
- return nil
487
- })
499
+ return nil
500
+ })
488
501
489
- if err != nil {
490
- return err
502
+ if err != nil {
503
+ return err
504
+ }
491
505
}
492
506
493
507
return resourceTencentCloudClsTopicRead (d , meta )
0 commit comments