Skip to content

Commit

Permalink
Add support for instance_type to google_bigtable_instance. (hashicorp…
Browse files Browse the repository at this point in the history
…#313)

* govendor fetch cloud.google.com/go/bigtable

* Vendor the rest of the stuff.

* Add support for instance_type to google_bigtable_instance.

* Revendored some packages.

* Removed bad packages from vendor.json
  • Loading branch information
rileykarson authored Aug 11, 2017
1 parent 1a96796 commit 442f19a
Show file tree
Hide file tree
Showing 24 changed files with 685 additions and 356 deletions.
38 changes: 29 additions & 9 deletions google/resource_bigtable_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,17 @@ func resourceBigtableInstance() *schema.Resource {
},

"num_nodes": {
Type: schema.TypeInt,
Type: schema.TypeInt,
Optional: true,
ForceNew: true,
},

"instance_type": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Default: 3,
ValidateFunc: validation.IntAtLeast(3),
Default: "PRODUCTION",
ValidateFunc: validation.StringInSlice([]string{"DEVELOPMENT", "PRODUCTION"}, false),
},

"storage_type": {
Expand Down Expand Up @@ -91,13 +97,27 @@ func resourceBigtableInstanceCreate(d *schema.ResourceData, meta interface{}) er
storageType = bigtable.SSD
}

numNodes := int32(d.Get("num_nodes").(int))
var instanceType bigtable.InstanceType
switch value := d.Get("instance_type"); value {
case "DEVELOPMENT":
instanceType = bigtable.DEVELOPMENT

if numNodes > 0 {
return fmt.Errorf("Can't specify a non-zero number of nodes: %d for DEVELOPMENT Bigtable instance: %s", numNodes, name)
}
case "PRODUCTION":
instanceType = bigtable.PRODUCTION
}

instanceConf := &bigtable.InstanceConf{
InstanceId: name,
DisplayName: displayName.(string),
ClusterId: d.Get("cluster_id").(string),
NumNodes: int32(d.Get("num_nodes").(int)),
StorageType: storageType,
Zone: d.Get("zone").(string),
InstanceId: name,
DisplayName: displayName.(string),
ClusterId: d.Get("cluster_id").(string),
NumNodes: numNodes,
InstanceType: instanceType,
StorageType: storageType,
Zone: d.Get("zone").(string),
}

c, err := config.bigtableClientFactory.NewInstanceAdminClient(project)
Expand Down
30 changes: 30 additions & 0 deletions google/resource_bigtable_instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,25 @@ func TestAccBigtableInstance_basic(t *testing.T) {
})
}

func TestAccBigtableInstance_development(t *testing.T) {
instanceName := fmt.Sprintf("tf-test-%s", acctest.RandString(10))

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckBigtableInstanceDestroy,
Steps: []resource.TestStep{
{
Config: testAccBigtableInstance_development(instanceName),
Check: resource.ComposeTestCheckFunc(
testAccBigtableInstanceExists(
"google_bigtable_instance.instance"),
),
},
},
})
}

func testAccCheckBigtableInstanceDestroy(s *terraform.State) error {
var ctx = context.Background()
for _, rs := range s.RootModule().Resources {
Expand Down Expand Up @@ -92,3 +111,14 @@ resource "google_bigtable_instance" "instance" {
}
`, instanceName, instanceName)
}

func testAccBigtableInstance_development(instanceName string) string {
return fmt.Sprintf(`
resource "google_bigtable_instance" "instance" {
name = "%s"
cluster_id = "%s"
zone = "us-central1-b"
instance_type = "DEVELOPMENT"
}
`, instanceName, instanceName)
}
18 changes: 8 additions & 10 deletions google/resource_bigtable_table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,10 @@ func testAccBigtableTableExists(n string) resource.TestCheckFunc {
func testAccBigtableTable(instanceName, tableName string) string {
return fmt.Sprintf(`
resource "google_bigtable_instance" "instance" {
name = "%s"
cluster_id = "%s"
zone = "us-central1-b"
num_nodes = 3
storage_type = "HDD"
name = "%s"
cluster_id = "%s"
zone = "us-central1-b"
instance_type = "DEVELOPMENT"
}
resource "google_bigtable_table" "table" {
Expand All @@ -123,11 +122,10 @@ resource "google_bigtable_table" "table" {
func testAccBigtableTable_splitKeys(instanceName, tableName string) string {
return fmt.Sprintf(`
resource "google_bigtable_instance" "instance" {
name = "%s"
cluster_id = "%s"
zone = "us-central1-b"
num_nodes = 3
storage_type = "HDD"
name = "%s"
cluster_id = "%s"
zone = "us-central1-b"
instance_type = "DEVELOPMENT"
}
resource "google_bigtable_table" "table" {
Expand Down
64 changes: 44 additions & 20 deletions vendor/cloud.google.com/go/bigtable/admin.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions vendor/cloud.google.com/go/bigtable/bigtable.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 30 additions & 0 deletions vendor/cloud.google.com/go/bigtable/filter.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion vendor/golang.org/x/oauth2/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 442f19a

Please sign in to comment.