Skip to content

Commit 9430425

Browse files
authored
fix: cvm - internet charge forcenew ignore (#1193)
1 parent 7bd3c88 commit 9430425

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

tencentcloud/resource_tc_instance.go

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -273,12 +273,18 @@ func resourceTencentCloudInstance() *schema.Resource {
273273
},
274274
// network
275275
"internet_charge_type": {
276-
Type: schema.TypeString,
277-
Optional: true,
278-
Computed: true,
279-
ForceNew: true,
276+
Type: schema.TypeString,
277+
Optional: true,
278+
Computed: true,
279+
DiffSuppressFunc: func(k, old, new string, d *schema.ResourceData) bool {
280+
stopMode := d.Get("stopped_mode").(string)
281+
if stopMode != CVM_STOP_MODE_STOP_CHARGING || !d.HasChange("running_flag") {
282+
return old == new
283+
}
284+
return old == "" || new == ""
285+
},
280286
ValidateFunc: validateAllowedStringValue(CVM_INTERNET_CHARGE_TYPE),
281-
Description: "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.",
287+
Description: "Internet charge type of the instance, Valid values are `BANDWIDTH_PREPAID`, `TRAFFIC_POSTPAID_BY_HOUR`, `BANDWIDTH_POSTPAID_BY_HOUR` and `BANDWIDTH_PACKAGE`. This value takes NO Effect when changing and does not need to be set when `allocate_public_ip` is false.",
282288
},
283289
"bandwidth_package_id": {
284290
Type: schema.TypeString,
@@ -1414,11 +1420,12 @@ func resourceTencentCloudInstanceUpdate(d *schema.ResourceData, meta interface{}
14141420

14151421
if d.HasChange("internet_max_bandwidth_out") {
14161422
chargeType := d.Get("internet_charge_type").(string)
1423+
bandWidthOut := int64(d.Get("internet_max_bandwidth_out").(int))
14171424
if chargeType != "TRAFFIC_POSTPAID_BY_HOUR" && chargeType != "BANDWIDTH_POSTPAID_BY_HOUR" && chargeType != "BANDWIDTH_PACKAGE" {
14181425
return fmt.Errorf("charge type should be one of `TRAFFIC_POSTPAID_BY_HOUR BANDWIDTH_POSTPAID_BY_HOUR BANDWIDTH_PACKAGE` when adjusting internet_max_bandwidth_out")
14191426
}
14201427

1421-
err := cvmService.ModifyInternetMaxBandwidthOut(ctx, instanceId, chargeType, int64(d.Get("internet_max_bandwidth_out").(int)))
1428+
err := cvmService.ModifyInternetMaxBandwidthOut(ctx, instanceId, chargeType, bandWidthOut)
14221429
if err != nil {
14231430
return err
14241431
}

website/docs/r/instance.html.markdown

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ The following arguments are supported:
157157
* `instance_count` - (Optional, Int, **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.
158158
* `instance_name` - (Optional, String) The name of the instance. The max length of instance_name is 60, and default value is `Terraform-CVM-Instance`.
159159
* `instance_type` - (Optional, String) The type of the instance.
160-
* `internet_charge_type` - (Optional, String, 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.
160+
* `internet_charge_type` - (Optional, String) Internet charge type of the instance, Valid values are `BANDWIDTH_PREPAID`, `TRAFFIC_POSTPAID_BY_HOUR`, `BANDWIDTH_POSTPAID_BY_HOUR` and `BANDWIDTH_PACKAGE`. This value takes NO Effect when changing and does not need to be set when `allocate_public_ip` is false.
161161
* `internet_max_bandwidth_out` - (Optional, Int) 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.
162162
* `keep_image_login` - (Optional, Bool) 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.
163163
* `key_name` - (Optional, String) The key pair to use for the instance, it looks like `skey-16jig7tx`. Modifying will cause the instance reset.

0 commit comments

Comments
 (0)