Skip to content

Commit aecd633

Browse files
authored
fix(es): [134409541] tencentcloud_elasticsearch_instance optimize code for tag (#4134)
* add * add
1 parent 718224a commit aecd633

2 files changed

Lines changed: 15 additions & 12 deletions

File tree

.changelog/4134.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
resource/tencentcloud_elasticsearch_instance: optimize code logic for create function
3+
```

tencentcloud/services/es/resource_tc_elasticsearch_instance.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,18 @@ func resourceTencentCloudElasticsearchInstanceCreate(d *schema.ResourceData, met
470470
if v, ok := d.GetOk("protocol"); ok {
471471
request.Protocol = helper.String(v.(string))
472472
}
473+
// tags - pass via CreateInstance.TagList directly instead of calling tag API afterwards.
474+
if tags := helper.GetTags(d, "tags"); len(tags) > 0 {
475+
tagList := make([]*es.TagInfo, 0, len(tags))
476+
for k, v := range tags {
477+
key, value := k, v
478+
tagList = append(tagList, &es.TagInfo{
479+
TagKey: &key,
480+
TagValue: &value,
481+
})
482+
}
483+
request.TagList = tagList
484+
}
473485
//internal version: replace reqTag begin, please do not modify this annotation and refrain from inserting any code between the beginning and end lines of the annotation.
474486
//internal version: replace reqTag end, please do not modify this annotation and refrain from inserting any code between the beginning and end lines of the annotation.
475487
instanceId := ""
@@ -670,18 +682,6 @@ func resourceTencentCloudElasticsearchInstanceCreate(d *schema.ResourceData, met
670682
}
671683
}
672684

673-
// tags
674-
if tags := helper.GetTags(d, "tags"); len(tags) > 0 {
675-
client := meta.(tccommon.ProviderMeta).GetAPIV3Conn()
676-
tagService := svctag.NewTagService(client)
677-
region := client.Region
678-
resourceName := fmt.Sprintf("qcs::es:%s:uin/:instance/%s", region, instanceId)
679-
err := tagService.ModifyTags(ctx, resourceName, tags, nil)
680-
if err != nil {
681-
return err
682-
}
683-
}
684-
685685
return resourceTencentCloudElasticsearchInstanceRead(d, meta)
686686
}
687687

0 commit comments

Comments
 (0)