Skip to content

Commit ff37fde

Browse files
committed
fix cvm creation while its tags not sync issue
When cvm created success, its tags may not attached at once, since it's async. We use a dedicated [tag](https://cloud.tencent.com/document/api/651/35326) api to attach and makes its behavior like a sync one.
1 parent 5e886be commit ff37fde

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

tencentcloud/resource_tc_instance.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -598,6 +598,20 @@ func resourceTencentCloudInstanceCreate(d *schema.ResourceData, meta interface{}
598598
return err
599599
}
600600

601+
// Wait for the tags attached to the vm since tags attachment it's async while vm creation.
602+
if tags := helper.GetTags(d, "tags"); len(tags) > 0 {
603+
tcClient := meta.(*TencentCloudClient).apiV3Conn
604+
tagService := &TagService{client: tcClient}
605+
resourceName := BuildTagResourceName("cvm", "instance", tcClient.Region, instanceId)
606+
err := tagService.ModifyTags(ctx, resourceName, tags, nil)
607+
if err != nil {
608+
// Since we have included the tags params in the creating cvm request,
609+
// when the call returns success, we assume it's successful, regardless of this `ModifyTags` call failed.
610+
// The next time user run terraform, the missing tags(if any) would be synced.
611+
log.Printf("[WARN] sync cvm %s tags failed: %+v, ignore", instanceId, err)
612+
}
613+
}
614+
601615
if !(d.Get("running_flag").(bool)) {
602616
err = cvmService.StopInstance(ctx, instanceId)
603617
if err != nil {

0 commit comments

Comments
 (0)