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 Spanner instance datasource #4111

Merged
merged 8 commits into from
Oct 15, 2020
25 changes: 25 additions & 0 deletions third_party/terraform/data_sources/data_source_spanner_instance.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package google

import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

func dataSourceSpannerInstance() *schema.Resource {

dsSchema := (resourceSpannerInstance().Schema)
addRequiredFieldsToSchema(dsSchema, "name")
addOptionalFieldsToSchema(dsSchema, "config")
addOptionalFieldsToSchema(dsSchema, "display_name")
addOptionalFieldsToSchema(dsSchema, "project")

return &schema.Resource{
Read: dataSourceSpannerInstanceRead,
Schema: dsSchema,
}
}

func dataSourceSpannerInstanceRead(d *schema.ResourceData, meta interface{}) error {

return resourceSpannerInstanceRead(d, meta)

}
46 changes: 46 additions & 0 deletions third_party/terraform/tests/data_source_spanner_instance_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package google

import (
"testing"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
)

func TestAccDataSourceSpannerInstance_basic(t *testing.T) {
t.Parallel()

context := map[string]interface{}{
"random_suffix": randString(t, 10),
}

vcrTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckSpannerInstanceDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccDataSourceSpannerInstanceBasic(context),
Check: resource.ComposeTestCheckFunc(
checkDataSourceStateMatchesResourceState("data.google_spanner_instance.foo", "google_spanner_instance.bar"),
),
},
},
})
}

func testAccDataSourceSpannerInstanceBasic(context map[string]interface{}) string {
return Nprintf(`
resource "google_spanner_instance" "bar" {
config = "regional-us-central1"
display_name = "Test Spanner Instance"
num_nodes = 2
labels = {
"foo" = "bar"
}
}

data "google_spanner_instance" "foo" {
name = google_spanner_instance.bar.name
}
`, context)
}
1 change: 1 addition & 0 deletions third_party/terraform/utils/provider.go.erb
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ func Provider() *schema.Provider {
"google_service_account_access_token": dataSourceGoogleServiceAccountAccessToken(),
"google_service_account_id_token": dataSourceGoogleServiceAccountIdToken(),
"google_service_account_key": dataSourceGoogleServiceAccountKey(),
"google_spanner_instance": dataSourceSpannerInstance(),
"google_sql_ca_certs": dataSourceGoogleSQLCaCerts(),
"google_sql_database_instance": dataSourceSqlDatabaseInstance(),
"google_storage_bucket_object": dataSourceGoogleStorageBucketObject(),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
---
subcategory: "Cloud Spanner"
layout: "google"
page_title: "Google: google_compute_global_forwarding_rule"
sidebar_current: "docs-google-datasource-spanner-instance"
description: |-
Get a spanner instance from Google Cloud
---

# google\_compute\_global_\forwarding\_rule

Get a spanner instance from Google Cloud by its name.

## Example Usage

```tf
data "google_spanner_instance" "foo" {
name = "bar"
}
```

## Argument Reference

The following arguments are supported:

* `name` - (Required) The name of the spanner instance.

- - -

* `project` - (Optional) The project in which the resource belongs. If it
is not provided, the provider project is used.

## Attributes Reference
See [google_spanner_instance](https://www.terraform.io/docs/providers/google/r/spanner_instance.html) resource for details of all the available attributes.