diff --git a/products/spanner/api.yaml b/products/spanner/api.yaml index 0e2d9952efe9..10391a1c831d 100644 --- a/products/spanner/api.yaml +++ b/products/spanner/api.yaml @@ -74,7 +74,13 @@ objects: name: 'config' resource: 'InstanceConfig' imports: 'name' - description: 'A reference to the instance configuration.' + description: | + The name of the instance's configuration (similar but not + quite the same as a region) which defines defines the geographic placement and + replication of your databases in this instance. It determines where your data + is stored. Values are typically of the form `regional-europe-west1` , `us-central` etc. + In order to obtain a valid list please consult the + [Configuration section of the docs](https://cloud.google.com/spanner/docs/instances). required: true - !ruby/object:Api::Type::String name: 'displayName' @@ -85,34 +91,10 @@ objects: - !ruby/object:Api::Type::Integer name: 'nodeCount' description: 'The number of nodes allocated to this instance.' - required: true + default_value: 1 - !ruby/object:Api::Type::KeyValuePairs name: 'labels' description: | - Cloud Labels are a flexible and lightweight mechanism for organizing - cloud resources into groups that reflect a customer's organizational - needs and deployment strategies. Cloud Labels can be used to filter - collections of resources. They can be used to control how resource - metrics are aggregated. And they can be used as arguments to policy - management rules (e.g. route, firewall, load balancing, etc.). - - Label keys must be between 1 and 63 characters long and must conform - to the following regular expression: `[a-z]([-a-z0-9]*[a-z0-9])?`. - Label values must be between 0 and 63 characters long and must conform - to the regular expression `([a-z]([-a-z0-9]*[a-z0-9])?)?`. - - No more than 64 labels can be associated with a given resource. - - See https://goo.gl/xmQnxf for more information on and examples of - labels. - - If you plan to use labels in your own code, please note that - additional characters may be allowed in the future. And so you are - advised to use an internal label representation, such as JSON, which - doesn't rely upon specific characters being disallowed. For example, - representing labels as the string: name + "_" + value would prove - problematic if we were to allow "_" in a future release. - An object containing a list of "key": value pairs. Example: { "name": "wrench", "mass": "1.3kg", "count": "3" }. - !ruby/object:Api::Type::Enum diff --git a/products/spanner/terraform.yaml b/products/spanner/terraform.yaml index 4c71ea908420..f2b4e89976a8 100644 --- a/products/spanner/terraform.yaml +++ b/products/spanner/terraform.yaml @@ -48,10 +48,19 @@ overrides: !ruby/object:Overrides::ResourceOverrides - "projects/{{project}}/instances/{{name}}" - "{{project}}/{{name}}" - "{{name}}" + examples: + - !ruby/object:Provider::Terraform::Examples + name: "spanner_instance_basic" + primary_resource_id: "example" + version: <%= version_name %> + description: | + {{description}} + + If not provided, a random string starting with `tf-` will be selected. properties: displayName: !ruby/object:Overrides::Terraform::PropertyOverride validation: !ruby/object:Provider::Terraform::Validation - regex: '^(?:[a-z](?:[-_a-z0-9]{2,28}[a-z0-9])?)$' + regex: '^(?:[a-zA-Z](?:[- _a-zA-Z0-9]{2,28}[a-zA-Z0-9])?)$' name: !ruby/object:Overrides::Terraform::PropertyOverride validation: !ruby/object:Provider::Terraform::Validation regex: '^(?:[a-z](?:[-_a-z0-9]{4,28}[a-z0-9])?)$' diff --git a/templates/terraform/examples/spanner_instance_basic.tf.erb b/templates/terraform/examples/spanner_instance_basic.tf.erb new file mode 100644 index 000000000000..34140d32ed39 --- /dev/null +++ b/templates/terraform/examples/spanner_instance_basic.tf.erb @@ -0,0 +1,8 @@ +resource "google_spanner_instance" "example" { + config = "regional-us-central1" + display_name = "Test Spanner Instance" + num_nodes = 2 + labels { + "foo" = "bar" + } +} diff --git a/templates/terraform/post_create/sleep.go.erb b/templates/terraform/post_create/sleep.go.erb index defb4f9bb242..30b726f3bebc 100644 --- a/templates/terraform/post_create/sleep.go.erb +++ b/templates/terraform/post_create/sleep.go.erb @@ -1,3 +1,4 @@ -// Spanner instances are, ironically, eventually consistent. -// We ensure that the Read sees the instance as created by sleeping, briefly. +// This is useful if the resource in question doesn't have a perfectly consistent API +// That is, the Operation for Create might return before the Get operation shows the +// completed state of the resource. time.Sleep(5 * time.Second) diff --git a/third_party/terraform/tests/resource_spanner_instance_test.go b/third_party/terraform/tests/resource_spanner_instance_test.go index f3231b58ae30..fb3c7c0e3711 100644 --- a/third_party/terraform/tests/resource_spanner_instance_test.go +++ b/third_party/terraform/tests/resource_spanner_instance_test.go @@ -2,15 +2,10 @@ package google import ( "fmt" - "net/http" "testing" - "github.com/hashicorp/errwrap" "github.com/hashicorp/terraform/helper/acctest" "github.com/hashicorp/terraform/helper/resource" - "github.com/hashicorp/terraform/terraform" - - "google.golang.org/api/googleapi" ) // Unit Tests @@ -131,44 +126,6 @@ func TestAccSpannerInstance_update(t *testing.T) { }) } -func testAccCheckSpannerInstanceDestroy(s *terraform.State) error { - config := testAccProvider.Meta().(*Config) - - for _, rs := range s.RootModule().Resources { - if rs.Type != "google_spanner_instance" { - continue - } - - if rs.Primary.ID == "" { - return fmt.Errorf("Unable to verify delete of spanner instance, ID is empty") - } - - instanceName := rs.Primary.Attributes["name"] - project, err := getTestProject(rs.Primary, config) - if err != nil { - return err - } - - id := spannerInstanceId{ - Project: project, - Instance: instanceName, - } - _, err = config.clientSpanner.Projects.Instances.Get( - id.instanceUri()).Do() - - if err == nil { - return fmt.Errorf("Spanner instance still exists") - } - - if gerr, ok := err.(*googleapi.Error); ok && gerr.Code == http.StatusNotFound { - return nil - } - return errwrap.Wrapf("Error verifying spanner instance deleted: {{err}}", err) - } - - return nil -} - func testAccSpannerInstance_basic(name string) string { return fmt.Sprintf(` resource "google_spanner_instance" "basic" { diff --git a/third_party/terraform/utils/provider.go.erb b/third_party/terraform/utils/provider.go.erb index f12c20914c48..617d2f48a282 100644 --- a/third_party/terraform/utils/provider.go.erb +++ b/third_party/terraform/utils/provider.go.erb @@ -146,6 +146,7 @@ func ResourceMapWithErrors() (map[string]*schema.Resource, error) { GeneratedRedisResourcesMap, GeneratedResourceManagerResourcesMap, GeneratedSourceRepoResourcesMap, + GeneratedSpannerResourcesMap, GeneratedStorageResourcesMap, GeneratedMonitoringResourcesMap, map[string]*schema.Resource{ @@ -216,11 +217,9 @@ func ResourceMapWithErrors() (map[string]*schema.Resource, error) { <% unless version == 'ga' -%> "google_service_networking_connection": resourceServiceNetworkingConnection(), <% end -%> - "google_spanner_instance": resourceSpannerInstance(), "google_spanner_instance_iam_binding": ResourceIamBindingWithImport(IamSpannerInstanceSchema, NewSpannerInstanceIamUpdater, SpannerInstanceIdParseFunc), "google_spanner_instance_iam_member": ResourceIamMemberWithImport(IamSpannerInstanceSchema, NewSpannerInstanceIamUpdater, SpannerInstanceIdParseFunc), "google_spanner_instance_iam_policy": ResourceIamPolicyWithImport(IamSpannerInstanceSchema, NewSpannerInstanceIamUpdater, SpannerInstanceIdParseFunc), - "google_spanner_database": resourceSpannerDatabase(), "google_spanner_database_iam_binding": ResourceIamBindingWithImport(IamSpannerDatabaseSchema, NewSpannerDatabaseIamUpdater, SpannerDatabaseIdParseFunc), "google_spanner_database_iam_member": ResourceIamMemberWithImport(IamSpannerDatabaseSchema, NewSpannerDatabaseIamUpdater, SpannerDatabaseIdParseFunc), "google_spanner_database_iam_policy": ResourceIamPolicyWithImport(IamSpannerDatabaseSchema, NewSpannerDatabaseIamUpdater, SpannerDatabaseIdParseFunc),