Changed Bigtable instance to use InstanceInfo instead of iterating the list of infos.

This commit is contained in:
Riley Karson 2017-06-28 10:00:49 -07:00 committed by Riley Karson
parent cfe9e4afb4
commit ec2f933252
2 changed files with 7 additions and 45 deletions

View File

@ -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
}

View File

@ -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"])
}