Skip to content

Commit

Permalink
Spanner Fixes
Browse files Browse the repository at this point in the history
Signed-off-by: Modular Magician <[email protected]>
  • Loading branch information
rambleraptor authored and modular-magician committed Jul 3, 2019
1 parent 3518b16 commit a4e6b67
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 2 deletions.
33 changes: 33 additions & 0 deletions google/resource_spanner_database.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"time"

"github.com/hashicorp/terraform/helper/schema"
"google.golang.org/api/spanner/v1"
)

func resourceSpannerDatabase() *schema.Resource {
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
}
Expand Down
15 changes: 13 additions & 2 deletions google/resource_spanner_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit a4e6b67

Please sign in to comment.