Skip to content

Commit c0f6436

Browse files
tongyimingmikatong
andauthored
[fix]supprt cvm import params (#773)
Co-authored-by: mikatong <mikatong@tencent.com>
1 parent c71ac57 commit c0f6436

File tree

3 files changed

+46
-12
lines changed

3 files changed

+46
-12
lines changed

tencentcloud/extension_cvm.go

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

3+
import (
4+
"time"
5+
)
6+
37
const (
48
CVM_CHARGE_TYPE_PREPAID = "PREPAID"
59
CVM_CHARGE_TYPE_POSTPAID = "POSTPAID_BY_HOUR"
@@ -99,3 +103,23 @@ var CVM_PLACEMENT_GROUP_TYPE = []string{
99103
var CVM_SPOT_INSTANCE_TYPE = []string{
100104
CVM_SPOT_INSTANCE_TYPE_ONE_TIME,
101105
}
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: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -241,14 +241,14 @@ func resourceTencentCloudInstance() *schema.Resource {
241241
Type: schema.TypeInt,
242242
Optional: true,
243243
ValidateFunc: validateAllowedIntValue(CVM_PREPAID_PERIOD),
244-
Description: "The tenancy (time unit is month) of the prepaid instance, NOTE: it only works when instance_charge_type is set to `PREPAID`. Valid values are `1`, `2`, `3`, `4`, `5`, `6`, `7`, `8`, `9`, `10`, `11`, `12`, `24`, `36`. Modifying will cause the instance reset.",
244+
Description: "The tenancy (time unit is month) of the prepaid instance, NOTE: it only works when instance_charge_type is set to `PREPAID`. Valid values are `1`, `2`, `3`, `4`, `5`, `6`, `7`, `8`, `9`, `10`, `11`, `12`, `24`, `36`.",
245245
},
246246
"instance_charge_type_prepaid_renew_flag": {
247247
Type: schema.TypeString,
248248
Optional: true,
249249
Computed: true,
250250
ValidateFunc: validateAllowedStringValue(CVM_PREPAID_RENEW_FLAG),
251-
Description: "Auto renewal flag. Valid values: `NOTIFY_AND_AUTO_RENEW`: notify upon expiration and renew automatically, `NOTIFY_AND_MANUAL_RENEW`: notify upon expiration but do not renew automatically, `DISABLE_NOTIFY_AND_MANUAL_RENEW`: neither notify upon expiration nor renew automatically. Default value: `NOTIFY_AND_MANUAL_RENEW`. If this parameter is specified as `NOTIFY_AND_AUTO_RENEW`, the instance will be automatically renewed on a monthly basis if the account balance is sufficient. NOTE: it only works when instance_charge_type is set to `PREPAID`. Modifying will cause the instance reset.",
251+
Description: "Auto renewal flag. Valid values: `NOTIFY_AND_AUTO_RENEW`: notify upon expiration and renew automatically, `NOTIFY_AND_MANUAL_RENEW`: notify upon expiration but do not renew automatically, `DISABLE_NOTIFY_AND_MANUAL_RENEW`: neither notify upon expiration nor renew automatically. Default value: `NOTIFY_AND_MANUAL_RENEW`. If this parameter is specified as `NOTIFY_AND_AUTO_RENEW`, the instance will be automatically renewed on a monthly basis if the account balance is sufficient. NOTE: it only works when instance_charge_type is set to `PREPAID`.",
252252
},
253253
"spot_instance_type": {
254254
Type: schema.TypeString,
@@ -414,26 +414,26 @@ func resourceTencentCloudInstance() *schema.Resource {
414414
Type: schema.TypeBool,
415415
Optional: true,
416416
Default: false,
417-
Description: "Disable enhance service for security, it is enabled by default. When this options is set, security agent won't be installed.",
417+
Description: "Disable enhance service for security, it is enabled by default. When this options is set, security agent won't be installed. Modifying will cause the instance reset.",
418418
},
419419
"disable_monitor_service": {
420420
Type: schema.TypeBool,
421421
Optional: true,
422422
Default: false,
423-
Description: "Disable enhance service for monitor, it is enabled by default. When this options is set, monitor agent won't be installed.",
423+
Description: "Disable enhance service for monitor, it is enabled by default. When this options is set, monitor agent won't be installed. Modifying will cause the instance reset.",
424424
},
425425
// login
426426
"key_name": {
427427
Type: schema.TypeString,
428428
Optional: true,
429429
Computed: true,
430-
Description: "The key pair to use for the instance, it looks like `skey-16jig7tx`.",
430+
Description: "The key pair to use for the instance, it looks like `skey-16jig7tx`. Modifying will cause the instance reset.",
431431
},
432432
"password": {
433433
Type: schema.TypeString,
434434
Optional: true,
435435
Sensitive: true,
436-
Description: "Password for the instance. In order for the new password to take effect, the instance will be restarted after the password change.",
436+
Description: "Password for the instance. In order for the new password to take effect, the instance will be restarted after the password change. Modifying will cause the instance reset.",
437437
},
438438
"keep_image_login": {
439439
Type: schema.TypeBool,
@@ -886,6 +886,16 @@ func resourceTencentCloudInstanceRead(d *schema.ResourceData, meta interface{})
886886
if d.Get("image_id").(string) == "" || !IsContains(cvmImages, *instance.ImageId) {
887887
_ = d.Set("image_id", instance.ImageId)
888888
}
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+
}
889899

890900
_ = d.Set("availability_zone", instance.Placement.Zone)
891901
_ = d.Set("instance_name", instance.InstanceName)

website/docs/r/instance.html.markdown

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -149,21 +149,21 @@ The following arguments are supported:
149149
* `cdh_host_id` - (Optional, ForceNew) Id of cdh instance. Note: it only works when instance_charge_type is set to `CDHPAID`.
150150
* `cdh_instance_type` - (Optional) Type of instance created on cdh, the value of this parameter is in the format of CDH_XCXG based on the number of CPU cores and memory capacity. Note: it only works when instance_charge_type is set to `CDHPAID`.
151151
* `data_disks` - (Optional, ForceNew) Settings for data disks.
152-
* `disable_monitor_service` - (Optional) Disable enhance service for monitor, it is enabled by default. When this options is set, monitor agent won't be installed.
153-
* `disable_security_service` - (Optional) Disable enhance service for security, it is enabled by default. When this options is set, security agent won't be installed.
152+
* `disable_monitor_service` - (Optional) Disable enhance service for monitor, it is enabled by default. When this options is set, monitor agent won't be installed. Modifying will cause the instance reset.
153+
* `disable_security_service` - (Optional) Disable enhance service for security, it is enabled by default. When this options is set, security agent won't be installed. Modifying will cause the instance reset.
154154
* `force_delete` - (Optional) Indicate whether to force delete the instance. Default is `false`. If set true, the instance will be permanently deleted instead of being moved into the recycle bin. Note: only works for `PREPAID` instance.
155155
* `hostname` - (Optional) The hostname of the instance. Windows instance: The name should be a combination of 2 to 15 characters comprised of letters (case insensitive), numbers, and hyphens (-). Period (.) is not supported, and the name cannot be a string of pure numbers. Other types (such as Linux) of instances: The name should be a combination of 2 to 60 characters, supporting multiple periods (.). The piece between two periods is composed of letters (case insensitive), numbers, and hyphens (-). Modifying will cause the instance reset.
156-
* `instance_charge_type_prepaid_period` - (Optional) The tenancy (time unit is month) of the prepaid instance, NOTE: it only works when instance_charge_type is set to `PREPAID`. Valid values are `1`, `2`, `3`, `4`, `5`, `6`, `7`, `8`, `9`, `10`, `11`, `12`, `24`, `36`. Modifying will cause the instance reset.
157-
* `instance_charge_type_prepaid_renew_flag` - (Optional) Auto renewal flag. Valid values: `NOTIFY_AND_AUTO_RENEW`: notify upon expiration and renew automatically, `NOTIFY_AND_MANUAL_RENEW`: notify upon expiration but do not renew automatically, `DISABLE_NOTIFY_AND_MANUAL_RENEW`: neither notify upon expiration nor renew automatically. Default value: `NOTIFY_AND_MANUAL_RENEW`. If this parameter is specified as `NOTIFY_AND_AUTO_RENEW`, the instance will be automatically renewed on a monthly basis if the account balance is sufficient. NOTE: it only works when instance_charge_type is set to `PREPAID`. Modifying will cause the instance reset.
156+
* `instance_charge_type_prepaid_period` - (Optional) The tenancy (time unit is month) of the prepaid instance, NOTE: it only works when instance_charge_type is set to `PREPAID`. Valid values are `1`, `2`, `3`, `4`, `5`, `6`, `7`, `8`, `9`, `10`, `11`, `12`, `24`, `36`.
157+
* `instance_charge_type_prepaid_renew_flag` - (Optional) Auto renewal flag. Valid values: `NOTIFY_AND_AUTO_RENEW`: notify upon expiration and renew automatically, `NOTIFY_AND_MANUAL_RENEW`: notify upon expiration but do not renew automatically, `DISABLE_NOTIFY_AND_MANUAL_RENEW`: neither notify upon expiration nor renew automatically. Default value: `NOTIFY_AND_MANUAL_RENEW`. If this parameter is specified as `NOTIFY_AND_AUTO_RENEW`, the instance will be automatically renewed on a monthly basis if the account balance is sufficient. NOTE: it only works when instance_charge_type is set to `PREPAID`.
158158
* `instance_charge_type` - (Optional, ForceNew) The charge type of instance. Valid values are `PREPAID`, `POSTPAID_BY_HOUR`, `SPOTPAID` and `CDHPAID`. The default is `POSTPAID_BY_HOUR`. Note: TencentCloud International only supports `POSTPAID_BY_HOUR` and `CDHPAID`. `PREPAID` instance may not allow to delete before expired. `SPOTPAID` instance must set `spot_instance_type` and `spot_max_price` at the same time. `CDHPAID` instance must set `cdh_instance_type` and `cdh_host_id`.
159159
* `instance_count` - (Optional, **Deprecated**) It has been deprecated from version 1.59.18. Use built-in `count` instead. The number of instances to be purchased. Value range:[1,100]; default value: 1.
160160
* `instance_name` - (Optional) The name of the instance. The max length of instance_name is 60, and default value is `Terraform-CVM-Instance`.
161161
* `instance_type` - (Optional) The type of the instance.
162162
* `internet_charge_type` - (Optional, ForceNew) Internet charge type of the instance, Valid values are `BANDWIDTH_PREPAID`, `TRAFFIC_POSTPAID_BY_HOUR`, `BANDWIDTH_POSTPAID_BY_HOUR` and `BANDWIDTH_PACKAGE`. This value does not need to be set when `allocate_public_ip` is false.
163163
* `internet_max_bandwidth_out` - (Optional) Maximum outgoing bandwidth to the public network, measured in Mbps (Mega bits per second). This value does not need to be set when `allocate_public_ip` is false.
164164
* `keep_image_login` - (Optional) Whether to keep image login or not, default is `false`. When the image type is private or shared or imported, this parameter can be set `true`. Modifying will cause the instance reset.
165-
* `key_name` - (Optional) The key pair to use for the instance, it looks like `skey-16jig7tx`.
166-
* `password` - (Optional) Password for the instance. In order for the new password to take effect, the instance will be restarted after the password change.
165+
* `key_name` - (Optional) The key pair to use for the instance, it looks like `skey-16jig7tx`. Modifying will cause the instance reset.
166+
* `password` - (Optional) Password for the instance. In order for the new password to take effect, the instance will be restarted after the password change. Modifying will cause the instance reset.
167167
* `placement_group_id` - (Optional, ForceNew) The ID of a placement group.
168168
* `private_ip` - (Optional) The private IP to be assigned to this instance, must be in the provided subnet and available.
169169
* `project_id` - (Optional) The project the instance belongs to, default to 0.

0 commit comments

Comments
 (0)