Skip to content

Commit

Permalink
Add Google Spanner Support (google_spanner_instance) (hashicorp#270)
Browse files Browse the repository at this point in the history
  • Loading branch information
nickithewatt authored and rosbo committed Aug 14, 2017
1 parent 0368b45 commit a6b5fa2
Show file tree
Hide file tree
Showing 11 changed files with 13,038 additions and 0 deletions.
9 changes: 9 additions & 0 deletions google/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"google.golang.org/api/pubsub/v1"
"google.golang.org/api/servicemanagement/v1"
"google.golang.org/api/sourcerepo/v1"
"google.golang.org/api/spanner/v1"
"google.golang.org/api/sqladmin/v1beta4"
"google.golang.org/api/storage/v1"
)
Expand All @@ -45,6 +46,7 @@ type Config struct {
clientDns *dns.Service
clientPubsub *pubsub.Service
clientResourceManager *cloudresourcemanager.Service
clientSpanner *spanner.Service
clientSourceRepo *sourcerepo.Service
clientStorage *storage.Service
clientSqlAdmin *sqladmin.Service
Expand Down Expand Up @@ -215,6 +217,13 @@ func (c *Config) loadAndValidate() error {
}
c.clientSourceRepo.UserAgent = userAgent

log.Printf("[INFO] Instantiating Google Cloud Spanner Client...")
c.clientSpanner, err = spanner.New(client)
if err != nil {
return err
}
c.clientSpanner.UserAgent = userAgent

return nil
}

Expand Down
59 changes: 59 additions & 0 deletions google/import_spanner_instance_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package google

import (
"fmt"
"testing"

"github.com/hashicorp/terraform/helper/acctest"
"github.com/hashicorp/terraform/helper/resource"
)

func TestAccGoogleSpannerInstance_importInstance(t *testing.T) {
resourceName := "google_spanner_instance.basic"
instanceName := fmt.Sprintf("span-itest-%s", acctest.RandString(10))

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckSpannerInstanceDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccSpannerInstance_basic(instanceName),
},

resource.TestStep{
ResourceName: resourceName,
ImportStateId: instanceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func TestAccGoogleSpannerInstance_importProjectInstance(t *testing.T) {
resourceName := "google_spanner_instance.basic"
instanceName := fmt.Sprintf("span-itest-%s", acctest.RandString(10))
var projectId = multiEnvSearch([]string{"GOOGLE_PROJECT", "GCLOUD_PROJECT", "CLOUDSDK_CORE_PROJECT"})
if projectId == "" {
t.Skip("Unable to locate projectId via environment variables ... skipping ")
return
}

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckSpannerInstanceDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccSpannerInstance_basicWithProject(projectId, instanceName),
},

resource.TestStep{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}
1 change: 1 addition & 0 deletions google/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ func Provider() terraform.ResourceProvider {
"google_dns_managed_zone": resourceDnsManagedZone(),
"google_dns_record_set": resourceDnsRecordSet(),
"google_sourcerepo_repository": resourceSourceRepoRepository(),
"google_spanner_instance": resourceSpannerInstance(),
"google_sql_database": resourceSqlDatabase(),
"google_sql_database_instance": resourceSqlDatabaseInstance(),
"google_sql_user": resourceSqlUser(),
Expand Down
Loading

0 comments on commit a6b5fa2

Please sign in to comment.