diff --git a/google/resource_bigtable_instance.go b/google/resource_bigtable_instance.go index 2ba226e4..b3ecc68f 100644 --- a/google/resource_bigtable_instance.go +++ b/google/resource_bigtable_instance.go @@ -132,27 +132,13 @@ func resourceBigtableInstanceRead(d *schema.ResourceData, meta interface{}) erro defer c.Close() - instances, err := c.Instances(ctx) + instance, err := c.InstanceInfo(ctx, d.Id()) if err != nil { - return fmt.Errorf("Error retrieving instances. %s", err) + return fmt.Errorf("Error retrieving instance. Could not find %s.", d.Id()) } - var instanceInfo *bigtable.InstanceInfo - name := d.Id() - found := false - for _, i := range instances { - if i.Name == name { - instanceInfo = i - found = true - break - } - } - if !found { - return fmt.Errorf("Error retrieving instance. Could not find %s.", name) - } - - d.Set("name", instanceInfo.Name) - d.Set("display_name", instanceInfo.DisplayName) + d.Set("name", instance.Name) + d.Set("display_name", instance.DisplayName) return nil } diff --git a/google/resource_bigtable_instance_test.go b/google/resource_bigtable_instance_test.go index 95ad5a1f..7592cba3 100644 --- a/google/resource_bigtable_instance_test.go +++ b/google/resource_bigtable_instance_test.go @@ -42,20 +42,8 @@ func testAccCheckBigtableInstanceDestroy(s *terraform.State) error { return fmt.Errorf("Error starting instance admin client. %s", err) } - instances, err := c.Instances(ctx) - if err != nil { - return fmt.Errorf("Error retrieving instances. %s", err) - } - - found := false - for _, i := range instances { - if i.Name == rs.Primary.Attributes["name"] { - found = true - break - } - } - - if found { + _, err = c.InstanceInfo(ctx, rs.Primary.Attributes["name"]) + if err == nil { return fmt.Errorf("Instance %s still exists.", rs.Primary.Attributes["name"]) } @@ -82,20 +70,8 @@ func testAccBigtableInstanceExists(n string) resource.TestCheckFunc { return fmt.Errorf("Error starting instance admin client. %s", err) } - instances, err := c.Instances(ctx) + _, err = c.InstanceInfo(ctx, rs.Primary.Attributes["name"]) if err != nil { - return fmt.Errorf("Error retrieving instances. %s", err) - } - - found := false - for _, i := range instances { - if i.Name == rs.Primary.Attributes["name"] { - found = true - break - } - } - - if !found { return fmt.Errorf("Error retrieving instance %s.", rs.Primary.Attributes["name"]) }