Skip to content

Commit 1ec3141

Browse files
committed
remove old tag attachement code
If new tag api call failed, the user will be notified and tack actions with terraform
1 parent 6222128 commit 1ec3141

File tree

1 file changed

+3
-23
lines changed

1 file changed

+3
-23
lines changed

tencentcloud/resource_tc_instance.go

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -541,23 +541,6 @@ func resourceTencentCloudInstanceCreate(d *schema.ResourceData, meta interface{}
541541
request.UserData = &userData
542542
}
543543

544-
// tags
545-
if tmpTags := helper.GetTags(d, "tags"); len(tmpTags) > 0 {
546-
tags := make([]*cvm.Tag, 0)
547-
for k, v := range tmpTags {
548-
tag := &cvm.Tag{
549-
Key: helper.String(k),
550-
Value: helper.String(v),
551-
}
552-
tags = append(tags, tag)
553-
}
554-
tagSpecification := &cvm.TagSpecification{
555-
ResourceType: helper.String("instance"),
556-
Tags: tags,
557-
}
558-
request.TagSpecification = []*cvm.TagSpecification{tagSpecification}
559-
}
560-
561544
instanceId := ""
562545
err := resource.Retry(writeRetryTimeout, func() *resource.RetryError {
563546
ratelimit.Check("create")
@@ -603,12 +586,9 @@ func resourceTencentCloudInstanceCreate(d *schema.ResourceData, meta interface{}
603586
tcClient := meta.(*TencentCloudClient).apiV3Conn
604587
tagService := &TagService{client: tcClient}
605588
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)
589+
if err := tagService.ModifyTags(ctx, resourceName, tags, nil); err != nil {
590+
// If tags attachment failed, the user will be notified, then plan/apply/update with terraform.
591+
return err
612592
}
613593
}
614594

0 commit comments

Comments
 (0)