Skip to content

Commit 07d5661

Browse files
tongyimingmikatong
andauthored
[fix]rollback instance_charge_type_prepaid_period (#799)
* [fix]rollback instance_charge_type_prepaid_period * [fix]rollback instance_charge_type_prepaid_period Co-authored-by: mikatong <[email protected]>
1 parent c3a17f5 commit 07d5661

File tree

3 files changed

+14
-53
lines changed

3 files changed

+14
-53
lines changed

tencentcloud/extension_cvm.go

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
package tencentcloud
22

3-
import (
4-
"time"
5-
)
6-
73
const (
84
CVM_CHARGE_TYPE_PREPAID = "PREPAID"
95
CVM_CHARGE_TYPE_POSTPAID = "POSTPAID_BY_HOUR"
@@ -103,23 +99,3 @@ var CVM_PLACEMENT_GROUP_TYPE = []string{
10399
var CVM_SPOT_INSTANCE_TYPE = []string{
104100
CVM_SPOT_INSTANCE_TYPE_ONE_TIME,
105101
}
106-
107-
func DeltaMonth(t1, t2 string) (deltaMonth int, err error) {
108-
// t1-t2
109-
timeTemplate := "2006-01-02T15:04:05Z"
110-
tt1, err := time.Parse(timeTemplate, t1)
111-
if err != nil {
112-
return
113-
}
114-
tt2, err := time.Parse(timeTemplate, t2)
115-
if err != nil {
116-
return
117-
}
118-
tt1Month := int(tt1.Month())
119-
tt2Month := int(tt2.Month())
120-
deltaMonth = tt1Month - tt2Month
121-
if deltaMonth < 0 {
122-
deltaMonth += 12
123-
}
124-
return
125-
}

tencentcloud/resource_tc_instance.go

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Example Usage
1010
```hcl
1111
data "tencentcloud_images" "my_favorite_image" {
1212
image_type = ["PUBLIC_IMAGE"]
13-
os_name = "centos"
13+
os_name = "Tencent Linux release 3.2 (Final)"
1414
}
1515
1616
data "tencentcloud_instance_types" "my_favorite_instance_types" {
@@ -51,9 +51,7 @@ resource "tencentcloud_instance" "my_awesome_app" {
5151
project_id = 0
5252
vpc_id = tencentcloud_vpc.app.id
5353
subnet_id = tencentcloud_subnet.app.id
54-
internet_max_bandwidth_out = 20
5554
count = 2
56-
cam_role_name = "CVM_QcsRole"
5755
5856
data_disks {
5957
data_disk_type = "CLOUD_PREMIUM"
@@ -146,7 +144,6 @@ import (
146144

147145
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
148146
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
149-
"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/errors"
150147
sdkErrors "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/errors"
151148
cvm "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm/v20170312"
152149
"github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper"
@@ -886,16 +883,6 @@ func resourceTencentCloudInstanceRead(d *schema.ResourceData, meta interface{})
886883
if d.Get("image_id").(string) == "" || !IsContains(cvmImages, *instance.ImageId) {
887884
_ = d.Set("image_id", instance.ImageId)
888885
}
889-
expiredTime := instance.ExpiredTime
890-
createdTime := instance.CreatedTime
891-
if expiredTime != nil && createdTime != nil {
892-
deltaMonth, err := DeltaMonth(*instance.ExpiredTime, *instance.CreatedTime)
893-
if err != nil {
894-
return err
895-
}
896-
_ = d.Set("instance_charge_type_prepaid_period", deltaMonth)
897-
898-
}
899886

900887
_ = d.Set("availability_zone", instance.Placement.Zone)
901888
_ = d.Set("instance_name", instance.InstanceName)
@@ -1449,7 +1436,7 @@ func resourceTencentCloudInstanceDelete(d *schema.ResourceData, meta interface{}
14491436
//when state is terminating, do not delete but check exist
14501437
if errRet != nil {
14511438
//check InvalidInstanceState.Terminating
1452-
ee, ok := errRet.(*errors.TencentCloudSDKError)
1439+
ee, ok := errRet.(*sdkErrors.TencentCloudSDKError)
14531440
if !ok {
14541441
return retryError(errRet)
14551442
}

website/docs/r/instance.html.markdown

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Provides a CVM instance resource.
2020
```hcl
2121
data "tencentcloud_images" "my_favorite_image" {
2222
image_type = ["PUBLIC_IMAGE"]
23-
os_name = "centos"
23+
os_name = "Tencent Linux release 3.2 (Final)"
2424
}
2525
2626
data "tencentcloud_instance_types" "my_favorite_instance_types" {
@@ -51,19 +51,17 @@ resource "tencentcloud_subnet" "app" {
5151
5252
// Create 2 CVM instances to host awesome_app
5353
resource "tencentcloud_instance" "my_awesome_app" {
54-
instance_name = "awesome_app"
55-
availability_zone = data.tencentcloud_availability_zones.my_favorite_zones.zones.0.name
56-
image_id = data.tencentcloud_images.my_favorite_image.images.0.image_id
57-
instance_type = data.tencentcloud_instance_types.my_favorite_instance_types.instance_types.0.instance_type
58-
system_disk_type = "CLOUD_PREMIUM"
59-
system_disk_size = 50
60-
hostname = "user"
61-
project_id = 0
62-
vpc_id = tencentcloud_vpc.app.id
63-
subnet_id = tencentcloud_subnet.app.id
64-
internet_max_bandwidth_out = 20
65-
count = 2
66-
cam_role_name = "CVM_QcsRole"
54+
instance_name = "awesome_app"
55+
availability_zone = data.tencentcloud_availability_zones.my_favorite_zones.zones.0.name
56+
image_id = data.tencentcloud_images.my_favorite_image.images.0.image_id
57+
instance_type = data.tencentcloud_instance_types.my_favorite_instance_types.instance_types.0.instance_type
58+
system_disk_type = "CLOUD_PREMIUM"
59+
system_disk_size = 50
60+
hostname = "user"
61+
project_id = 0
62+
vpc_id = tencentcloud_vpc.app.id
63+
subnet_id = tencentcloud_subnet.app.id
64+
count = 2
6765
6866
data_disks {
6967
data_disk_type = "CLOUD_PREMIUM"

0 commit comments

Comments
 (0)