Skip to content

Commit 6222128

Browse files
committed
refactor cvm tags related stuff
- use `helper.GetTags` to do with tags uniformly - use `BuildTagResourceName` to build resource name uniformly
1 parent ff37fde commit 6222128

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

tencentcloud/common.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,9 @@ func CheckNil(object interface{}, fields map[string]string) (nilFields []string)
191191
return
192192
}
193193

194+
// BuildTagResourceName builds the Tencent Clould specific name of a resource description.
195+
// The format is `qcs:project_id:service_type:region:account:resource`.
196+
// For more information, go to https://cloud.tencent.com/document/product/598/10606.
194197
func BuildTagResourceName(serviceType, resourceType, region, id string) string {
195198
switch serviceType {
196199
case "cos":

tencentcloud/resource_tc_instance.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -542,12 +542,12 @@ func resourceTencentCloudInstanceCreate(d *schema.ResourceData, meta interface{}
542542
}
543543

544544
// tags
545-
if v, ok := d.GetOk("tags"); ok {
545+
if tmpTags := helper.GetTags(d, "tags"); len(tmpTags) > 0 {
546546
tags := make([]*cvm.Tag, 0)
547-
for key, value := range v.(map[string]interface{}) {
547+
for k, v := range tmpTags {
548548
tag := &cvm.Tag{
549-
Key: helper.String(key),
550-
Value: helper.String(value.(string)),
549+
Key: helper.String(k),
550+
Value: helper.String(v),
551551
}
552552
tags = append(tags, tag)
553553
}
@@ -974,7 +974,7 @@ func resourceTencentCloudInstanceUpdate(d *schema.ResourceData, meta interface{}
974974
client: meta.(*TencentCloudClient).apiV3Conn,
975975
}
976976
region := meta.(*TencentCloudClient).apiV3Conn.Region
977-
resourceName := fmt.Sprintf("qcs::cvm:%s:uin/:instance/%s", region, instanceId)
977+
resourceName := BuildTagResourceName("cvm", "instance", region, instanceId)
978978
err := tagService.ModifyTags(ctx, resourceName, replaceTags, deleteTags)
979979
if err != nil {
980980
return err

0 commit comments

Comments
 (0)