Skip to content

Commit

Permalink
Add computed state attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
nickithewatt committed Aug 12, 2017
1 parent f7d7384 commit ddbabb6
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
9 changes: 7 additions & 2 deletions google/resource_spanner_database.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ func resourceSpannerDatabase() *schema.Resource {
ForceNew: true,
Elem: &schema.Schema{Type: schema.TypeString},
},

"state": {
Type: schema.TypeString,
Computed: true,
},
},
}
}
Expand Down Expand Up @@ -119,13 +124,13 @@ func resourceSpannerDatabaseRead(d *schema.ResourceData, meta interface{}) error
return err
}

_, err = config.clientSpanner.Projects.Instances.Databases.Get(
db, err := config.clientSpanner.Projects.Instances.Databases.Get(
id.databaseUri()).Do()
if err != nil {
return handleNotFoundError(err, d, fmt.Sprintf("Spanner database %q", id.databaseUri()))
}

d.SetId(id.terraformId())
d.Set("state", db.State)
return nil
}

Expand Down
3 changes: 2 additions & 1 deletion google/resource_spanner_database_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ func TestAccSpannerDatabase_basic(t *testing.T) {
testAccCheckSpannerDatabaseExists("google_spanner_database.basic", &db),

resource.TestCheckResourceAttr("google_spanner_database.basic", "name", "my-db-"+rnd),
resource.TestCheckResourceAttrSet("google_spanner_database.basic", "state"),
),
},
},
Expand Down Expand Up @@ -208,7 +209,7 @@ func testAccCheckSpannerDatabaseExists(n string, instance *spanner.Database) res
return err
}

fName := extractInstanceNameFromApi(found.Name)
fName := extractInstanceNameFromUri(found.Name)
if fName != id.Database {
return fmt.Errorf("Spanner database %s not found, found %s instead", id.Database, fName)
}
Expand Down
5 changes: 4 additions & 1 deletion website/docs/r/spanner_database.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@ The following arguments are supported:

## Attributes Reference

No additional attributes are computed other than those defined above.
In addition to the arguments listed above, the following computed attributes are
exported:

* `state` - The current state of the database.

## Import

Expand Down

0 comments on commit ddbabb6

Please sign in to comment.