mirror of
https://github.com/letic/terraform-provider-google.git
synced 2024-07-03 08:42:39 +00:00
Add configurable timeouts for disks (#717)
* add configurable timeouts for disks * add test for disk timeout
This commit is contained in:
parent
b3a22d0a7e
commit
b5faecd585
|
@ -5,6 +5,7 @@ import (
|
|||
"log"
|
||||
"regexp"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/hashicorp/terraform/helper/schema"
|
||||
"google.golang.org/api/compute/v1"
|
||||
|
@ -29,6 +30,12 @@ func resourceComputeDisk() *schema.Resource {
|
|||
State: schema.ImportStatePassthrough,
|
||||
},
|
||||
|
||||
Timeouts: &schema.ResourceTimeout{
|
||||
Create: schema.DefaultTimeout(5 * time.Minute),
|
||||
Update: schema.DefaultTimeout(5 * time.Minute),
|
||||
Delete: schema.DefaultTimeout(5 * time.Minute),
|
||||
},
|
||||
|
||||
Schema: map[string]*schema.Schema{
|
||||
"name": &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
|
@ -199,7 +206,7 @@ func resourceComputeDiskCreate(d *schema.ResourceData, meta interface{}) error {
|
|||
// It probably maybe worked, so store the ID now
|
||||
d.SetId(disk.Name)
|
||||
|
||||
err = computeOperationWait(config.clientCompute, op, project, "Creating Disk")
|
||||
err = computeOperationWaitTime(config.clientCompute, op, project, "Creating Disk", int(d.Timeout(schema.TimeoutCreate).Minutes()))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -225,7 +232,7 @@ func resourceComputeDiskUpdate(d *schema.ResourceData, meta interface{}) error {
|
|||
}
|
||||
d.SetPartial("size")
|
||||
|
||||
err = computeOperationWait(config.clientCompute, op, project, "Resizing Disk")
|
||||
err = computeOperationWaitTime(config.clientCompute, op, project, "Resizing Disk", int(d.Timeout(schema.TimeoutUpdate).Minutes()))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -243,7 +250,7 @@ func resourceComputeDiskUpdate(d *schema.ResourceData, meta interface{}) error {
|
|||
}
|
||||
d.SetPartial("labels")
|
||||
|
||||
err = computeOperationWait(config.clientCompute, op, project, "Setting labels on disk")
|
||||
err = computeOperationWaitTime(config.clientCompute, op, project, "Setting labels on disk", int(d.Timeout(schema.TimeoutUpdate).Minutes()))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -378,7 +385,7 @@ func resourceComputeDiskDelete(d *schema.ResourceData, meta interface{}) error {
|
|||
return fmt.Errorf("Error deleting disk: %s", err)
|
||||
}
|
||||
|
||||
err = computeOperationWait(config.clientCompute, op, project, "Deleting Disk")
|
||||
err = computeOperationWaitTime(config.clientCompute, op, project, "Deleting Disk", int(d.Timeout(schema.TimeoutDelete).Minutes()))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ package google
|
|||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"testing"
|
||||
|
||||
|
@ -36,6 +37,21 @@ func TestAccComputeDisk_basic(t *testing.T) {
|
|||
})
|
||||
}
|
||||
|
||||
func TestAccComputeDisk_timeout(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
resource.Test(t, resource.TestCase{
|
||||
PreCheck: func() { testAccPreCheck(t) },
|
||||
Providers: testAccProviders,
|
||||
Steps: []resource.TestStep{
|
||||
resource.TestStep{
|
||||
Config: testAccComputeDisk_timeout,
|
||||
ExpectError: regexp.MustCompile("timeout"),
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TestAccComputeDisk_update(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
|
@ -298,6 +314,18 @@ resource "google_compute_disk" "foobar" {
|
|||
}`, diskName)
|
||||
}
|
||||
|
||||
var testAccComputeDisk_timeout = fmt.Sprintf(`
|
||||
resource "google_compute_disk" "foobar" {
|
||||
name = "%s"
|
||||
image = "debian-8-jessie-v20160803"
|
||||
type = "pd-ssd"
|
||||
zone = "us-central1-a"
|
||||
|
||||
timeouts {
|
||||
Create = "1s"
|
||||
}
|
||||
}`, acctest.RandString(10))
|
||||
|
||||
func testAccComputeDisk_updated(diskName string) string {
|
||||
return fmt.Sprintf(`
|
||||
resource "google_compute_disk" "foobar" {
|
||||
|
|
|
@ -78,6 +78,15 @@ exported:
|
|||
|
||||
* `label_fingerprint` - The fingerprint of the assigned labels.
|
||||
|
||||
## Timeouts
|
||||
|
||||
`google_compute_disk` provides the following
|
||||
[Timeouts](/docs/configuration/resources.html#timeouts) configuration options:
|
||||
|
||||
- `create` - (Default `5 minutes`) Used for creating disks.
|
||||
- `update` - (Default `5 minutes`) Used for resizing a disk and setting labels on disks.
|
||||
- `delete` - (Default `5 minutes`) Used for destroying disks (not including time to detach the disk from instances).
|
||||
|
||||
## Import
|
||||
|
||||
Disks can be imported using the `name`, e.g.
|
||||
|
|
Loading…
Reference in New Issue
Block a user