From a4e6b670f4d3cc15b70ec9cdaa709c9130013eb6 Mon Sep 17 00:00:00 2001 From: Alex Stephen Date: Wed, 3 Jul 2019 21:35:41 +0000 Subject: [PATCH] Spanner Fixes Signed-off-by: Modular Magician --- google/resource_spanner_database.go | 33 +++++++++++++++++++++++++++++ google/resource_spanner_instance.go | 15 +++++++++++-- 2 files changed, 46 insertions(+), 2 deletions(-) diff --git a/google/resource_spanner_database.go b/google/resource_spanner_database.go index 05f36be47a1..7e4b124cd15 100644 --- a/google/resource_spanner_database.go +++ b/google/resource_spanner_database.go @@ -21,6 +21,7 @@ import ( "time" "github.com/hashicorp/terraform/helper/schema" + "google.golang.org/api/spanner/v1" ) func resourceSpannerDatabase() *schema.Resource { @@ -119,6 +120,20 @@ func resourceSpannerDatabaseCreate(d *schema.ResourceData, meta interface{}) err } d.SetId(id) + project, err := getProject(d, config) + if err != nil { + return err + } + waitErr := spannerOperationWaitTime( + config, res, project, "Creating Database", + int(d.Timeout(schema.TimeoutCreate).Minutes())) + + if waitErr != nil { + // The resource didn't actually create + d.SetId("") + return fmt.Errorf("Error waiting to create Database: %s", waitErr) + } + log.Printf("[DEBUG] Finished creating Database %q: %#v", d.Id(), res) return resourceSpannerDatabaseRead(d, meta) @@ -178,6 +193,24 @@ func resourceSpannerDatabaseDelete(d *schema.ResourceData, meta interface{}) err return handleNotFoundError(err, d, "Database") } + project, err := getProject(d, config) + if err != nil { + return err + } + op := &spanner.Operation{} + err = Convert(res, op) + if err != nil { + return err + } + + err = spannerOperationWaitTime( + config.clientSpanner, op, project, "Deleting Database", + int(d.Timeout(schema.TimeoutDelete).Minutes())) + + if err != nil { + return err + } + log.Printf("[DEBUG] Finished deleting Database %q: %#v", d.Id(), res) return nil } diff --git a/google/resource_spanner_instance.go b/google/resource_spanner_instance.go index 5895429c4e6..753fd362392 100644 --- a/google/resource_spanner_instance.go +++ b/google/resource_spanner_instance.go @@ -25,6 +25,7 @@ import ( "github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/helper/schema" + "google.golang.org/api/spanner/v1" ) func resourceSpannerInstance() *schema.Resource { @@ -265,9 +266,14 @@ 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, res, project, "Updating Instance", + config.clientSpanner, op, project, "Updating Instance", int(d.Timeout(schema.TimeoutUpdate).Minutes())) if err != nil { @@ -296,9 +302,14 @@ 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, res, project, "Deleting Instance", + config.clientSpanner, op, project, "Deleting Instance", int(d.Timeout(schema.TimeoutDelete).Minutes())) if err != nil {