@@ -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,16 @@ 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+ log .Printf ("[DEBUG]Mysql instance create, resourceName:%s\n " , resourceName )
649+ if err := tagService .ModifyTags (ctx , resourceName , tags , nil ); err != nil {
650+ return err
651+ }
652+ }
653+
661654 return resourceTencentCloudMysqlInstanceRead (d , meta )
662655}
663656
@@ -733,11 +726,15 @@ func tencentMsyqlBasicInfoRead(ctx context.Context, d *schema.ResourceData, meta
733726 }
734727 _ = d .Set ("gtid" , int (isGTIDOpen ))
735728 }
736- tags , err := mysqlService .DescribeTagsOfInstanceId (ctx , d .Id ())
729+
730+ tcClient := meta .(* TencentCloudClient ).apiV3Conn
731+ tagService := & TagService {client : tcClient }
732+ tags , err := tagService .DescribeResourceTags (ctx , "cdb" , "instanceId" , tcClient .Region , d .Id ())
737733 if err != nil {
738734 errRet = err
739735 return
740736 }
737+
741738 if err := d .Set ("tags" , tags ); err != nil {
742739 log .Printf ("[CRITAL]%s provider set tags fail, reason:%s\n " , logId , err .Error ())
743740 return
@@ -993,25 +990,15 @@ func mysqlAllInstanceRoleUpdate(ctx context.Context, d *schema.ResourceData, met
993990 if d .HasChange ("tags" ) {
994991
995992 oldValue , newValue := d .GetChange ("tags" )
993+ replaceTags , deleteTags := diffTags (oldValue .(map [string ]interface {}), newValue .(map [string ]interface {}))
996994
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 )
995+ tagService := TagService {
996+ client : meta .(* TencentCloudClient ).apiV3Conn ,
1012997 }
1013-
1014- if err := mysqlService .ModifyInstanceTag (ctx , d .Id (), deleteTags , modifytTags ); err != nil {
998+ region := meta .(* TencentCloudClient ).apiV3Conn .Region
999+ resourceName := BuildTagResourceName ("cdb" , "instanceId" , region , d .Id ())
1000+ err := tagService .ModifyTags (ctx , resourceName , replaceTags , deleteTags )
1001+ if err != nil {
10151002 return err
10161003 }
10171004 d .SetPartial ("tags" )
0 commit comments