2017-06-15 17:41:05 +00:00
|
|
|
package google
|
|
|
|
|
|
|
|
import (
|
2017-07-05 19:54:38 +00:00
|
|
|
"context"
|
2017-06-15 17:41:05 +00:00
|
|
|
"fmt"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/hashicorp/terraform/helper/acctest"
|
|
|
|
"github.com/hashicorp/terraform/helper/resource"
|
|
|
|
"github.com/hashicorp/terraform/terraform"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestAccBigtableInstance_basic(t *testing.T) {
|
2017-10-12 22:07:29 +00:00
|
|
|
t.Parallel()
|
|
|
|
|
2017-06-15 17:41:05 +00:00
|
|
|
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(instanceName),
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccBigtableInstanceExists(
|
|
|
|
"google_bigtable_instance.instance"),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2017-08-11 21:43:00 +00:00
|
|
|
func TestAccBigtableInstance_development(t *testing.T) {
|
2017-10-12 22:07:29 +00:00
|
|
|
t.Parallel()
|
|
|
|
|
2017-08-11 21:43:00 +00:00
|
|
|
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"),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2017-06-15 17:41:05 +00:00
|
|
|
func testAccCheckBigtableInstanceDestroy(s *terraform.State) error {
|
|
|
|
var ctx = context.Background()
|
|
|
|
for _, rs := range s.RootModule().Resources {
|
|
|
|
if rs.Type != "google_bigtable_instance" {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
config := testAccProvider.Meta().(*Config)
|
2017-06-26 20:34:33 +00:00
|
|
|
c, err := config.bigtableClientFactory.NewInstanceAdminClient(config.Project)
|
2017-06-15 17:41:05 +00:00
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("Error starting instance admin client. %s", err)
|
|
|
|
}
|
|
|
|
|
2017-06-28 17:00:49 +00:00
|
|
|
_, err = c.InstanceInfo(ctx, rs.Primary.Attributes["name"])
|
|
|
|
if err == nil {
|
2017-06-15 17:41:05 +00:00
|
|
|
return fmt.Errorf("Instance %s still exists.", rs.Primary.Attributes["name"])
|
|
|
|
}
|
|
|
|
|
|
|
|
c.Close()
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func testAccBigtableInstanceExists(n string) resource.TestCheckFunc {
|
|
|
|
var ctx = context.Background()
|
|
|
|
return func(s *terraform.State) error {
|
|
|
|
rs, ok := s.RootModule().Resources[n]
|
|
|
|
if !ok {
|
|
|
|
return fmt.Errorf("Not found: %s", n)
|
|
|
|
}
|
|
|
|
|
|
|
|
if rs.Primary.ID == "" {
|
|
|
|
return fmt.Errorf("No ID is set")
|
|
|
|
}
|
|
|
|
config := testAccProvider.Meta().(*Config)
|
2017-06-26 20:34:33 +00:00
|
|
|
c, err := config.bigtableClientFactory.NewInstanceAdminClient(config.Project)
|
2017-06-15 17:41:05 +00:00
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("Error starting instance admin client. %s", err)
|
|
|
|
}
|
|
|
|
|
2017-06-28 17:00:49 +00:00
|
|
|
_, err = c.InstanceInfo(ctx, rs.Primary.Attributes["name"])
|
2017-06-15 17:41:05 +00:00
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("Error retrieving instance %s.", rs.Primary.Attributes["name"])
|
|
|
|
}
|
|
|
|
|
|
|
|
c.Close()
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func testAccBigtableInstance(instanceName string) string {
|
|
|
|
return fmt.Sprintf(`
|
|
|
|
resource "google_bigtable_instance" "instance" {
|
2017-06-26 20:33:05 +00:00
|
|
|
name = "%s"
|
|
|
|
cluster_id = "%s"
|
|
|
|
zone = "us-central1-b"
|
|
|
|
num_nodes = 3
|
|
|
|
storage_type = "HDD"
|
2017-06-15 17:41:05 +00:00
|
|
|
}
|
|
|
|
`, instanceName, instanceName)
|
|
|
|
}
|
2017-08-11 21:43:00 +00:00
|
|
|
|
|
|
|
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)
|
|
|
|
}
|