Skip to content

Commit bbc4fa7

Browse files
authored
add attribute to resource (#158)
1 parent 8c20676 commit bbc4fa7

File tree

7 files changed

+71
-52
lines changed

7 files changed

+71
-52
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## 1.38.2 (2023-09-27)
2+
3+
FEATURES:
4+
5+
* add `reboot_instance_for_resizing` attribute to `ucloud_disk` resource
6+
17
## 1.38.1 (2023-09-03)
28

39
FEATURES:

examples/rssd/main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ terraform {
22
required_providers {
33
ucloud = {
44
source = "ucloud/ucloud"
5-
version = "~>1.38.1"
5+
version = "~>1.38.2"
66
}
77
}
88
}

ucloud/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ func (c *Config) Client() (*UCloudClient, error) {
7272
// enable auto retry with http/connection error
7373
cfg.MaxRetries = c.MaxRetries
7474
cfg.LogLevel = log.PanicLevel
75-
cfg.UserAgent = "Terraform-UCloud/1.38.1"
75+
cfg.UserAgent = "Terraform-UCloud/1.38.2"
7676
cfg.BaseUrl = c.BaseURL
7777

7878
cred := auth.NewCredential()

ucloud/resource_ucloud_disk.go

Lines changed: 57 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,12 @@ func resourceUCloudDisk() *schema.Resource {
8585
StateFunc: stateFuncTag,
8686
},
8787

88+
"reboot_instance_for_resizing": {
89+
Type: schema.TypeBool,
90+
Optional: true,
91+
Default: true,
92+
},
93+
8894
"create_time": {
8995
Type: schema.TypeString,
9096
Computed: true,
@@ -199,33 +205,38 @@ func resourceUCloudDiskUpdate(d *schema.ResourceData, meta interface{}) error {
199205
}
200206
return fmt.Errorf("error on reading disk %q, %s", d.Id(), err)
201207
}
202-
208+
allowRebootInstance := false
209+
if reboot, ok := d.Get("reboot_instance_for_resizing").(bool); reboot || !ok {
210+
allowRebootInstance = true
211+
}
203212
if diskSet.UHostId != "" {
204213
uhostId := diskSet.UHostId
205214
instance, err := client.describeInstanceById(uhostId)
206215
if err != nil {
207216
return fmt.Errorf("error on reading instance %q when updating the size of disk %q, %s", uhostId, d.Id(), err)
208217
}
209-
if instance.State != statusStopped {
210-
stopReq := uhostConn.NewStopUHostInstanceRequest()
211-
stopReq.UHostId = ucloud.String(uhostId)
212-
_, err := uhostConn.StopUHostInstance(stopReq)
213-
if err != nil {
214-
return fmt.Errorf("error on stopping instance %q when updating the size of disk %q, %s", uhostId, d.Id(), err)
215-
}
216-
217-
// after stop instance, we need to wait it stopped
218-
stateConf := &resource.StateChangeConf{
219-
Pending: []string{statusPending},
220-
Target: []string{statusStopped},
221-
Refresh: instanceStateRefreshFunc(client, uhostId, statusStopped),
222-
Timeout: 15 * time.Minute,
223-
Delay: 3 * time.Second,
224-
MinTimeout: 2 * time.Second,
225-
}
226-
227-
if _, err = stateConf.WaitForState(); err != nil {
228-
return fmt.Errorf("error on waiting for stopping instance %q when updating the size of disk %q, %s", uhostId, d.Id(), err)
218+
if allowRebootInstance {
219+
if instance.State != statusStopped {
220+
stopReq := uhostConn.NewStopUHostInstanceRequest()
221+
stopReq.UHostId = ucloud.String(uhostId)
222+
_, err := uhostConn.StopUHostInstance(stopReq)
223+
if err != nil {
224+
return fmt.Errorf("error on stopping instance %q when updating the size of disk %q, %s", uhostId, d.Id(), err)
225+
}
226+
227+
// after stop instance, we need to wait it stopped
228+
stateConf := &resource.StateChangeConf{
229+
Pending: []string{statusPending},
230+
Target: []string{statusStopped},
231+
Refresh: instanceStateRefreshFunc(client, uhostId, statusStopped),
232+
Timeout: 15 * time.Minute,
233+
Delay: 3 * time.Second,
234+
MinTimeout: 2 * time.Second,
235+
}
236+
237+
if _, err = stateConf.WaitForState(); err != nil {
238+
return fmt.Errorf("error on waiting for stopping instance %q when updating the size of disk %q, %s", uhostId, d.Id(), err)
239+
}
229240
}
230241
}
231242

@@ -250,31 +261,32 @@ func resourceUCloudDiskUpdate(d *schema.ResourceData, meta interface{}) error {
250261
if err != nil {
251262
return fmt.Errorf("error on reading instance %q c %q, %s", uhostId, d.Id(), err)
252263
}
253-
254-
if instanceAfter.State != statusRunning {
255-
// after instance update, we need to wait it started
256-
startReq := uhostConn.NewStartUHostInstanceRequest()
257-
startReq.UHostId = ucloud.String(uhostId)
258-
259-
if _, err := uhostConn.StartUHostInstance(startReq); err != nil {
260-
return fmt.Errorf("error on starting instance %q after updating the size of disk %q, %s", uhostId, d.Id(), err)
261-
}
262-
263-
stateConf = &resource.StateChangeConf{
264-
Pending: []string{statusPending},
265-
Target: []string{statusRunning},
266-
Refresh: instanceStateRefreshFunc(client, uhostId, statusRunning),
267-
Timeout: 15 * time.Minute,
268-
Delay: 3 * time.Second,
269-
MinTimeout: 2 * time.Second,
270-
}
271-
272-
if _, err = stateConf.WaitForState(); err != nil {
273-
return fmt.Errorf("error on waiting for starting instance %q after updating the size of disk %q, %s", uhostId, d.Id(), err)
264+
if allowRebootInstance {
265+
if instanceAfter.State != statusRunning {
266+
// after instance update, we need to wait it started
267+
startReq := uhostConn.NewStartUHostInstanceRequest()
268+
startReq.UHostId = ucloud.String(uhostId)
269+
270+
if _, err := uhostConn.StartUHostInstance(startReq); err != nil {
271+
return fmt.Errorf("error on starting instance %q after updating the size of disk %q, %s", uhostId, d.Id(), err)
272+
}
273+
274+
stateConf = &resource.StateChangeConf{
275+
Pending: []string{statusPending},
276+
Target: []string{statusRunning},
277+
Refresh: instanceStateRefreshFunc(client, uhostId, statusRunning),
278+
Timeout: 15 * time.Minute,
279+
Delay: 3 * time.Second,
280+
MinTimeout: 2 * time.Second,
281+
}
282+
283+
if _, err = stateConf.WaitForState(); err != nil {
284+
return fmt.Errorf("error on waiting for starting instance %q after updating the size of disk %q, %s", uhostId, d.Id(), err)
285+
}
286+
287+
// Executing DetachUDisk immediately after starting up the instance will cause an error, this sleep to avoid this error
288+
time.Sleep(3 * time.Second)
274289
}
275-
276-
// Executing DetachUDisk immediately after starting up the instance will cause an error, this sleep to avoid this error
277-
time.Sleep(3 * time.Second)
278290
}
279291
} else {
280292
req := conn.NewResizeUDiskRequest()

website/docs/index.html.markdown

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ terraform {
2323
required_providers {
2424
ucloud = {
2525
source = "ucloud/ucloud"
26-
version = "~>1.38.1"
26+
version = "~>1.38.2"
2727
}
2828
}
2929
}
@@ -91,7 +91,7 @@ terraform {
9191
required_providers {
9292
ucloud = {
9393
source = "ucloud/ucloud"
94-
version = "~>1.38.1"
94+
version = "~>1.38.2"
9595
}
9696
}
9797
}

website/docs/r/disk.html.markdown

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ description: |-
1010

1111
Provides a Cloud Disk resource.
1212

13-
~> **Note** If the disk have attached to the instance, the instance will reboot automatically to make the change take effect when update the `disk_size`.
13+
~> **Note** If the disk have attached to the instance and reboot_instance_for_resizing is not set to false, the instance will reboot automatically to make the change take effect when update the `disk_size` by default.
1414

1515
## Example Usage
1616

@@ -35,11 +35,12 @@ The following arguments are supported:
3535

3636
- - -
3737

38-
* `name` - (Optional) The name of disk, should have 6-63 characters and only support Chinese, English, numbers, '-', '_'. If not specified, terraform will auto-generate a name beginning with `tf-disk`.
38+
* `name` - (Optional) The name of disk, should have 6-63 characters and only support Chinese, English, numbers, '-', '_'. If not specified, terraform will auto-generate a name beginning with `tf-disk`.
3939
* `disk_type` - (Optional, ForceNew) The type of disk. Possible values are: `data_disk`as cloud disk, `ssd_data_disk` as ssd cloud disk, `rssd_data_disk` as RDMA-SSD cloud disk.(Default: `data_disk`).
4040
* `charge_type` - (Optional, ForceNew) Charge type of disk. Possible values are: `year` as pay by year, `month` as pay by month, `dynamic` as pay by hour. (Default: `month`).
4141
* `duration` - (Optional, ForceNew) The duration that you will buy the resource. (Default: `1`). It is not required when `dynamic` (pay by hour), the value is `0` when `month`(pay by month) and the disk will be vaild till the last day of that month.
4242
* `tag` - (Optional, ForceNew) A tag assigned to VPC, which contains at most 63 characters and only support Chinese, English, numbers, '-', '_', and '.'. If it is not filled in or a empty string is filled in, then default tag will be assigned. (Default: `Default`).
43+
* `reboot_instance_for_resizing` - (Optional) Whether the attached instance of the disk will be rebooted automatically to make the change take effect when update the `disk_size`. (Default: `"true"`).
4344

4445
## Attributes Reference
4546

website/docs/r/lb.html.markdown

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ resource "ucloud_lb" "web" {
2323

2424
The following arguments are supported:
2525

26-
* `internal` - (Optional, ForceNew) Indicate whether the load balancer is intranet mode.(Default: `"false"`)
26+
* `internal` - (Optional, ForceNew) Indicate whether the load balancer is intranet mode. (Default: `"false"`)
2727
* `name` - (Optional) The name of the load balancer. If not specified, terraform will auto-generate a name beginning with `tf-lb`.
2828
* `charge_type` - (**Deprecated**, ForceNew), argument `charge_type` is deprecated for optimizing parameters.
2929
* `vpc_id` - (Optional, ForceNew) The ID of the VPC linked to the Load balancer, This argument is not required if default VPC.

0 commit comments

Comments
 (0)