diff --git a/.changelog/3102.txt b/.changelog/3102.txt new file mode 100644 index 00000000000..56d214c3fab --- /dev/null +++ b/.changelog/3102.txt @@ -0,0 +1,3 @@ +```release-note:enhancement +* bigtable: added update support for `display_name` and `instance_type` +``` diff --git a/google/resource_bigtable_instance.go b/google/resource_bigtable_instance.go index 63536e73470..0f76789b3e2 100644 --- a/google/resource_bigtable_instance.go +++ b/google/resource_bigtable_instance.go @@ -24,7 +24,6 @@ func resourceBigtableInstance() *schema.Resource { }, CustomizeDiff: customdiff.All( - resourceBigtableInstanceValidateDevelopment, resourceBigtableInstanceClusterReorderTypeList, ), @@ -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), }, @@ -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) @@ -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 } @@ -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 diff --git a/google/resource_bigtable_instance_test.go b/google/resource_bigtable_instance_test.go index efef6cfbfd1..d7752999d48 100644 --- a/google/resource_bigtable_instance_test.go +++ b/google/resource_bigtable_instance_test.go @@ -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 }, }, }) @@ -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 }, }, }) @@ -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 }, }, }) @@ -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) -}