@@ -397,23 +397,6 @@ func mysqlAllInstanceRoleSet(ctx context.Context, requestInter interface{}, d *s
397
397
requestByUse .SecurityGroup = requestSecurityGroup
398
398
}
399
399
}
400
-
401
- if tagsMap , ok := d .Get ("tags" ).(map [string ]interface {}); ok {
402
- requestResourceTags := make ([]* cdb.TagInfo , 0 , len (tagsMap ))
403
- for k , v := range tagsMap {
404
- key := k
405
- value := v .(string )
406
- var tagInfo cdb.TagInfo
407
- tagInfo .TagKey = & key
408
- tagInfo .TagValue = []* string {& value }
409
- requestResourceTags = append (requestResourceTags , & tagInfo )
410
- }
411
- if okByMonth {
412
- requestByMonth .ResourceTags = requestResourceTags
413
- } else {
414
- requestByUse .ResourceTags = requestResourceTags
415
- }
416
- }
417
400
return nil
418
401
419
402
}
@@ -658,6 +641,15 @@ func resourceTencentCloudMysqlInstanceCreate(d *schema.ResourceData, meta interf
658
641
}
659
642
}
660
643
644
+ if tags := helper .GetTags (d , "tags" ); len (tags ) > 0 {
645
+ tcClient := meta .(* TencentCloudClient ).apiV3Conn
646
+ tagService := & TagService {client : tcClient }
647
+ resourceName := BuildTagResourceName ("cdb" , "instanceId" , tcClient .Region , d .Id ())
648
+ if err := tagService .ModifyTags (ctx , resourceName , tags , nil ); err != nil {
649
+ return err
650
+ }
651
+ }
652
+
661
653
return resourceTencentCloudMysqlInstanceRead (d , meta )
662
654
}
663
655
@@ -733,11 +725,15 @@ func tencentMsyqlBasicInfoRead(ctx context.Context, d *schema.ResourceData, meta
733
725
}
734
726
_ = d .Set ("gtid" , int (isGTIDOpen ))
735
727
}
736
- tags , err := mysqlService .DescribeTagsOfInstanceId (ctx , d .Id ())
728
+
729
+ tcClient := meta .(* TencentCloudClient ).apiV3Conn
730
+ tagService := & TagService {client : tcClient }
731
+ tags , err := tagService .DescribeResourceTags (ctx , "cdb" , "instanceId" , tcClient .Region , d .Id ())
737
732
if err != nil {
738
733
errRet = err
739
734
return
740
735
}
736
+
741
737
if err := d .Set ("tags" , tags ); err != nil {
742
738
log .Printf ("[CRITAL]%s provider set tags fail, reason:%s\n " , logId , err .Error ())
743
739
return
@@ -993,25 +989,14 @@ func mysqlAllInstanceRoleUpdate(ctx context.Context, d *schema.ResourceData, met
993
989
if d .HasChange ("tags" ) {
994
990
995
991
oldValue , newValue := d .GetChange ("tags" )
992
+ replaceTags , deleteTags := diffTags (oldValue .(map [string ]interface {}), newValue .(map [string ]interface {}))
996
993
997
- oldTags := oldValue .(map [string ]interface {})
998
- newTags := newValue .(map [string ]interface {})
999
-
1000
- //set(oldTags-newTags) need delete
1001
- var deleteTags = make (map [string ]string , len (oldTags ))
1002
- for k , v := range oldTags {
1003
- if _ , has := newTags [k ]; ! has {
1004
- deleteTags [k ] = v .(string )
1005
- }
1006
- }
1007
-
1008
- //set newTags need modify
1009
- var modifytTags = make (map [string ]string , len (newTags ))
1010
- for k , v := range newTags {
1011
- modifytTags [k ] = v .(string )
1012
- }
1013
-
1014
- if err := mysqlService .ModifyInstanceTag (ctx , d .Id (), deleteTags , modifytTags ); err != nil {
994
+ tcClient := meta .(* TencentCloudClient ).apiV3Conn
995
+ tagService := & TagService {client : tcClient }
996
+ region := meta .(* TencentCloudClient ).apiV3Conn .Region
997
+ resourceName := BuildTagResourceName ("cdb" , "instanceId" , region , d .Id ())
998
+ err := tagService .ModifyTags (ctx , resourceName , replaceTags , deleteTags )
999
+ if err != nil {
1015
1000
return err
1016
1001
}
1017
1002
d .SetPartial ("tags" )
0 commit comments