Autogen Spanner operations on TF (#3068)

<!-- This change is generated by MagicModules. -->
/cc @rambleraptor
This commit is contained in:
The Magician 2019-02-15 16:13:30 -08:00 committed by Riley Karson
parent 44ba598a4f
commit 0b1d338d31
4 changed files with 53 additions and 53 deletions

View File

@ -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,
}

View File

@ -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 {

View File

@ -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)
}

View File

@ -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)
}