mirror of
https://github.com/letic/terraform-provider-google.git
synced 2024-09-07 09:36:44 +00:00
94 lines
2.5 KiB
Go
94 lines
2.5 KiB
Go
![]() |
// ----------------------------------------------------------------------------
|
||
|
//
|
||
|
// *** AUTO GENERATED CODE *** AUTO GENERATED CODE ***
|
||
|
//
|
||
|
// ----------------------------------------------------------------------------
|
||
|
//
|
||
|
// This file is automatically generated by Magic Modules and manual
|
||
|
// changes will be clobbered when the file is regenerated.
|
||
|
//
|
||
|
// Please read more about how to change this file in
|
||
|
// .github/CONTRIBUTING.md.
|
||
|
//
|
||
|
// ----------------------------------------------------------------------------
|
||
|
|
||
|
package google
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
"strings"
|
||
|
"testing"
|
||
|
|
||
|
"github.com/hashicorp/terraform/helper/acctest"
|
||
|
"github.com/hashicorp/terraform/helper/resource"
|
||
|
"github.com/hashicorp/terraform/terraform"
|
||
|
)
|
||
|
|
||
|
func TestAccSpannerDatabase_spannerDatabaseBasicExample(t *testing.T) {
|
||
|
t.Parallel()
|
||
|
|
||
|
context := map[string]interface{}{
|
||
|
"random_suffix": acctest.RandString(10),
|
||
|
}
|
||
|
|
||
|
resource.Test(t, resource.TestCase{
|
||
|
PreCheck: func() { testAccPreCheck(t) },
|
||
|
Providers: testAccProviders,
|
||
|
CheckDestroy: testAccCheckSpannerDatabaseDestroy,
|
||
|
Steps: []resource.TestStep{
|
||
|
{
|
||
|
Config: testAccSpannerDatabase_spannerDatabaseBasicExample(context),
|
||
|
},
|
||
|
{
|
||
|
ResourceName: "google_spanner_database.database",
|
||
|
ImportState: true,
|
||
|
ImportStateVerify: true,
|
||
|
ImportStateVerifyIgnore: []string{"ddl"},
|
||
|
},
|
||
|
},
|
||
|
})
|
||
|
}
|
||
|
|
||
|
func testAccSpannerDatabase_spannerDatabaseBasicExample(context map[string]interface{}) string {
|
||
|
return Nprintf(`
|
||
|
resource "google_spanner_instance" "main" {
|
||
|
config = "regional-europe-west1"
|
||
|
display_name = "main-instance"
|
||
|
}
|
||
|
|
||
|
resource "google_spanner_database" "database" {
|
||
|
instance = "${google_spanner_instance.main.name}"
|
||
|
name = "my-database-%{random_suffix}"
|
||
|
ddl = [
|
||
|
"CREATE TABLE t1 (t1 INT64 NOT NULL,) PRIMARY KEY(t1)",
|
||
|
"CREATE TABLE t2 (t2 INT64 NOT NULL,) PRIMARY KEY(t2)"
|
||
|
]
|
||
|
}
|
||
|
`, context)
|
||
|
}
|
||
|
|
||
|
func testAccCheckSpannerDatabaseDestroy(s *terraform.State) error {
|
||
|
for name, rs := range s.RootModule().Resources {
|
||
|
if rs.Type != "google_spanner_database" {
|
||
|
continue
|
||
|
}
|
||
|
if strings.HasPrefix(name, "data.") {
|
||
|
continue
|
||
|
}
|
||
|
|
||
|
config := testAccProvider.Meta().(*Config)
|
||
|
|
||
|
url, err := replaceVarsForTest(rs, "https://spanner.googleapis.com/v1/projects/{{project}}/instances/{{instance}}/databases/{{name}}")
|
||
|
if err != nil {
|
||
|
return err
|
||
|
}
|
||
|
|
||
|
_, err = sendRequest(config, "GET", url, nil)
|
||
|
if err == nil {
|
||
|
return fmt.Errorf("SpannerDatabase still exists at %s", url)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return nil
|
||
|
}
|