Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 94300a4

Browse files
fix(cvm): [128000341] tencentcloud_instance support stop_type (#3562)
* add * add
1 parent b4c2d8b commit 94300a4

File tree

6 files changed

+84
-3
lines changed

6 files changed

+84
-3
lines changed

‎.changelog/3562.txt‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
resource/tencentcloud_instance: support `stop_type`
3+
```

‎tencentcloud/services/cvm/extension_cvm.go‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ const (
6161
// @Deprecated use cvm.RESOURCEINSUFFICIENT_CLOUDDISKSOLDOUT instead
6262
CVM_CLOUD_DISK_SOLD_OUT_ERROR = "ResourceInsufficient.CloudDiskSoldOut"
6363

64+
CVM_STOP_TYPE_SOFT_FIRST = "SOFT_FIRST"
65+
CVM_STOP_TYPE_HARD = "HARD"
66+
CVM_STOP_TYPE_SOFT = "SOFT"
6467
CVM_STOP_MODE_KEEP_CHARGING = "KEEP_CHARGING"
6568
CVM_STOP_MODE_STOP_CHARGING = "STOP_CHARGING"
6669
CVM_SELL_STATUS = "SELL"

‎tencentcloud/services/cvm/resource_tc_instance.go‎

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,16 @@ func ResourceTencentCloudInstance() *schema.Resource {
9595
Computed: true,
9696
Description: "Set instance to running or stop. Default value is true, the instance will shutdown when this flag is false.",
9797
},
98+
"stop_type": {
99+
Type: schema.TypeString,
100+
Optional: true,
101+
Description: "Instance shutdown mode. Valid values: SOFT_FIRST: perform a soft shutdown first, and force shut down the instance if the soft shutdown fails; HARD: force shut down the instance directly; SOFT: soft shutdown only. Default value: SOFT.",
102+
ValidateFunc: tccommon.ValidateAllowedStringValue([]string{
103+
CVM_STOP_TYPE_SOFT_FIRST,
104+
CVM_STOP_TYPE_HARD,
105+
CVM_STOP_TYPE_SOFT,
106+
}),
107+
},
98108
"stopped_mode": {
99109
Type: schema.TypeString,
100110
Optional: true,
@@ -1086,8 +1096,9 @@ func resourceTencentCloudInstanceCreate(d *schema.ResourceData, meta interface{}
10861096

10871097
if v, ok := d.GetOkExists("running_flag"); ok {
10881098
if !v.(bool) {
1099+
stopType := d.Get("stop_type").(string)
10891100
stoppedMode := d.Get("stopped_mode").(string)
1090-
err = cvmService.StopInstance(ctx, instanceId, stoppedMode)
1101+
err = cvmService.StopInstance(ctx, instanceId, stopType, stoppedMode)
10911102
if err != nil {
10921103
return err
10931104
}
@@ -2784,12 +2795,13 @@ func switchInstance(cvmService *CvmService, ctx context.Context, d *schema.Resou
27842795
return err
27852796
}
27862797
} else {
2798+
stopType := d.Get("stop_type").(string)
27872799
stoppedMode := d.Get("stopped_mode").(string)
27882800
skipStopApi := false
27892801
err = resource.Retry(tccommon.WriteRetryTimeout, func() *resource.RetryError {
27902802
// when retry polling instance status, stop instance should skipped
27912803
if !skipStopApi {
2792-
err := cvmService.StopInstance(ctx, instanceId, stoppedMode)
2804+
err := cvmService.StopInstance(ctx, instanceId, stopType, stoppedMode)
27932805
if err != nil {
27942806
return resource.NonRetryableError(err)
27952807
}

‎tencentcloud/services/cvm/resource_tc_instance.md‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,35 @@ resource "tencentcloud_instance" "example" {
279279
}
280280
```
281281

282+
Create CVM instance with setting running flag
283+
284+
```hcl
285+
resource "tencentcloud_instance" "example" {
286+
instance_name = "tf-example"
287+
availability_zone = "ap-guangzhou-6"
288+
image_id = "img-eb30mz89"
289+
instance_type = "S5.MEDIUM4"
290+
system_disk_type = "CLOUD_HSSD"
291+
system_disk_size = 50
292+
hostname = "user"
293+
project_id = 0
294+
vpc_id = "vpc-i5yyodl9"
295+
subnet_id = "subnet-hhi88a58"
296+
orderly_security_groups = ["sg-ma82yjwp"]
297+
running_flag = false
298+
stop_type = "SOFT_FIRST"
299+
stopped_mode = "KEEP_CHARGING"
300+
data_disks {
301+
data_disk_type = "CLOUD_HSSD"
302+
data_disk_size = 100
303+
encrypt = false
304+
}
305+
tags = {
306+
tagKey = "tagValue"
307+
}
308+
}
309+
```
310+
282311
Import
283312

284313
CVM instance can be imported using the id, e.g.

‎tencentcloud/services/cvm/service_tencentcloud_cvm.go‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -436,10 +436,14 @@ func (me *CvmService) ModifyVpc(ctx context.Context, instanceId, vpcId, subnetId
436436
return nil
437437
}
438438

439-
func (me *CvmService) StopInstance(ctx context.Context, instanceId string, stoppedMode string) error {
439+
func (me *CvmService) StopInstance(ctx context.Context, instanceId string, stopTypestring, stoppedMode string) error {
440440
logId := tccommon.GetLogId(ctx)
441441
request := cvm.NewStopInstancesRequest()
442442
request.InstanceIds = []*string{&instanceId}
443+
if stopType != "" {
444+
request.StopType = &stopType
445+
}
446+
443447
if stoppedMode != "" {
444448
request.StoppedMode = &stoppedMode
445449
}

‎website/docs/r/instance.html.markdown‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,35 @@ resource "tencentcloud_instance" "example" {
290290
}
291291
```
292292

293+
### Create CVM instance with setting running flag
294+
295+
```hcl
296+
resource "tencentcloud_instance" "example" {
297+
instance_name = "tf-example"
298+
availability_zone = "ap-guangzhou-6"
299+
image_id = "img-eb30mz89"
300+
instance_type = "S5.MEDIUM4"
301+
system_disk_type = "CLOUD_HSSD"
302+
system_disk_size = 50
303+
hostname = "user"
304+
project_id = 0
305+
vpc_id = "vpc-i5yyodl9"
306+
subnet_id = "subnet-hhi88a58"
307+
orderly_security_groups = ["sg-ma82yjwp"]
308+
running_flag = false
309+
stop_type = "SOFT_FIRST"
310+
stopped_mode = "KEEP_CHARGING"
311+
data_disks {
312+
data_disk_type = "CLOUD_HSSD"
313+
data_disk_size = 100
314+
encrypt = false
315+
}
316+
tags = {
317+
tagKey = "tagValue"
318+
}
319+
}
320+
```
321+
293322
## Argument Reference
294323

295324
The following arguments are supported:
@@ -337,6 +366,7 @@ The following arguments are supported:
337366
* `security_groups` - (Optional, Set: [`String`], **Deprecated**) It will be deprecated. Use `orderly_security_groups` instead. A list of security group IDs to associate with.
338367
* `spot_instance_type` - (Optional, String) Type of spot instance, only support `ONE-TIME` now. Note: it only works when instance_charge_type is set to `SPOTPAID`.
339368
* `spot_max_price` - (Optional, String, ForceNew) Max price of a spot instance, is the format of decimal string, for example "0.50". Note: it only works when instance_charge_type is set to `SPOTPAID`.
369+
* `stop_type` - (Optional, String) Instance shutdown mode. Valid values: SOFT_FIRST: perform a soft shutdown first, and force shut down the instance if the soft shutdown fails; HARD: force shut down the instance directly; SOFT: soft shutdown only. Default value: SOFT.
340370
* `stopped_mode` - (Optional, String) Billing method of a pay-as-you-go instance after shutdown. Available values: `KEEP_CHARGING`,`STOP_CHARGING`. Default `KEEP_CHARGING`.
341371
* `subnet_id` - (Optional, String) The ID of a VPC subnet. If you want to create instances in a VPC network, this parameter must be set.
342372
* `system_disk_id` - (Optional, String) System disk snapshot ID used to initialize the system disk. When system disk type is `LOCAL_BASIC` and `LOCAL_SSD`, disk id is not supported.

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /