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 timeouts to all resources that use Operations #2007

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
3 changes: 3 additions & 0 deletions .changelog/3432.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
* all: add configurable timeouts to several resources that did not previously have them
```
4 changes: 0 additions & 4 deletions google-beta/appengine_operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,6 @@ func (w *AppEngineOperationWaiter) QueryOp() (interface{}, error) {
return w.Service.Apps.Operations.Get(w.AppId, matches[1]).Do()
}

func appEngineOperationWait(config *Config, res interface{}, appId, activity string) error {
return appEngineOperationWaitTime(config, res, appId, activity, 4*time.Minute)
}

func appEngineOperationWaitTimeWithResponse(config *Config, res interface{}, response *map[string]interface{}, appId, activity string, timeout time.Duration) error {
op := &appengine.Operation{}
err := Convert(res, op)
Expand Down
4 changes: 0 additions & 4 deletions google-beta/compute_operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,6 @@ func (w *ComputeOperationWaiter) TargetStates() []string {
return []string{"DONE"}
}

func computeOperationWait(config *Config, res interface{}, project, activity string) error {
return computeOperationWaitTime(config, res, project, activity, 4*time.Minute)
}

func computeOperationWaitTime(config *Config, res interface{}, project, activity string, timeout time.Duration) error {
op := &compute.Operation{}
err := Convert(res, op)
Expand Down
10 changes: 8 additions & 2 deletions google-beta/resource_app_engine_application.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package google
import (
"fmt"
"log"
"time"

"github.com/hashicorp/terraform-plugin-sdk/helper/customdiff"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
Expand All @@ -21,6 +22,11 @@ func resourceAppEngineApplication() *schema.Resource {
State: schema.ImportStatePassthrough,
},

Timeouts: &schema.ResourceTimeout{
Create: schema.DefaultTimeout(4 * time.Minute),
Update: schema.DefaultTimeout(4 * time.Minute),
},

CustomizeDiff: customdiff.All(
appEngineApplicationLocationIDCustomizeDiff,
),
Expand Down Expand Up @@ -188,7 +194,7 @@ func resourceAppEngineApplicationCreate(d *schema.ResourceData, meta interface{}
d.SetId(project)

// Wait for the operation to complete
waitErr := appEngineOperationWait(config, op, project, "App Engine app to create")
waitErr := appEngineOperationWaitTime(config, op, project, "App Engine app to create", d.Timeout(schema.TimeoutCreate))
if waitErr != nil {
d.SetId("")
return waitErr
Expand Down Expand Up @@ -265,7 +271,7 @@ func resourceAppEngineApplicationUpdate(d *schema.ResourceData, meta interface{}
}

// Wait for the operation to complete
waitErr := appEngineOperationWait(config, op, pid, "App Engine app to update")
waitErr := appEngineOperationWaitTime(config, op, pid, "App Engine app to update", d.Timeout(schema.TimeoutUpdate))
if waitErr != nil {
return waitErr
}
Expand Down
6 changes: 4 additions & 2 deletions google-beta/resource_compute_backend_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -1115,7 +1115,8 @@ func resourceComputeBackendServiceCreate(d *schema.ResourceData, meta interface{
if err != nil {
return errwrap.Wrapf("Error setting Backend Service security policy: {{err}}", err)
}
waitErr := computeOperationWait(config, op, project, "Setting Backend Service Security Policy")
// This uses the create timeout for simplicity, though technically this code appears in both create and update
waitErr := computeOperationWaitTime(config, op, project, "Setting Backend Service Security Policy", d.Timeout(schema.TimeoutCreate))
if waitErr != nil {
return waitErr
}
Expand Down Expand Up @@ -1423,7 +1424,8 @@ func resourceComputeBackendServiceUpdate(d *schema.ResourceData, meta interface{
if err != nil {
return errwrap.Wrapf("Error setting Backend Service security policy: {{err}}", err)
}
waitErr := computeOperationWait(config, op, project, "Setting Backend Service Security Policy")
// This uses the create timeout for simplicity, though technically this code appears in both create and update
waitErr := computeOperationWaitTime(config, op, project, "Setting Backend Service Security Policy", d.Timeout(schema.TimeoutCreate))
if waitErr != nil {
return waitErr
}
Expand Down
4 changes: 2 additions & 2 deletions google-beta/resource_compute_disk.go
Original file line number Diff line number Diff line change
Expand Up @@ -897,8 +897,8 @@ func resourceComputeDiskDelete(d *schema.ResourceData, meta interface{}) error {
return fmt.Errorf("Error detaching disk %s from instance %s/%s/%s: %s", call.deviceName, call.project,
call.zone, call.instance, err.Error())
}
err = computeOperationWait(config, op, call.project,
fmt.Sprintf("Detaching disk from %s/%s/%s", call.project, call.zone, call.instance))
err = computeOperationWaitTime(config, op, call.project,
fmt.Sprintf("Detaching disk from %s/%s/%s", call.project, call.zone, call.instance), d.Timeout(schema.TimeoutDelete))
if err != nil {
if opErr, ok := err.(ComputeOperationError); ok && len(opErr.Errors) == 1 && opErr.Errors[0].Code == "RESOURCE_NOT_FOUND" {
log.Printf("[WARN] instance %q was deleted while awaiting detach", call.instance)
Expand Down
19 changes: 13 additions & 6 deletions google-beta/resource_compute_instance_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"log"
"strings"
"time"

"google.golang.org/api/compute/v1"
"google.golang.org/api/googleapi"
Expand All @@ -21,6 +22,12 @@ func resourceComputeInstanceGroup() *schema.Resource {
State: resourceComputeInstanceGroupImportState,
},

Timeouts: &schema.ResourceTimeout{
Create: schema.DefaultTimeout(6 * time.Minute),
Update: schema.DefaultTimeout(6 * time.Minute),
Delete: schema.DefaultTimeout(6 * time.Minute),
},

SchemaVersion: 2,
MigrateState: resourceComputeInstanceGroupMigrateState,

Expand Down Expand Up @@ -159,7 +166,7 @@ func resourceComputeInstanceGroupCreate(d *schema.ResourceData, meta interface{}
d.SetId(fmt.Sprintf("projects/%s/zones/%s/instanceGroups/%s", project, zone, name))

// Wait for the operation to complete
err = computeOperationWait(config, op, project, "Creating InstanceGroup")
err = computeOperationWaitTime(config, op, project, "Creating InstanceGroup", d.Timeout(schema.TimeoutCreate))
if err != nil {
d.SetId("")
return err
Expand All @@ -183,7 +190,7 @@ func resourceComputeInstanceGroupCreate(d *schema.ResourceData, meta interface{}
}

// Wait for the operation to complete
err = computeOperationWait(config, op, project, "Adding instances to InstanceGroup")
err = computeOperationWaitTime(config, op, project, "Adding instances to InstanceGroup", d.Timeout(schema.TimeoutCreate))
if err != nil {
return err
}
Expand Down Expand Up @@ -295,7 +302,7 @@ func resourceComputeInstanceGroupUpdate(d *schema.ResourceData, meta interface{}
}
} else {
// Wait for the operation to complete
err = computeOperationWait(config, removeOp, project, "Updating InstanceGroup")
err = computeOperationWaitTime(config, removeOp, project, "Updating InstanceGroup", d.Timeout(schema.TimeoutUpdate))
if err != nil {
return err
}
Expand All @@ -316,7 +323,7 @@ func resourceComputeInstanceGroupUpdate(d *schema.ResourceData, meta interface{}
}

// Wait for the operation to complete
err = computeOperationWait(config, addOp, project, "Updating InstanceGroup")
err = computeOperationWaitTime(config, addOp, project, "Updating InstanceGroup", d.Timeout(schema.TimeoutUpdate))
if err != nil {
return err
}
Expand All @@ -339,7 +346,7 @@ func resourceComputeInstanceGroupUpdate(d *schema.ResourceData, meta interface{}
return fmt.Errorf("Error updating named ports for InstanceGroup: %s", err)
}

err = computeOperationWait(config, op, project, "Updating InstanceGroup")
err = computeOperationWaitTime(config, op, project, "Updating InstanceGroup", d.Timeout(schema.TimeoutUpdate))
if err != nil {
return err
}
Expand Down Expand Up @@ -369,7 +376,7 @@ func resourceComputeInstanceGroupDelete(d *schema.ResourceData, meta interface{}
return fmt.Errorf("Error deleting InstanceGroup: %s", err)
}

err = computeOperationWait(config, op, project, "Deleting InstanceGroup")
err = computeOperationWaitTime(config, op, project, "Deleting InstanceGroup", d.Timeout(schema.TimeoutDelete))
if err != nil {
return err
}
Expand Down
31 changes: 16 additions & 15 deletions google-beta/resource_compute_instance_migrate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"os"
"strings"
"testing"
"time"

"google.golang.org/api/compute/v1"

Expand Down Expand Up @@ -107,7 +108,7 @@ func TestAccComputeInstanceMigrateState(t *testing.T) {
if err != nil {
t.Fatalf("Error creating instance: %s", err)
}
waitErr := computeOperationWait(config, op, config.Project, "instance to create")
waitErr := computeOperationWaitTime(config, op, config.Project, "instance to create", 4*time.Minute)
if waitErr != nil {
t.Fatal(waitErr)
}
Expand Down Expand Up @@ -180,7 +181,7 @@ func TestAccComputeInstanceMigrateState_bootDisk(t *testing.T) {
if err != nil {
t.Fatalf("Error creating instance: %s", err)
}
waitErr := computeOperationWait(config, op, config.Project, "instance to create")
waitErr := computeOperationWaitTime(config, op, config.Project, "instance to create", 4*time.Minute)
if waitErr != nil {
t.Fatal(waitErr)
}
Expand Down Expand Up @@ -248,7 +249,7 @@ func TestAccComputeInstanceMigrateState_v4FixBootDisk(t *testing.T) {
if err != nil {
t.Fatalf("Error creating instance: %s", err)
}
waitErr := computeOperationWait(config, op, config.Project, "instance to create")
waitErr := computeOperationWaitTime(config, op, config.Project, "instance to create", 4*time.Minute)
if waitErr != nil {
t.Fatal(waitErr)
}
Expand Down Expand Up @@ -301,7 +302,7 @@ func TestAccComputeInstanceMigrateState_attachedDiskFromSource(t *testing.T) {
if err != nil {
t.Fatalf("Error creating disk: %s", err)
}
waitErr := computeOperationWait(config, op, config.Project, "disk to create")
waitErr := computeOperationWaitTime(config, op, config.Project, "disk to create", 4*time.Minute)
if waitErr != nil {
t.Fatal(waitErr)
}
Expand Down Expand Up @@ -333,7 +334,7 @@ func TestAccComputeInstanceMigrateState_attachedDiskFromSource(t *testing.T) {
if err != nil {
t.Fatalf("Error creating instance: %s", err)
}
waitErr = computeOperationWait(config, op, config.Project, "instance to create")
waitErr = computeOperationWaitTime(config, op, config.Project, "instance to create", 4*time.Minute)
if waitErr != nil {
t.Fatal(waitErr)
}
Expand Down Expand Up @@ -382,7 +383,7 @@ func TestAccComputeInstanceMigrateState_v4FixAttachedDiskFromSource(t *testing.T
if err != nil {
t.Fatalf("Error creating disk: %s", err)
}
waitErr := computeOperationWait(config, op, config.Project, "disk to create")
waitErr := computeOperationWaitTime(config, op, config.Project, "disk to create", 4*time.Minute)
if waitErr != nil {
t.Fatal(waitErr)
}
Expand Down Expand Up @@ -414,7 +415,7 @@ func TestAccComputeInstanceMigrateState_v4FixAttachedDiskFromSource(t *testing.T
if err != nil {
t.Fatalf("Error creating instance: %s", err)
}
waitErr = computeOperationWait(config, op, config.Project, "instance to create")
waitErr = computeOperationWaitTime(config, op, config.Project, "instance to create", 4*time.Minute)
if waitErr != nil {
t.Fatal(waitErr)
}
Expand Down Expand Up @@ -483,7 +484,7 @@ func TestAccComputeInstanceMigrateState_attachedDiskFromEncryptionKey(t *testing
if err != nil {
t.Fatalf("Error creating instance: %s", err)
}
waitErr := computeOperationWait(config, op, config.Project, "instance to create")
waitErr := computeOperationWaitTime(config, op, config.Project, "instance to create", 4*time.Minute)
if waitErr != nil {
t.Fatal(waitErr)
}
Expand Down Expand Up @@ -552,7 +553,7 @@ func TestAccComputeInstanceMigrateState_v4FixAttachedDiskFromEncryptionKey(t *te
if err != nil {
t.Fatalf("Error creating instance: %s", err)
}
waitErr := computeOperationWait(config, op, config.Project, "instance to create")
waitErr := computeOperationWaitTime(config, op, config.Project, "instance to create", 4*time.Minute)
if waitErr != nil {
t.Fatal(waitErr)
}
Expand Down Expand Up @@ -623,7 +624,7 @@ func TestAccComputeInstanceMigrateState_attachedDiskFromAutoDeleteAndImage(t *te
if err != nil {
t.Fatalf("Error creating instance: %s", err)
}
waitErr := computeOperationWait(config, op, config.Project, "instance to create")
waitErr := computeOperationWaitTime(config, op, config.Project, "instance to create", 4*time.Minute)
if waitErr != nil {
t.Fatal(waitErr)
}
Expand Down Expand Up @@ -696,7 +697,7 @@ func TestAccComputeInstanceMigrateState_v4FixAttachedDiskFromAutoDeleteAndImage(
if err != nil {
t.Fatalf("Error creating instance: %s", err)
}
waitErr := computeOperationWait(config, op, config.Project, "instance to create")
waitErr := computeOperationWaitTime(config, op, config.Project, "instance to create", 4*time.Minute)
if waitErr != nil {
t.Fatal(waitErr)
}
Expand Down Expand Up @@ -764,7 +765,7 @@ func TestAccComputeInstanceMigrateState_scratchDisk(t *testing.T) {
if err != nil {
t.Fatalf("Error creating instance: %s", err)
}
waitErr := computeOperationWait(config, op, config.Project, "instance to create")
waitErr := computeOperationWaitTime(config, op, config.Project, "instance to create", 4*time.Minute)
if waitErr != nil {
t.Fatal(waitErr)
}
Expand Down Expand Up @@ -829,7 +830,7 @@ func TestAccComputeInstanceMigrateState_v4FixScratchDisk(t *testing.T) {
if err != nil {
t.Fatalf("Error creating instance: %s", err)
}
waitErr := computeOperationWait(config, op, config.Project, "instance to create")
waitErr := computeOperationWaitTime(config, op, config.Project, "instance to create", 4*time.Minute)
if waitErr != nil {
t.Fatal(waitErr)
}
Expand Down Expand Up @@ -908,7 +909,7 @@ func cleanUpInstance(config *Config, instanceName, zone string) {
}

// Wait for the operation to complete
opErr := computeOperationWait(config, op, config.Project, "instance to delete")
opErr := computeOperationWaitTime(config, op, config.Project, "instance to delete", 4*time.Minute)
if opErr != nil {
log.Printf("[WARNING] Error deleting instance %q, dangling resources may exist: %s", instanceName, opErr)
}
Expand All @@ -922,7 +923,7 @@ func cleanUpDisk(config *Config, diskName, zone string) {
}

// Wait for the operation to complete
opErr := computeOperationWait(config, op, config.Project, "disk to delete")
opErr := computeOperationWaitTime(config, op, config.Project, "disk to delete", 4*time.Minute)
if opErr != nil {
log.Printf("[WARNING] Error deleting disk %q, dangling resources may exist: %s", diskName, opErr)
}
Expand Down
10 changes: 8 additions & 2 deletions google-beta/resource_compute_instance_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"reflect"
"strings"
"time"

"github.com/hashicorp/errwrap"
"github.com/hashicorp/terraform-plugin-sdk/helper/customdiff"
Expand Down Expand Up @@ -45,6 +46,11 @@ func resourceComputeInstanceTemplate() *schema.Resource {
),
MigrateState: resourceComputeInstanceTemplateMigrateState,

Timeouts: &schema.ResourceTimeout{
Create: schema.DefaultTimeout(4 * time.Minute),
Delete: schema.DefaultTimeout(4 * time.Minute),
},

// A compute instance template is more or less a subset of a compute
// instance. Please attempt to maintain consistency with the
// resource_compute_instance schema when updating this one.
Expand Down Expand Up @@ -785,7 +791,7 @@ func resourceComputeInstanceTemplateCreate(d *schema.ResourceData, meta interfac
// Store the ID now
d.SetId(fmt.Sprintf("projects/%s/global/instanceTemplates/%s", project, instanceTemplate.Name))

err = computeOperationWait(config, op, project, "Creating Instance Template")
err = computeOperationWaitTime(config, op, project, "Creating Instance Template", d.Timeout(schema.TimeoutCreate))
if err != nil {
return err
}
Expand Down Expand Up @@ -1146,7 +1152,7 @@ func resourceComputeInstanceTemplateDelete(d *schema.ResourceData, meta interfac
return fmt.Errorf("Error deleting instance template: %s", err)
}

err = computeOperationWait(config, op, project, "Deleting Instance Template")
err = computeOperationWaitTime(config, op, project, "Deleting Instance Template", d.Timeout(schema.TimeoutDelete))
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion google-beta/resource_compute_network.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ func resourceComputeNetworkCreate(d *schema.ResourceData, meta interface{}) erro
if err != nil {
return fmt.Errorf("Error deleting route: %s", err)
}
err = computeOperationWait(config, op, project, "Deleting Route")
err = computeOperationWaitTime(config, op, project, "Deleting Route", d.Timeout(schema.TimeoutCreate))
if err != nil {
return err
}
Expand Down
10 changes: 8 additions & 2 deletions google-beta/resource_compute_network_peering.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"log"
"sort"
"strings"
"time"

"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"google.golang.org/api/compute/v1"
Expand All @@ -22,6 +23,11 @@ func resourceComputeNetworkPeering() *schema.Resource {
State: resourceComputeNetworkPeeringImport,
},

Timeouts: &schema.ResourceTimeout{
Create: schema.DefaultTimeout(4 * time.Minute),
Delete: schema.DefaultTimeout(4 * time.Minute),
},

Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Expand Down Expand Up @@ -107,7 +113,7 @@ func resourceComputeNetworkPeeringCreate(d *schema.ResourceData, meta interface{
return fmt.Errorf("Error adding network peering: %s", err)
}

err = computeOperationWait(config, addOp, networkFieldValue.Project, "Adding Network Peering")
err = computeOperationWaitTime(config, addOp, networkFieldValue.Project, "Adding Network Peering", d.Timeout(schema.TimeoutCreate))
if err != nil {
return err
}
Expand Down Expand Up @@ -182,7 +188,7 @@ func resourceComputeNetworkPeeringDelete(d *schema.ResourceData, meta interface{
return fmt.Errorf("Error removing peering `%s` from network `%s`: %s", name, networkFieldValue.Name, err)
}
} else {
err = computeOperationWait(config, removeOp, networkFieldValue.Project, "Removing Network Peering")
err = computeOperationWaitTime(config, removeOp, networkFieldValue.Project, "Removing Network Peering", d.Timeout(schema.TimeoutDelete))
if err != nil {
return err
}
Expand Down
Loading