Merge pull request #10081 from aditya87/google_compute_image_timeout

Added create timeout for compute images and instances
This commit is contained in:
Evan Brown 2016-11-17 12:56:02 -08:00 committed by GitHub
commit 3920460220
7 changed files with 42 additions and 3 deletions

View File

@ -83,6 +83,10 @@ func (e ComputeOperationError) Error() string {
}
func computeOperationWaitGlobal(config *Config, op *compute.Operation, project string, activity string) error {
return computeOperationWaitGlobalTime(config, op, project, activity, 4)
}
func computeOperationWaitGlobalTime(config *Config, op *compute.Operation, project string, activity string, timeoutMin int) error {
w := &ComputeOperationWaiter{
Service: config.clientCompute,
Op: op,
@ -92,7 +96,7 @@ func computeOperationWaitGlobal(config *Config, op *compute.Operation, project s
state := w.Conf()
state.Delay = 10 * time.Second
state.Timeout = 4 * time.Minute
state.Timeout = time.Duration(timeoutMin) * time.Minute
state.MinTimeout = 2 * time.Second
opRaw, err := state.WaitForState()
if err != nil {

View File

@ -78,6 +78,13 @@ func resourceComputeImage() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},
"create_timeout": &schema.Schema{
Type: schema.TypeInt,
Optional: true,
Default: 4,
ForceNew: true,
},
},
}
}
@ -122,6 +129,12 @@ func resourceComputeImageCreate(d *schema.ResourceData, meta interface{}) error
image.RawDisk = imageRawDisk
}
// Read create timeout
var createTimeout int
if v, ok := d.GetOk("create_timeout"); ok {
createTimeout = v.(int)
}
// Insert the image
op, err := config.clientCompute.Images.Insert(
project, image).Do()
@ -132,7 +145,7 @@ func resourceComputeImageCreate(d *schema.ResourceData, meta interface{}) error
// Store the ID
d.SetId(image.Name)
err = computeOperationWaitGlobal(config, op, project, "Creating Image")
err = computeOperationWaitGlobalTime(config, op, project, "Creating Image", createTimeout)
if err != nil {
return err
}

View File

@ -101,6 +101,7 @@ resource "google_compute_image" "foobar" {
raw_disk {
source = "https://storage.googleapis.com/bosh-cpi-artifacts/bosh-stemcell-3262.4-google-kvm-ubuntu-trusty-go_agent-raw.tar.gz"
}
create_timeout = 5
}`, acctest.RandString(10))
var testAccComputeImage_basedondisk = fmt.Sprintf(`

View File

@ -291,6 +291,13 @@ func resourceComputeInstance() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},
"create_timeout": &schema.Schema{
Type: schema.TypeInt,
Optional: true,
Default: 4,
ForceNew: true,
},
},
}
}
@ -564,6 +571,12 @@ func resourceComputeInstanceCreate(d *schema.ResourceData, meta interface{}) err
scheduling.OnHostMaintenance = val.(string)
}
// Read create timeout
var createTimeout int
if v, ok := d.GetOk("create_timeout"); ok {
createTimeout = v.(int)
}
metadata, err := resourceInstanceMetadata(d)
if err != nil {
return fmt.Errorf("Error creating metadata: %s", err)
@ -594,7 +607,7 @@ func resourceComputeInstanceCreate(d *schema.ResourceData, meta interface{}) err
d.SetId(instance.Name)
// Wait for the operation to complete
waitErr := computeOperationWaitZone(config, op, project, zone.Name, "instance to create")
waitErr := computeOperationWaitZoneTime(config, op, project, zone.Name, createTimeout, "instance to create")
if waitErr != nil {
// The resource didn't actually create
d.SetId("")

View File

@ -748,6 +748,8 @@ func testAccComputeInstance_basic(instance string) string {
baz = "qux"
}
create_timeout = 5
metadata_startup_script = "echo Hello"
}`, instance)
}

View File

@ -53,6 +53,9 @@ The following arguments are supported: (Note that one of either source_disk or
Changing this forces a new resource to be created. Structure is documented
below.
* `create_timeout` - Configurable timeout in minutes for creating images. Default is 4 minutes.
Changing this forces a new resource to be created.
The `raw_disk` block supports:
* `source` - (Required) The full Google Cloud Storage URL where the disk

View File

@ -105,6 +105,9 @@ The following arguments are supported:
* `tags` - (Optional) Tags to attach to the instance.
* `create_timeout` - (Optional) Configurable timeout in minutes for creating instances. Default is 4 minutes.
Changing this forces a new resource to be created.
The `disk` block supports: (Note that either disk or image is required, unless
the type is "local-ssd", in which case scratch must be true).