Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add configurable timeouts to google_compute_instance #856

Merged
merged 1 commit into from
Dec 14, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 23 additions & 14 deletions google/resource_compute_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand Down Expand Up @@ -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.",
},
},
}
Expand Down Expand Up @@ -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)
}

Expand Down Expand Up @@ -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
}
Expand All @@ -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
}
Expand All @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand All @@ -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
}
Expand Down Expand Up @@ -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
}
Expand All @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down
9 changes: 9 additions & 0 deletions website/docs/r/compute_instance_group.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down