Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for instance_type to google_bigtable_instance. #313

Merged
merged 6 commits into from
Aug 11, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the number of nodes is ForceNew, we don't want to force our users to delete and recreate their production database.

I would rather have our users specify num_nodes = 1 for DEVELOPMENT.

If you don't send num_nodes to the server, does it set 1 for dev and 3 for production by default? If so, we could use Computed = True for num_nodes.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we send a non-zero value to the server for num_nodes for a DEVELOPMENT instance, the request fails. There's no server default when you don't send a num_nodes for a production one; the request fails.

Users won't actually need to recreate their instances; the num_nodes of 3 is preserved in state, and they will just need to update their config when it diffs.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we leave the num_nodes default to 3 and just don't send the property when creating a DEVELOPMENT instance? This way, we don't create churn for our users...

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doing things like that breaks the 1:1 mapping from config -> the API, and imo isn't worth it if we ever need to correct later. For example, if we were to gain the ability to read num_nodes, we would either need to conditionally read it or would see diffs in the future.

I think it's worth a breaking change here because the number of users is small (and I expect the # of users that relied on the implicit default is smaller), the change is easy to make, and it means we'll be tracking the API as accurately as we can until the next client update.

},

"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