Skip to content

Commit a28efe7

Browse files
authored
add action timeout (#1124)
1 parent 46ab1c3 commit a28efe7

File tree

2 files changed

+90
-19
lines changed

2 files changed

+90
-19
lines changed

tencentcloud/resource_tc_instance_set.go

Lines changed: 82 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,13 @@ resource "tencentcloud_subnet" "app" {
4343
4444
// Create 10 CVM instances to host awesome_app
4545
resource "tencentcloud_instance_set" "my_awesome_app" {
46+
timeouts {
47+
create = "5m"
48+
read = "20s"
49+
delete = "1h"
50+
}
51+
52+
instance_count = 10
4653
instance_name = "awesome_app"
4754
availability_zone = data.tencentcloud_availability_zones.my_favorite_zones.zones.0.name
4855
image_id = data.tencentcloud_images.my_favorite_image.images.0.image_id
@@ -53,7 +60,6 @@ resource "tencentcloud_instance_set" "my_awesome_app" {
5360
project_id = 0
5461
vpc_id = tencentcloud_vpc.app.id
5562
subnet_id = tencentcloud_subnet.app.id
56-
instance_count = 10
5763
}
5864
```
5965
@@ -82,11 +88,17 @@ func resourceTencentCloudInstanceSet() *schema.Resource {
8288
Read: resourceTencentCloudInstanceSetRead,
8389
Update: resourceTencentCloudInstanceSetUpdate,
8490
Delete: resourceTencentCloudInstanceSetDelete,
91+
Timeouts: &schema.ResourceTimeout{
92+
Create: schema.DefaultTimeout(600 * time.Second),
93+
Read: schema.DefaultTimeout(600 * time.Second),
94+
Delete: schema.DefaultTimeout(600 * time.Second),
95+
},
8596

8697
Schema: map[string]*schema.Schema{
8798
"image_id": {
8899
Type: schema.TypeString,
89100
Required: true,
101+
ForceNew: true,
90102
Description: "The image to use for the instance. Changing `image_id` will cause the instance reset.",
91103
},
92104
"availability_zone": {
@@ -139,12 +151,6 @@ func resourceTencentCloudInstanceSet() *schema.Resource {
139151
ValidateFunc: validateAllowedStringValue(CVM_CHARGE_TYPE),
140152
Description: "The charge type of instance. Only support `POSTPAID_BY_HOUR`.",
141153
},
142-
"instance_charge_type_prepaid_period": {
143-
Type: schema.TypeInt,
144-
Optional: true,
145-
ValidateFunc: validateAllowedIntValue(CVM_PREPAID_PERIOD),
146-
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`.",
147-
},
148154
// network
149155
"internet_charge_type": {
150156
Type: schema.TypeString,
@@ -315,6 +321,72 @@ func resourceTencentCloudInstanceSet() *schema.Resource {
315321
}
316322

317323
func resourceTencentCloudInstanceSetCreate(d *schema.ResourceData, meta interface{}) error {
324+
doneChan := make(chan struct{}, 1)
325+
rspChan := make(chan error, 1)
326+
327+
timeout := d.Timeout(schema.TimeoutCreate)
328+
329+
go func(d *schema.ResourceData, meta interface{}) {
330+
e := doResourceTencentCloudInstanceSetCreate(d, meta)
331+
doneChan <- struct{}{}
332+
rspChan <- e
333+
}(d, meta)
334+
335+
select {
336+
case <-doneChan:
337+
return <-rspChan
338+
case <-time.After(timeout):
339+
return fmt.Errorf("Do cvm instance set create action timeout, current timeout :[%.3f]s", timeout.Seconds())
340+
}
341+
}
342+
343+
func resourceTencentCloudInstanceSetRead(d *schema.ResourceData, meta interface{}) error {
344+
doneChan := make(chan struct{}, 1)
345+
rspChan := make(chan error, 1)
346+
347+
timeout := d.Timeout(schema.TimeoutRead)
348+
349+
go func(d *schema.ResourceData, meta interface{}) {
350+
e := doResourceTencentCloudInstanceSetRead(d, meta)
351+
doneChan <- struct{}{}
352+
rspChan <- e
353+
}(d, meta)
354+
355+
select {
356+
case <-doneChan:
357+
return <-rspChan
358+
case <-time.After(timeout):
359+
return fmt.Errorf("Do cvm instance set read action timeout, current timeout :[%.3f]s", timeout.Seconds())
360+
}
361+
}
362+
363+
func resourceTencentCloudInstanceSetUpdate(d *schema.ResourceData, meta interface{}) (err error) {
364+
defer logElapsed("resource.tencentcloud_instance_set.update")()
365+
366+
return fmt.Errorf("`resource_instance_set` do not support change now.")
367+
}
368+
369+
func resourceTencentCloudInstanceSetDelete(d *schema.ResourceData, meta interface{}) error {
370+
doneChan := make(chan struct{}, 1)
371+
rspChan := make(chan error, 1)
372+
373+
timeout := d.Timeout(schema.TimeoutDelete)
374+
375+
go func(d *schema.ResourceData, meta interface{}) {
376+
e := doResourceTencentCloudInstanceSetDelete(d, meta)
377+
doneChan <- struct{}{}
378+
rspChan <- e
379+
}(d, meta)
380+
381+
select {
382+
case <-doneChan:
383+
return <-rspChan
384+
case <-time.After(timeout):
385+
return fmt.Errorf("Do cvm instance set delete action timeout, current timeout :[%.3f]s", timeout.Seconds())
386+
}
387+
}
388+
389+
func doResourceTencentCloudInstanceSetCreate(d *schema.ResourceData, meta interface{}) error {
318390
defer logElapsed("resource.tencentcloud_instance_set.create")()
319391
logId := getLogId(contextNil)
320392

@@ -473,13 +545,13 @@ func resourceTencentCloudInstanceSetCreate(d *schema.ResourceData, meta interfac
473545
return err
474546
}
475547

476-
d.Set("instance_ids", instanceIds)
548+
_ = d.Set("instance_ids", instanceIds)
477549
d.SetId(helper.StrListToStr(instanceIds))
478550

479551
return nil
480552
}
481553

482-
func resourceTencentCloudInstanceSetRead(d *schema.ResourceData, meta interface{}) error {
554+
func doResourceTencentCloudInstanceSetRead(d *schema.ResourceData, meta interface{}) error {
483555
defer logElapsed("resource.tencentcloud_instance_set.read")()
484556
defer inconsistentCheck(d, meta)()
485557

@@ -547,13 +619,7 @@ func resourceTencentCloudInstanceSetRead(d *schema.ResourceData, meta interface{
547619
return nil
548620
}
549621

550-
func resourceTencentCloudInstanceSetUpdate(d *schema.ResourceData, meta interface{}) (err error) {
551-
defer logElapsed("resource.tencentcloud_instance_set.update")()
552-
553-
return fmt.Errorf("`resource_instance_set` do not support change now.")
554-
}
555-
556-
func resourceTencentCloudInstanceSetDelete(d *schema.ResourceData, meta interface{}) error {
622+
func doResourceTencentCloudInstanceSetDelete(d *schema.ResourceData, meta interface{}) error {
557623
defer logElapsed("resource.tencentcloud_instance_set.delete")()
558624

559625
logId := getLogId(contextNil)

website/docs/r/instance_set.html.markdown

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,13 @@ resource "tencentcloud_subnet" "app" {
5353
5454
// Create 10 CVM instances to host awesome_app
5555
resource "tencentcloud_instance_set" "my_awesome_app" {
56+
timeouts {
57+
create = "5m"
58+
read = "20s"
59+
delete = "1h"
60+
}
61+
62+
instance_count = 10
5663
instance_name = "awesome_app"
5764
availability_zone = data.tencentcloud_availability_zones.my_favorite_zones.zones.0.name
5865
image_id = data.tencentcloud_images.my_favorite_image.images.0.image_id
@@ -63,7 +70,6 @@ resource "tencentcloud_instance_set" "my_awesome_app" {
6370
project_id = 0
6471
vpc_id = tencentcloud_vpc.app.id
6572
subnet_id = tencentcloud_subnet.app.id
66-
instance_count = 10
6773
}
6874
```
6975

@@ -72,14 +78,13 @@ resource "tencentcloud_instance_set" "my_awesome_app" {
7278
The following arguments are supported:
7379

7480
* `availability_zone` - (Required, ForceNew) The available zone for the CVM instance.
75-
* `image_id` - (Required) The image to use for the instance. Changing `image_id` will cause the instance reset.
81+
* `image_id` - (Required, ForceNew) The image to use for the instance. Changing `image_id` will cause the instance reset.
7682
* `allocate_public_ip` - (Optional, ForceNew) Associate a public IP address with an instance in a VPC or Classic. Boolean value, Default is false.
7783
* `bandwidth_package_id` - (Optional) bandwidth package id. if user is standard user, then the bandwidth_package_id is needed, or default has bandwidth_package_id.
7884
* `cam_role_name` - (Optional, ForceNew) CAM role name authorized to access.
7985
* `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.
8086
* `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.
8187
* `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.
82-
* `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`.
8388
* `instance_charge_type` - (Optional) The charge type of instance. Only support `POSTPAID_BY_HOUR`.
8489
* `instance_count` - (Optional) The number of instances to be purchased. Value range:[1,100]; default value: 1.
8590
* `instance_name` - (Optional) The name of the instance. The max length of instance_name is 60, and default value is `Terraform-CVM-Instance`.

0 commit comments

Comments
 (0)