mirror of
https://github.com/letic/terraform-provider-google.git
synced 2024-07-01 07:42:40 +00:00
Autogen Spanner operations on TF (#3068)
<!-- This change is generated by MagicModules. --> /cc @rambleraptor
This commit is contained in:
parent
44ba598a4f
commit
0b1d338d31
|
@ -32,6 +32,10 @@ func (w *RedisOperationWaiter) QueryOp() (interface{}, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func redisOperationWaitTime(config *Config, op map[string]interface{}, project, activity string, timeoutMinutes int) 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{
|
w := &RedisOperationWaiter{
|
||||||
Config: config,
|
Config: config,
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,7 +25,6 @@ import (
|
||||||
|
|
||||||
"github.com/hashicorp/terraform/helper/resource"
|
"github.com/hashicorp/terraform/helper/resource"
|
||||||
"github.com/hashicorp/terraform/helper/schema"
|
"github.com/hashicorp/terraform/helper/schema"
|
||||||
"google.golang.org/api/spanner/v1"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func resourceSpannerInstance() *schema.Resource {
|
func resourceSpannerInstance() *schema.Resource {
|
||||||
|
@ -148,14 +147,8 @@ func resourceSpannerInstanceCreate(d *schema.ResourceData, meta interface{}) err
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
op := &spanner.Operation{}
|
|
||||||
err = Convert(res, op)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
waitErr := spannerOperationWaitTime(
|
waitErr := spannerOperationWaitTime(
|
||||||
config.clientSpanner, op, project, "Creating Instance",
|
config, res, project, "Creating Instance",
|
||||||
int(d.Timeout(schema.TimeoutCreate).Minutes()))
|
int(d.Timeout(schema.TimeoutCreate).Minutes()))
|
||||||
|
|
||||||
if waitErr != nil {
|
if waitErr != nil {
|
||||||
|
@ -272,14 +265,9 @@ func resourceSpannerInstanceUpdate(d *schema.ResourceData, meta interface{}) err
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
op := &spanner.Operation{}
|
|
||||||
err = Convert(res, op)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
err = spannerOperationWaitTime(
|
err = spannerOperationWaitTime(
|
||||||
config.clientSpanner, op, project, "Updating Instance",
|
config, res, project, "Updating Instance",
|
||||||
int(d.Timeout(schema.TimeoutUpdate).Minutes()))
|
int(d.Timeout(schema.TimeoutUpdate).Minutes()))
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -308,14 +296,9 @@ func resourceSpannerInstanceDelete(d *schema.ResourceData, meta interface{}) err
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
op := &spanner.Operation{}
|
|
||||||
err = Convert(res, op)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
err = spannerOperationWaitTime(
|
err = spannerOperationWaitTime(
|
||||||
config.clientSpanner, op, project, "Deleting Instance",
|
config, res, project, "Deleting Instance",
|
||||||
int(d.Timeout(schema.TimeoutDelete).Minutes()))
|
int(d.Timeout(schema.TimeoutDelete).Minutes()))
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -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)
|
|
||||||
}
|
|
46
google/spanner_operation.go
Normal file
46
google/spanner_operation.go
Normal 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)
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user