Skip to content

Commit b3c01af

Browse files
authored
Merge pull request #11 from displague/feature/user-timeouts-for-linodes-images-volumes
add support for timeouts on instance, image, and volume resources
2 parents 41b36e7 + e5bab1a commit b3c01af

File tree

8 files changed

+69
-11
lines changed

8 files changed

+69
-11
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
11
## 1.2.1 (Unreleased)
2+
3+
ENHANCEMENTS:
4+
5+
* resource/linode\_instance: Add `timeouts` support for `create`, `update`, and `delete` (defaults 10, 20, 10)
6+
* resource/linode\_image: Add `timeouts` support for `create` (defaults 20)
7+
* resource/linode\_volume: Add `timeouts` support for `create`, `update`, and `delete` (defaults 10, 20, 10)
8+
29
## 1.2.0 (November 08, 2018)
310

411
ENHANCEMENTS:

linode/linode_instance_helpers.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,7 @@ func makeVolumeDetacher(client linodego.Client, d *schema.ResourceData) volumeDe
461461
}
462462

463463
log.Printf("[INFO] Waiting for Linode Volume %d to detach ...", volumeID)
464-
if _, err := client.WaitForVolumeLinodeID(ctx, volumeID, nil, int(d.Timeout("update").Seconds())); err != nil {
464+
if _, err := client.WaitForVolumeLinodeID(ctx, volumeID, nil, int(d.Timeout(schema.TimeoutUpdate).Seconds())); err != nil {
465465
return err
466466
}
467467
return nil

linode/resource_linode_image.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ import (
1010
"github.com/linode/linodego"
1111
)
1212

13+
const (
14+
LinodeImageCreateTimeout = 20 * time.Minute
15+
)
16+
1317
func resourceLinodeImage() *schema.Resource {
1418
return &schema.Resource{
1519
Create: resourceLinodeImageCreate,
@@ -20,6 +24,9 @@ func resourceLinodeImage() *schema.Resource {
2024
Importer: &schema.ResourceImporter{
2125
State: schema.ImportStatePassthrough,
2226
},
27+
Timeouts: &schema.ResourceTimeout{
28+
Create: schema.DefaultTimeout(LinodeImageCreateTimeout),
29+
},
2330
Schema: map[string]*schema.Schema{
2431
"label": {
2532
Type: schema.TypeString,
@@ -144,7 +151,7 @@ func resourceLinodeImageCreate(d *schema.ResourceData, meta interface{}) error {
144151
linodeID := d.Get("linode_id").(int)
145152
diskID := d.Get("disk_id").(int)
146153

147-
if _, err := client.WaitForInstanceDiskStatus(context.Background(), linodeID, diskID, linodego.DiskReady, int(d.Timeout("create").Seconds())); err != nil {
154+
if _, err := client.WaitForInstanceDiskStatus(context.Background(), linodeID, diskID, linodego.DiskReady, int(d.Timeout(schema.TimeoutCreate).Seconds())); err != nil {
148155
return fmt.Errorf("Error waiting for Linode Instance %d Disk %d to become ready for taking an Image", linodeID, diskID)
149156
}
150157

@@ -164,7 +171,7 @@ func resourceLinodeImageCreate(d *schema.ResourceData, meta interface{}) error {
164171
d.SetPartial("description")
165172
d.Partial(false)
166173

167-
if _, err := client.WaitForInstanceDiskStatus(context.Background(), linodeID, diskID, linodego.DiskReady, int(d.Timeout("create").Seconds())); err != nil {
174+
if _, err := client.WaitForInstanceDiskStatus(context.Background(), linodeID, diskID, linodego.DiskReady, int(d.Timeout(schema.TimeoutCreate).Seconds())); err != nil {
168175
return fmt.Errorf("Error waiting for Linode Instance %d Disk %d to become ready while taking an Image", linodeID, diskID)
169176
}
170177

linode/resource_linode_instance.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,27 @@ import (
1212
"github.com/linode/linodego"
1313
)
1414

15+
const (
16+
LinodeInstanceCreateTimeout = 10 * time.Minute
17+
LinodeInstanceUpdateTimeout = 20 * time.Minute
18+
LinodeInstanceDeleteTimeout = 10 * time.Minute
19+
)
20+
1521
func resourceLinodeInstance() *schema.Resource {
1622
return &schema.Resource{
1723
Create: resourceLinodeInstanceCreate,
1824
Read: resourceLinodeInstanceRead,
1925
Update: resourceLinodeInstanceUpdate,
2026
Delete: resourceLinodeInstanceDelete,
2127
Exists: resourceLinodeInstanceExists,
22-
2328
Importer: &schema.ResourceImporter{
2429
State: schema.ImportStatePassthrough,
2530
},
31+
Timeouts: &schema.ResourceTimeout{
32+
Create: schema.DefaultTimeout(LinodeInstanceCreateTimeout),
33+
Update: schema.DefaultTimeout(LinodeInstanceUpdateTimeout),
34+
Delete: schema.DefaultTimeout(LinodeInstanceDeleteTimeout),
35+
},
2636
Schema: map[string]*schema.Schema{
2737
"image": &schema.Schema{
2838
Type: schema.TypeString,

linode/resource_linode_volume.go

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,18 @@ import (
55
"fmt"
66
"log"
77
"strconv"
8+
"time"
89

910
"github.com/hashicorp/terraform/helper/schema"
1011
"github.com/linode/linodego"
1112
)
1213

14+
const (
15+
LinodeVolumeCreateTimeout = 10 * time.Minute
16+
LinodeVolumeUpdateTimeout = 20 * time.Minute
17+
LinodeVolumeDeleteTimeout = 10 * time.Minute
18+
)
19+
1320
func resourceLinodeVolume() *schema.Resource {
1421
return &schema.Resource{
1522
Create: resourceLinodeVolumeCreate,
@@ -20,6 +27,11 @@ func resourceLinodeVolume() *schema.Resource {
2027
Importer: &schema.ResourceImporter{
2128
State: schema.ImportStatePassthrough,
2229
},
30+
Timeouts: &schema.ResourceTimeout{
31+
Create: schema.DefaultTimeout(LinodeVolumeCreateTimeout),
32+
Update: schema.DefaultTimeout(LinodeVolumeUpdateTimeout),
33+
Delete: schema.DefaultTimeout(LinodeVolumeDeleteTimeout),
34+
},
2335
Schema: map[string]*schema.Schema{
2436
"label": &schema.Schema{
2537
Type: schema.TypeString,
@@ -137,13 +149,13 @@ func resourceLinodeVolumeCreate(d *schema.ResourceData, meta interface{}) error
137149
d.SetPartial("size")
138150

139151
if createOpts.LinodeID > 0 {
140-
if _, err := client.WaitForVolumeLinodeID(context.Background(), volume.ID, linodeID, int(d.Timeout("update").Seconds())); err != nil {
152+
if _, err := client.WaitForVolumeLinodeID(context.Background(), volume.ID, linodeID, int(d.Timeout(schema.TimeoutUpdate).Seconds())); err != nil {
141153
return err
142154
}
143155
d.SetPartial("linode_id")
144156
}
145157

146-
if _, err = client.WaitForVolumeStatus(context.Background(), volume.ID, linodego.VolumeActive, int(d.Timeout("create").Seconds())); err != nil {
158+
if _, err = client.WaitForVolumeStatus(context.Background(), volume.ID, linodego.VolumeActive, int(d.Timeout(schema.TimeoutCreate).Seconds())); err != nil {
147159
return err
148160
}
149161

@@ -172,7 +184,7 @@ func resourceLinodeVolumeUpdate(d *schema.ResourceData, meta interface{}) error
172184
return err
173185
}
174186

175-
if _, err = client.WaitForVolumeStatus(context.Background(), volume.ID, linodego.VolumeActive, int(d.Timeout("update").Seconds())); err != nil {
187+
if _, err = client.WaitForVolumeStatus(context.Background(), volume.ID, linodego.VolumeActive, int(d.Timeout(schema.TimeoutUpdate).Seconds())); err != nil {
176188
return err
177189
}
178190

@@ -206,7 +218,7 @@ func resourceLinodeVolumeUpdate(d *schema.ResourceData, meta interface{}) error
206218
}
207219

208220
log.Printf("[INFO] Waiting for Linode Volume %d to detach ...", volume.ID)
209-
if _, err = client.WaitForVolumeLinodeID(context.Background(), volume.ID, nil, int(d.Timeout("update").Seconds())); err != nil {
221+
if _, err = client.WaitForVolumeLinodeID(context.Background(), volume.ID, nil, int(d.Timeout(schema.TimeoutUpdate).Seconds())); err != nil {
210222
return err
211223
}
212224
}
@@ -224,7 +236,7 @@ func resourceLinodeVolumeUpdate(d *schema.ResourceData, meta interface{}) error
224236
}
225237

226238
log.Printf("[INFO] Waiting for Linode Volume %d to attach ...", volume.ID)
227-
if _, err = client.WaitForVolumeLinodeID(context.Background(), volume.ID, linodeID, int(d.Timeout("update").Seconds())); err != nil {
239+
if _, err = client.WaitForVolumeLinodeID(context.Background(), volume.ID, linodeID, int(d.Timeout(schema.TimeoutUpdate).Seconds())); err != nil {
228240
return err
229241
}
230242
}
@@ -252,7 +264,7 @@ func resourceLinodeVolumeDelete(d *schema.ResourceData, meta interface{}) error
252264
}
253265

254266
log.Printf("[INFO] Waiting for Linode Volume %d to detach ...", id)
255-
if _, err := client.WaitForVolumeLinodeID(context.Background(), id, nil, int(d.Timeout("update").Seconds())); err != nil {
267+
if _, err := client.WaitForVolumeLinodeID(context.Background(), id, nil, int(d.Timeout(schema.TimeoutUpdate).Seconds())); err != nil {
256268
return err
257269
}
258270

website/docs/r/image.html.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@ The following arguments are supported:
4444

4545
* `description` - (Optional) A detailed description of this Image.
4646

47+
### Timeouts
48+
49+
The `timeouts` block allows you to specify [timeouts](https://www.terraform.io/docs/configuration/resources.html#timeouts) for certain actions:
50+
51+
* `create` - (Defaults to 20 mins) Used when creating the instance image (until the instance is available)
52+
4753
## Attributes
4854

4955
This resource exports the following attributes:

website/docs/r/instance.html.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,14 @@ Configuration profiles define the VM settings and boot behavior of the Linode In
204204

205205
* `memory_limit` - (Optional) - Defaults to the total RAM of the Linode
206206

207+
### Timeouts
208+
209+
The `timeouts` block allows you to specify [timeouts](https://www.terraform.io/docs/configuration/resources.html#timeouts) for certain actions:
210+
211+
* `create` - (Defaults to 10 mins) Used when launching the instance (until it reaches the initial `running` state)
212+
* `update` - (Defaults to 20 mins) Used when stopping and starting the instance when necessary during update - e.g. when changing instance type
213+
* `delete` - (Defaults to 10 mins) Used when terminating the instance
214+
207215
## Attributes
208216

209217
This Linode Instance resource exports the following attributes:
@@ -248,4 +256,4 @@ When importing an instance, all `disk` and `config` values must be represented.
248256

249257
Imported disks must include their `label` value. **Any disk that is not precisely represented may be removed resulting in data loss.**
250258

251-
Imported configs should include all `devices`, and must include `label`, `kernel`, and the `root_device`. The instance must include a `boot_config_label` referring to the correct configuration profile.
259+
Imported configs should include all `devices`, and must include `label`, `kernel`, and the `root_device`. The instance must include a `boot_config_label` referring to the correct configuration profile.

website/docs/r/volume.html.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,14 @@ The following arguments are supported:
6060

6161
* `linode_id` - (Optional) The ID of a Linode Instance where the the Volume should be attached.
6262

63+
### Timeouts
64+
65+
The `timeouts` block allows you to specify [timeouts](https://www.terraform.io/docs/configuration/resources.html#timeouts) for certain actions:
66+
67+
* `create` - (Defaults to 10 mins) Used when creating the volume (until the volume is reaches the initial `active` state)
68+
* `update` - (Defaults to 20 mins) Used when updating the volume when necessary during update - e.g. when resizing the volume
69+
* `delete` - (Defaults to 10 mins) Used when deleting the volume
70+
6371
## Attributes
6472

6573
This resource exports the following attributes:

0 commit comments

Comments
 (0)