@@ -397,23 +397,6 @@ func mysqlAllInstanceRoleSet(ctx context.Context, requestInter interface{}, d *s
397397 requestByUse .SecurityGroup = requestSecurityGroup
398398 }
399399 }
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- }
417400 return nil
418401
419402}
@@ -658,6 +641,15 @@ func resourceTencentCloudMysqlInstanceCreate(d *schema.ResourceData, meta interf
658641 }
659642 }
660643
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+
661653 return resourceTencentCloudMysqlInstanceRead (d , meta )
662654}
663655
@@ -733,11 +725,15 @@ func tencentMsyqlBasicInfoRead(ctx context.Context, d *schema.ResourceData, meta
733725 }
734726 _ = d .Set ("gtid" , int (isGTIDOpen ))
735727 }
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 ())
737732 if err != nil {
738733 errRet = err
739734 return
740735 }
736+
741737 if err := d .Set ("tags" , tags ); err != nil {
742738 log .Printf ("[CRITAL]%s provider set tags fail, reason:%s\n " , logId , err .Error ())
743739 return
@@ -993,25 +989,14 @@ func mysqlAllInstanceRoleUpdate(ctx context.Context, d *schema.ResourceData, met
993989 if d .HasChange ("tags" ) {
994990
995991 oldValue , newValue := d .GetChange ("tags" )
992+ replaceTags , deleteTags := diffTags (oldValue .(map [string ]interface {}), newValue .(map [string ]interface {}))
996993
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 {
10151000 return err
10161001 }
10171002 d .SetPartial ("tags" )
0 commit comments