diff --git a/google/redis_operation.go b/google/redis_operation.go index f85108c0..5b816490 100644 --- a/google/redis_operation.go +++ b/google/redis_operation.go @@ -32,6 +32,10 @@ func (w *RedisOperationWaiter) QueryOp() (interface{}, error) { } func redisOperationWaitTime(config *Config, op map[string]interface{}, project, activity string, timeoutMinutes int) error { + if val, ok := op["name"]; !ok || val == "" { + // This was a synchronous call - there is no operation to wait for. + return nil + } w := &RedisOperationWaiter{ Config: config, } diff --git a/google/resource_spanner_instance.go b/google/resource_spanner_instance.go index ae8df5ef..dab3abe3 100644 --- a/google/resource_spanner_instance.go +++ b/google/resource_spanner_instance.go @@ -25,7 +25,6 @@ import ( "github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/helper/schema" - "google.golang.org/api/spanner/v1" ) func resourceSpannerInstance() *schema.Resource { @@ -148,14 +147,8 @@ func resourceSpannerInstanceCreate(d *schema.ResourceData, meta interface{}) err if err != nil { return err } - op := &spanner.Operation{} - err = Convert(res, op) - if err != nil { - return err - } - waitErr := spannerOperationWaitTime( - config.clientSpanner, op, project, "Creating Instance", + config, res, project, "Creating Instance", int(d.Timeout(schema.TimeoutCreate).Minutes())) if waitErr != nil { @@ -272,14 +265,9 @@ func resourceSpannerInstanceUpdate(d *schema.ResourceData, meta interface{}) err if err != nil { return err } - op := &spanner.Operation{} - err = Convert(res, op) - if err != nil { - return err - } err = spannerOperationWaitTime( - config.clientSpanner, op, project, "Updating Instance", + config, res, project, "Updating Instance", int(d.Timeout(schema.TimeoutUpdate).Minutes())) if err != nil { @@ -308,14 +296,9 @@ func resourceSpannerInstanceDelete(d *schema.ResourceData, meta interface{}) err if err != nil { return err } - op := &spanner.Operation{} - err = Convert(res, op) - if err != nil { - return err - } err = spannerOperationWaitTime( - config.clientSpanner, op, project, "Deleting Instance", + config, res, project, "Deleting Instance", int(d.Timeout(schema.TimeoutDelete).Minutes())) if err != nil { diff --git a/google/spanner_instance_operation.go b/google/spanner_instance_operation.go deleted file mode 100644 index d90dd50a..00000000 --- a/google/spanner_instance_operation.go +++ /dev/null @@ -1,33 +0,0 @@ -package google - -import ( - "fmt" - - "google.golang.org/api/spanner/v1" -) - -type SpannerInstanceOperationWaiter struct { - Service *spanner.Service - CommonOperationWaiter -} - -func (w *SpannerInstanceOperationWaiter) QueryOp() (interface{}, error) { - if w == nil { - return nil, fmt.Errorf("Cannot query operation, it's unset or nil.") - } - return w.Service.Projects.Instances.Operations.Get(w.Op.Name).Do() -} - -func spannerOperationWaitTime(spanner *spanner.Service, op *spanner.Operation, _ string, activity string, timeoutMinutes int) error { - if op.Name == "" { - // This was a synchronous call - there is no operation to wait for. - return nil - } - w := &SpannerInstanceOperationWaiter{ - Service: spanner, - } - if err := w.SetOp(op); err != nil { - return err - } - return OperationWait(w, activity, timeoutMinutes) -} diff --git a/google/spanner_operation.go b/google/spanner_operation.go new file mode 100644 index 00000000..23e4af9c --- /dev/null +++ b/google/spanner_operation.go @@ -0,0 +1,46 @@ +// ---------------------------------------------------------------------------- +// +// *** AUTO GENERATED CODE *** AUTO GENERATED CODE *** +// +// ---------------------------------------------------------------------------- +// +// This file is automatically generated by Magic Modules and manual +// changes will be clobbered when the file is regenerated. +// +// Please read more about how to change this file in +// .github/CONTRIBUTING.md. +// +// ---------------------------------------------------------------------------- +package google + +import ( + "fmt" +) + +type SpannerOperationWaiter struct { + Config *Config + CommonOperationWaiter +} + +func (w *SpannerOperationWaiter) QueryOp() (interface{}, error) { + if w == nil { + return nil, fmt.Errorf("Cannot query operation, it's unset or nil.") + } + // Returns the proper get. + url := fmt.Sprintf("https://spanner.googleapis.com/v1/%s", w.CommonOperationWaiter.Op.Name) + return sendRequest(w.Config, "GET", url, nil) +} + +func spannerOperationWaitTime(config *Config, op map[string]interface{}, project, activity string, timeoutMinutes int) error { + if val, ok := op["name"]; !ok || val == "" { + // This was a synchronous call - there is no operation to wait for. + return nil + } + w := &SpannerOperationWaiter{ + Config: config, + } + if err := w.CommonOperationWaiter.SetOp(op); err != nil { + return err + } + return OperationWait(w, activity, timeoutMinutes) +}