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

Bigtable Instance changes #5648

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
3 changes: 3 additions & 0 deletions .changelog/3102.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
* bigtable: added update support for `display_name` and `instance_type`
```
27 changes: 2 additions & 25 deletions google/resource_bigtable_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ func resourceBigtableInstance() *schema.Resource {
},

CustomizeDiff: customdiff.All(
resourceBigtableInstanceValidateDevelopment,
resourceBigtableInstanceClusterReorderTypeList,
),

Expand Down Expand Up @@ -69,14 +68,12 @@ func resourceBigtableInstance() *schema.Resource {
"display_name": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Computed: true,
},

"instance_type": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Default: "PRODUCTION",
ValidateFunc: validation.StringInSlice([]string{"DEVELOPMENT", "PRODUCTION"}, false),
},
Expand Down Expand Up @@ -167,14 +164,6 @@ func resourceBigtableInstanceRead(d *schema.ResourceData, meta interface{}) erro

d.Set("project", project)

var instanceType string
if instance.InstanceType == bigtable.DEVELOPMENT {
instanceType = "DEVELOPMENT"
} else {
instanceType = "PRODUCTION"
}
d.Set("instance_type", instanceType)

clusters, err := c.Clusters(ctx, instance.Name)
if err != nil {
return fmt.Errorf("Error retrieving instance clusters. %s", err)
Expand All @@ -193,6 +182,8 @@ func resourceBigtableInstanceRead(d *schema.ResourceData, meta interface{}) erro

d.Set("name", instance.Name)
d.Set("display_name", instance.DisplayName)
// Don't set instance_type: we don't want to detect drift on it because it can
// change under-the-hood.

return nil
}
Expand Down Expand Up @@ -306,20 +297,6 @@ func expandBigtableClusters(clusters []interface{}, instanceID string) []bigtabl
return results
}

// resourceBigtableInstanceValidateDevelopment validates restrictions specific to DEVELOPMENT clusters
func resourceBigtableInstanceValidateDevelopment(diff *schema.ResourceDiff, meta interface{}) error {
if diff.Get("instance_type").(string) != "DEVELOPMENT" {
return nil
}
if diff.Get("cluster.#").(int) != 1 {
return fmt.Errorf("config is invalid: instance with instance_type=\"DEVELOPMENT\" should have exactly one \"cluster\" block")
}
if diff.Get("cluster.0.num_nodes").(int) > 1 {
return fmt.Errorf("config is invalid: num_nodes cannot be set for instance_type=\"DEVELOPMENT\"")
}
return nil
}

// resourceBigtableInstanceClusterReorderTypeList causes the cluster block to
// act like a TypeSet while it's a TypeList underneath. It preserves state
// ordering on updates, and causes the resource to get recreated if it would
Expand Down
80 changes: 28 additions & 52 deletions google/resource_bigtable_instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,19 @@ func TestAccBigtableInstance_basic(t *testing.T) {
Config: testAccBigtableInstance(instanceName, 3),
},
{
ResourceName: "google_bigtable_instance.instance",
ImportState: true,
ImportStateVerify: true,
ResourceName: "google_bigtable_instance.instance",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"instance_type"}, // we don't read instance type back
},
{
Config: testAccBigtableInstance(instanceName, 4),
},
{
ResourceName: "google_bigtable_instance.instance",
ImportState: true,
ImportStateVerify: true,
ResourceName: "google_bigtable_instance.instance",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"instance_type"}, // we don't read instance type back
},
},
})
Expand All @@ -63,33 +65,37 @@ func TestAccBigtableInstance_cluster(t *testing.T) {
Config: testAccBigtableInstance_cluster(instanceName, 3),
},
{
ResourceName: "google_bigtable_instance.instance",
ImportState: true,
ImportStateVerify: true,
ResourceName: "google_bigtable_instance.instance",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"instance_type"}, // we don't read instance type back
},
{
Config: testAccBigtableInstance_clusterReordered(instanceName, 5),
},
{
ResourceName: "google_bigtable_instance.instance",
ImportState: true,
ImportStateVerify: true,
ResourceName: "google_bigtable_instance.instance",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"instance_type"}, // we don't read instance type back
},
{
Config: testAccBigtableInstance_clusterModified(instanceName, 5),
},
{
ResourceName: "google_bigtable_instance.instance",
ImportState: true,
ImportStateVerify: true,
ResourceName: "google_bigtable_instance.instance",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"instance_type"}, // we don't read instance type back
},
{
Config: testAccBigtableInstance_clusterReordered(instanceName, 5),
},
{
ResourceName: "google_bigtable_instance.instance",
ImportState: true,
ImportStateVerify: true,
ResourceName: "google_bigtable_instance.instance",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"instance_type"}, // we don't read instance type back
},
},
})
Expand All @@ -105,21 +111,14 @@ func TestAccBigtableInstance_development(t *testing.T) {
Providers: testAccProviders,
CheckDestroy: testAccCheckBigtableInstanceDestroy,
Steps: []resource.TestStep{
{
Config: testAccBigtableInstance_development_invalid_no_cluster(instanceName),
ExpectError: regexp.MustCompile("config is invalid: instance with instance_type=\"DEVELOPMENT\" should have exactly one \"cluster\" block"),
},
{
Config: testAccBigtableInstance_development_invalid_num_nodes(instanceName),
ExpectError: regexp.MustCompile("config is invalid: num_nodes cannot be set for instance_type=\"DEVELOPMENT\""),
},
{
Config: testAccBigtableInstance_development(instanceName),
},
{
ResourceName: "google_bigtable_instance.instance",
ImportState: true,
ImportStateVerify: true,
ResourceName: "google_bigtable_instance.instance",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"instance_type"}, // we don't read instance type back
},
},
})
Expand Down Expand Up @@ -311,26 +310,3 @@ resource "google_bigtable_instance" "instance" {
}
`, instanceName, instanceName)
}

func testAccBigtableInstance_development_invalid_num_nodes(instanceName string) string {
return fmt.Sprintf(`
resource "google_bigtable_instance" "instance" {
name = "%s"
cluster {
cluster_id = "%s"
zone = "us-central1-b"
num_nodes = 3
}
instance_type = "DEVELOPMENT"
}
`, instanceName, instanceName)
}

func testAccBigtableInstance_development_invalid_no_cluster(instanceName string) string {
return fmt.Sprintf(`
resource "google_bigtable_instance" "instance" {
name = "%s"
instance_type = "DEVELOPMENT"
}
`, instanceName)
}