@@ -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,16 @@ 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
+ 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
+
661
654
return resourceTencentCloudMysqlInstanceRead (d , meta )
662
655
}
663
656
@@ -733,11 +726,15 @@ func tencentMsyqlBasicInfoRead(ctx context.Context, d *schema.ResourceData, meta
733
726
}
734
727
_ = d .Set ("gtid" , int (isGTIDOpen ))
735
728
}
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 ())
737
733
if err != nil {
738
734
errRet = err
739
735
return
740
736
}
737
+
741
738
if err := d .Set ("tags" , tags ); err != nil {
742
739
log .Printf ("[CRITAL]%s provider set tags fail, reason:%s\n " , logId , err .Error ())
743
740
return
@@ -993,25 +990,15 @@ func mysqlAllInstanceRoleUpdate(ctx context.Context, d *schema.ResourceData, met
993
990
if d .HasChange ("tags" ) {
994
991
995
992
oldValue , newValue := d .GetChange ("tags" )
993
+ replaceTags , deleteTags := diffTags (oldValue .(map [string ]interface {}), newValue .(map [string ]interface {}))
996
994
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 ,
1012
997
}
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 {
1015
1002
return err
1016
1003
}
1017
1004
d .SetPartial ("tags" )
0 commit comments