Skip to content

Commit f138201

Browse files
authored
Merge branch 'master' into master
2 parents c226217 + 86b1cd8 commit f138201

File tree

3 files changed

+19
-40
lines changed

3 files changed

+19
-40
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
## 1.39.0 (Unreleased)
1+
## 1.38.2 (Unreleased)
22

33
BUG FIXES:
44

5+
* Resource: `tencentcloud_instance` fix `allocate_public_ip` inconsistency when eip is attached to the cvm.
56
* Resource: `tencentcloud_mysql_instance` fix auto-forcenew on `charge_type` and `pay_type` when upgrading terraform version. ([#459](https://github.com/terraform-providers/terraform-provider-tencentcloud/pull/459)).
67

78
## 1.38.1 (June 30, 2020)

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: 14 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ import (
8787
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
8888
"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/errors"
8989
cvm "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm/v20170312"
90-
vpc "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/vpc/v20170312"
9190
"github.com/terraform-providers/terraform-provider-tencentcloud/tencentcloud/internal/helper"
9291
"github.com/terraform-providers/terraform-provider-tencentcloud/tencentcloud/ratelimit"
9392
)
@@ -541,23 +540,6 @@ func resourceTencentCloudInstanceCreate(d *schema.ResourceData, meta interface{}
541540
request.UserData = &userData
542541
}
543542

544-
// tags
545-
if v, ok := d.GetOk("tags"); ok {
546-
tags := make([]*cvm.Tag, 0)
547-
for key, value := range v.(map[string]interface{}) {
548-
tag := &cvm.Tag{
549-
Key: helper.String(key),
550-
Value: helper.String(value.(string)),
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-
561543
instanceId := ""
562544
err := resource.Retry(writeRetryTimeout, func() *resource.RetryError {
563545
ratelimit.Check("create")
@@ -598,6 +580,17 @@ func resourceTencentCloudInstanceCreate(d *schema.ResourceData, meta interface{}
598580
return err
599581
}
600582

583+
// Wait for the tags attached to the vm since tags attachment it's async while vm creation.
584+
if tags := helper.GetTags(d, "tags"); len(tags) > 0 {
585+
tcClient := meta.(*TencentCloudClient).apiV3Conn
586+
tagService := &TagService{client: tcClient}
587+
resourceName := BuildTagResourceName("cvm", "instance", tcClient.Region, instanceId)
588+
if err := tagService.ModifyTags(ctx, resourceName, tags, nil); err != nil {
589+
// If tags attachment failed, the user will be notified, then plan/apply/update with terraform.
590+
return err
591+
}
592+
}
593+
601594
if !(d.Get("running_flag").(bool)) {
602595
err = cvmService.StopInstance(ctx, instanceId)
603596
if err != nil {
@@ -695,26 +688,8 @@ func resourceTencentCloudInstanceRead(d *schema.ResourceData, meta interface{})
695688
_ = d.Set("create_time", instance.CreatedTime)
696689
_ = d.Set("expired_time", instance.ExpiredTime)
697690

698-
if len(instance.PublicIpAddresses) > 0 {
699-
vpcService := VpcService{client: client}
700-
filter := map[string][]string{
701-
"address-ip": {*instance.PublicIpAddresses[0]},
702-
}
703-
var eips []*vpc.Address
704-
var errRet error
705-
err := resource.Retry(readRetryTimeout, func() *resource.RetryError {
706-
eips, errRet = vpcService.DescribeEipByFilter(ctx, filter)
707-
if errRet != nil {
708-
return retryError(errRet, InternalError)
709-
}
710-
return nil
711-
})
712-
if err != nil {
713-
return err
714-
}
715-
_ = d.Set("allocate_public_ip", len(eips) < 1)
716-
} else {
717-
_ = d.Set("allocate_public_ip", false)
691+
if _, ok := d.GetOkExists("allocate_public_ip"); !ok {
692+
_ = d.Set("allocate_public_ip", len(instance.PublicIpAddresses) > 0)
718693
}
719694

720695
// as attachment add tencentcloud:autoscaling:auto-scaling-group-id tag automatically
@@ -960,7 +935,7 @@ func resourceTencentCloudInstanceUpdate(d *schema.ResourceData, meta interface{}
960935
client: meta.(*TencentCloudClient).apiV3Conn,
961936
}
962937
region := meta.(*TencentCloudClient).apiV3Conn.Region
963-
resourceName := fmt.Sprintf("qcs::cvm:%s:uin/:instance/%s", region, instanceId)
938+
resourceName := BuildTagResourceName("cvm", "instance", region, instanceId)
964939
err := tagService.ModifyTags(ctx, resourceName, replaceTags, deleteTags)
965940
if err != nil {
966941
return err

0 commit comments

Comments
 (0)