Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Google Spanner Support (google_spanner_instance) #270

Merged
merged 8 commits into from
Aug 14, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -109,6 +109,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