diff --git a/google/resource_compute_instance.go b/google/resource_compute_instance.go index f8f185c2625..f55fd741695 100644 --- a/google/resource_compute_instance.go +++ b/google/resource_compute_instance.go @@ -14,6 +14,7 @@ import ( computeBeta "google.golang.org/api/compute/v0.beta" "google.golang.org/api/compute/v1" "google.golang.org/api/googleapi" + "time" ) var InstanceBaseApiVersion = v1 @@ -29,6 +30,12 @@ func resourceComputeInstance() *schema.Resource { SchemaVersion: 6, MigrateState: resourceComputeInstanceMigrateState, + Timeouts: &schema.ResourceTimeout{ + Create: schema.DefaultTimeout(6 * time.Minute), + Update: schema.DefaultTimeout(6 * time.Minute), + Delete: schema.DefaultTimeout(6 * time.Minute), + }, + // A compute instance is more or less a superset of a compute instance // template. Please attempt to maintain consistency with the // resource_compute_instance_template schema when updating this one. @@ -534,9 +541,10 @@ func resourceComputeInstance() *schema.Resource { }, "create_timeout": &schema.Schema{ - Type: schema.TypeInt, - Optional: true, - Default: 4, + Type: schema.TypeInt, + Optional: true, + Default: 4, + Deprecated: "Use timeouts block instead.", }, }, } @@ -647,8 +655,9 @@ func resourceComputeInstanceCreate(d *schema.ResourceData, meta interface{}) err scheduling.ForceSendFields = []string{"AutomaticRestart", "Preemptible"} // Read create timeout - var createTimeout int - if v, ok := d.GetOk("create_timeout"); ok { + // Until "create_timeout" is removed, use that timeout if set. + createTimeout := int(d.Timeout(schema.TimeoutCreate).Minutes()) + if v, ok := d.GetOk("create_timeout"); ok && v != 4 { createTimeout = v.(int) } @@ -914,7 +923,7 @@ func resourceComputeInstanceUpdate(d *schema.ResourceData, meta interface{}) err return fmt.Errorf("Error updating metadata: %s", err) } - opErr := computeOperationWait(config.clientCompute, op, project, "metadata to update") + opErr := computeOperationWaitTime(config.clientCompute, op, project, "metadata to update", int(d.Timeout(schema.TimeoutUpdate).Minutes())) if opErr != nil { return opErr } @@ -938,7 +947,7 @@ func resourceComputeInstanceUpdate(d *schema.ResourceData, meta interface{}) err return fmt.Errorf("Error updating tags: %s", err) } - opErr := computeOperationWait(config.clientCompute, op, project, "tags to update") + opErr := computeOperationWaitTime(config.clientCompute, op, project, "tags to update", int(d.Timeout(schema.TimeoutUpdate).Minutes())) if opErr != nil { return opErr } @@ -956,7 +965,7 @@ func resourceComputeInstanceUpdate(d *schema.ResourceData, meta interface{}) err return fmt.Errorf("Error updating labels: %s", err) } - opErr := computeOperationWait(config.clientCompute, op, project, "labels to update") + opErr := computeOperationWaitTime(config.clientCompute, op, project, "labels to update", int(d.Timeout(schema.TimeoutUpdate).Minutes())) if opErr != nil { return opErr } @@ -986,7 +995,7 @@ func resourceComputeInstanceUpdate(d *schema.ResourceData, meta interface{}) err return fmt.Errorf("Error updating scheduling policy: %s", err) } - opErr := computeOperationWait(config.clientCompute, op, project, "scheduling policy update") + opErr := computeOperationWaitTime(config.clientCompute, op, project, "scheduling policy update", int(d.Timeout(schema.TimeoutUpdate).Minutes())) if opErr != nil { return opErr } @@ -1026,7 +1035,7 @@ func resourceComputeInstanceUpdate(d *schema.ResourceData, meta interface{}) err if err != nil { return fmt.Errorf("Error deleting old access_config: %s", err) } - opErr := computeOperationWait(config.clientCompute, op, project, "old access_config to delete") + opErr := computeOperationWaitTime(config.clientCompute, op, project, "old access_config to delete", int(d.Timeout(schema.TimeoutUpdate).Minutes())) if opErr != nil { return opErr } @@ -1045,7 +1054,7 @@ func resourceComputeInstanceUpdate(d *schema.ResourceData, meta interface{}) err if err != nil { return fmt.Errorf("Error adding new access_config: %s", err) } - opErr := computeOperationWait(config.clientCompute, op, project, "new access_config to add") + opErr := computeOperationWaitTime(config.clientCompute, op, project, "new access_config to add", int(d.Timeout(schema.TimeoutUpdate).Minutes())) if opErr != nil { return opErr } @@ -1123,7 +1132,7 @@ func resourceComputeInstanceUpdate(d *schema.ResourceData, meta interface{}) err return errwrap.Wrapf("Error detaching disk: %s", err) } - opErr := computeOperationWait(config.clientCompute, op, project, "detaching disk") + opErr := computeOperationWaitTime(config.clientCompute, op, project, "detaching disk", int(d.Timeout(schema.TimeoutUpdate).Minutes())) if opErr != nil { return opErr } @@ -1138,7 +1147,7 @@ func resourceComputeInstanceUpdate(d *schema.ResourceData, meta interface{}) err return errwrap.Wrapf("Error attaching disk : {{err}}", err) } - opErr := computeOperationWait(config.clientCompute, op, project, "attaching disk") + opErr := computeOperationWaitTime(config.clientCompute, op, project, "attaching disk", int(d.Timeout(schema.TimeoutUpdate).Minutes())) if opErr != nil { return opErr } @@ -1221,7 +1230,7 @@ func resourceComputeInstanceDelete(d *schema.ResourceData, meta interface{}) err } // Wait for the operation to complete - opErr := computeOperationWait(config.clientCompute, op, project, "instance to delete") + opErr := computeOperationWaitTime(config.clientCompute, op, project, "instance to delete", int(d.Timeout(schema.TimeoutDelete).Minutes())) if opErr != nil { return opErr } diff --git a/website/docs/r/compute_instance_group.html.markdown b/website/docs/r/compute_instance_group.html.markdown index ee7e07ba032..c9a40439815 100644 --- a/website/docs/r/compute_instance_group.html.markdown +++ b/website/docs/r/compute_instance_group.html.markdown @@ -97,6 +97,15 @@ exported: * `size` - The number of instances in the group. +## Timeouts + +This resource provides the following +[Timeouts](/docs/configuration/resources.html#timeouts) configuration options: + +- `create` - Default is `6 minutes` +- `update` - Default is `6 minutes` +- `delete` - Default is `6 minutes` + ## Import Instance group can be imported using the `zone` and `name`, e.g.