From eb4e1af9c4ecbecaa5675fff13d77011c7b395dc Mon Sep 17 00:00:00 2001 From: venkykuberan Date: Wed, 2 Sep 2020 20:39:46 -0700 Subject: [PATCH 01/16] eoncders and customdiff added for spanner DB ddl update --- products/spanner/api.yaml | 8 ++--- products/spanner/terraform.yaml | 6 ++-- .../constants/spanner_database.go.erb | 28 ++++++++++++++++++ .../spanner_database.go.erb | 15 ++++++++++ .../update_encoder/spanner_database.go.erb | 29 +++++++++++++++++++ .../tests/resource_spanner_database_test.go | 24 +++++++++++++++ 6 files changed, 104 insertions(+), 6 deletions(-) create mode 100644 templates/terraform/resource_definition/spanner_database.go.erb create mode 100644 templates/terraform/update_encoder/spanner_database.go.erb diff --git a/products/spanner/api.yaml b/products/spanner/api.yaml index 35d861e9e4e4..f7eed98928d8 100644 --- a/products/spanner/api.yaml +++ b/products/spanner/api.yaml @@ -122,15 +122,16 @@ objects: - !ruby/object:Api::Resource name: 'Database' base_url: projects/{{project}}/instances/{{instance}}/databases + update_url: projects/{{project}}/instances/{{instance}}/databases/{{name}}/ddl + update_verb: :PATCH description: | A Cloud Spanner Database which is hosted on a Spanner instance. - input: true references: !ruby/object:Api::Resource::ReferenceLinks guides: 'Official Documentation': 'https://cloud.google.com/spanner/' api: 'https://cloud.google.com/spanner/docs/reference/rest/v1/projects.instances.databases' async: !ruby/object:Api::OpAsync - actions: ['create', 'update'] + actions: ['create','update'] operation: !ruby/object:Api::OpAsync::Operation path: 'name' base_url: '{{op_id}}' @@ -173,7 +174,6 @@ objects: database. Statements can create tables, indexes, etc. These statements execute atomically with the creation of the database: if there is an error in any statement, the database is not created. - input: true - !ruby/object:Api::Type::Enum name: 'state' description: An explanation of the status of the database. @@ -183,4 +183,4 @@ objects: exclude: true values: - :READY - - :CREATING + - :CREATING \ No newline at end of file diff --git a/products/spanner/terraform.yaml b/products/spanner/terraform.yaml index df0085b4ff61..beca997a4014 100644 --- a/products/spanner/terraform.yaml +++ b/products/spanner/terraform.yaml @@ -45,8 +45,11 @@ overrides: !ruby/object:Overrides::ResourceOverrides state: !ruby/object:Overrides::Terraform::PropertyOverride exclude: false custom_code: !ruby/object:Provider::Terraform::CustomCode + constants: 'templates/terraform/constants/spanner_database.go.erb' encoder: templates/terraform/encoders/spanner_database.go.erb decoder: templates/terraform/decoders/spanner_database.go.erb + update_encoder: templates/terraform/update_encoder/spanner_database.go.erb + resource_definition: 'templates/terraform/resource_definition/spanner_database.go.erb' InstanceConfig: !ruby/object:Overrides::Terraform::ResourceOverride # This is appropriate for a datasource - doesn't have a create method. exclude: true @@ -87,10 +90,9 @@ overrides: !ruby/object:Overrides::ResourceOverrides update_encoder: templates/terraform/encoders/spanner_instance_update.go.erb decoder: templates/terraform/decoders/spanner_instance.go.erb post_create: templates/terraform/post_create/sleep.go.erb - # This is for copying files over files: !ruby/object:Provider::Config::Files # These files have templating (ERB) code that will be run. # This is usually to add licensing info, autogeneration notices, etc. compile: -<%= lines(indent(compile('provider/terraform/product~compile.yaml'), 4)) -%> +<%= lines(indent(compile('provider/terraform/product~compile.yaml'), 4)) -%> \ No newline at end of file diff --git a/templates/terraform/constants/spanner_database.go.erb b/templates/terraform/constants/spanner_database.go.erb index e69de29bb2d1..df3fed991532 100644 --- a/templates/terraform/constants/spanner_database.go.erb +++ b/templates/terraform/constants/spanner_database.go.erb @@ -0,0 +1,28 @@ +<%- # the license inside this block applies to this file + # Copyright 2020 Google Inc. + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. +-%> +// customizeDiff func for additional checks on google_spanner_database properties: +func resourceSpannerDBDdlCustomDiff(diff *schema.ResourceDiff, meta interface{}) error { + old, new := diff.GetChange("ddl") + oldDdls := old.([]interface{}) + newDdls := new.([]interface{}) + + for i := range oldDdls { + if newDdls[i].(string) != oldDdls[i].(string) { + diff.ForceNew("ddl") + return nil + } + } + return nil +} diff --git a/templates/terraform/resource_definition/spanner_database.go.erb b/templates/terraform/resource_definition/spanner_database.go.erb new file mode 100644 index 000000000000..8e231bebd479 --- /dev/null +++ b/templates/terraform/resource_definition/spanner_database.go.erb @@ -0,0 +1,15 @@ +<%# The license inside this block applies to this file. + # Copyright 2020 Google Inc. + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. +-%> +CustomizeDiff: resourceSpannerDBDdlCustomDiff, diff --git a/templates/terraform/update_encoder/spanner_database.go.erb b/templates/terraform/update_encoder/spanner_database.go.erb new file mode 100644 index 000000000000..35c82b2a805b --- /dev/null +++ b/templates/terraform/update_encoder/spanner_database.go.erb @@ -0,0 +1,29 @@ +<%# The license inside this block applies to this file. + # Copyright 2020 Google Inc. + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. +-%> +old, new := d.GetChange("ddl") +oldDdls := old.([]interface{}) +newDdls := new.([]interface{}) +updateDdls := []string{} + +//Only new ddl statments to be add to update call +for i := len(oldDdls); i < len(newDdls); i++ { + updateDdls = append(updateDdls, newDdls[i].(string)) +} + +obj["statements"] = strings.Join(updateDdls, ",") +delete(obj, "name") +delete(obj, "instance") +delete(obj, "extraStatements") +return obj, nil \ No newline at end of file diff --git a/third_party/terraform/tests/resource_spanner_database_test.go b/third_party/terraform/tests/resource_spanner_database_test.go index c8d237c75f1a..0eb170909b67 100644 --- a/third_party/terraform/tests/resource_spanner_database_test.go +++ b/third_party/terraform/tests/resource_spanner_database_test.go @@ -66,6 +66,30 @@ resource "google_spanner_instance" "basic" { resource "google_spanner_database" "basic" { instance = google_spanner_instance.basic.name name = "%s" + ddl = [ + "CREATE TABLE t1 (t1 INT64 NOT NULL,) PRIMARY KEY(t1)", + "CREATE TABLE t2 (t2 INT64 NOT NULL,) PRIMARY KEY(t2)", + ] +} +`, instanceName, instanceName, databaseName) +} + +func testAccSpannerDatabase_basicUpdate(instanceName, databaseName string) string { + return fmt.Sprintf(` +resource "google_spanner_instance" "basic" { + name = "%s" + config = "regional-us-central1" + display_name = "display-%s" + num_nodes = 1 +} + +resource "google_spanner_database" "basic" { + instance = google_spanner_instance.basic.name + name = "%s" + ddl = [ + "CREATE TABLE t1 (t1 INT64 NOT NULL,) PRIMARY KEY(t1)", + "CREATE TABLE t3 (t3 INT64 NOT NULL,) PRIMARY KEY(t3)", + ] } `, instanceName, instanceName, databaseName) } From d4bf11fe638e501874979a1037fc6ba843a98777 Mon Sep 17 00:00:00 2001 From: venkykuberan Date: Thu, 3 Sep 2020 06:52:46 -0700 Subject: [PATCH 02/16] config update test case added --- .../terraform/tests/resource_spanner_database_test.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/third_party/terraform/tests/resource_spanner_database_test.go b/third_party/terraform/tests/resource_spanner_database_test.go index 0eb170909b67..bac157655144 100644 --- a/third_party/terraform/tests/resource_spanner_database_test.go +++ b/third_party/terraform/tests/resource_spanner_database_test.go @@ -26,6 +26,12 @@ func TestAccSpannerDatabase_basic(t *testing.T) { resource.TestCheckResourceAttrSet("google_spanner_database.basic", "state"), ), }, + { + Config: testAccSpannerDatabase_basicUpdate(instanceName, databaseName), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrSet("google_spanner_database.basic", "state"), + ), + }, { // Test import with default Terraform ID ResourceName: "google_spanner_database.basic", From 692cf8eebb5230e364d782fff2619457bcbe1bbc Mon Sep 17 00:00:00 2001 From: venkykuberan Date: Thu, 3 Sep 2020 11:27:41 -0700 Subject: [PATCH 03/16] customdiff modified to handle out-of-index issue --- products/spanner/api.yaml | 7 ++++--- templates/terraform/constants/spanner_database.go.erb | 5 +++++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/products/spanner/api.yaml b/products/spanner/api.yaml index f7eed98928d8..caf83f96f20d 100644 --- a/products/spanner/api.yaml +++ b/products/spanner/api.yaml @@ -122,8 +122,7 @@ objects: - !ruby/object:Api::Resource name: 'Database' base_url: projects/{{project}}/instances/{{instance}}/databases - update_url: projects/{{project}}/instances/{{instance}}/databases/{{name}}/ddl - update_verb: :PATCH + input: true description: | A Cloud Spanner Database which is hosted on a Spanner instance. references: !ruby/object:Api::Resource::ReferenceLinks @@ -131,7 +130,7 @@ objects: 'Official Documentation': 'https://cloud.google.com/spanner/' api: 'https://cloud.google.com/spanner/docs/reference/rest/v1/projects.instances.databases' async: !ruby/object:Api::OpAsync - actions: ['create','update'] + actions: ['create','update','delete'] operation: !ruby/object:Api::OpAsync::Operation path: 'name' base_url: '{{op_id}}' @@ -169,6 +168,8 @@ objects: - !ruby/object:Api::Type::Array item_type: Api::Type::String name: 'extraStatements' + update_url: projects/{{project}}/instances/{{instance}}/databases/{{name}}/ddl + update_verb: :PATCH description: | An optional list of DDL statements to run inside the newly created database. Statements can create tables, indexes, etc. These statements diff --git a/templates/terraform/constants/spanner_database.go.erb b/templates/terraform/constants/spanner_database.go.erb index df3fed991532..0fadc35d4063 100644 --- a/templates/terraform/constants/spanner_database.go.erb +++ b/templates/terraform/constants/spanner_database.go.erb @@ -18,6 +18,11 @@ func resourceSpannerDBDdlCustomDiff(diff *schema.ResourceDiff, meta interface{}) oldDdls := old.([]interface{}) newDdls := new.([]interface{}) + if len(newDdls) < len(oldDdls) { + diff.ForceNew("ddl") + return nil + } + for i := range oldDdls { if newDdls[i].(string) != oldDdls[i].(string) { diff.ForceNew("ddl") From 9fcb2909a85274221d4043353b78ed8248fd4edb Mon Sep 17 00:00:00 2001 From: venkykuberan Date: Thu, 3 Sep 2020 11:54:12 -0700 Subject: [PATCH 04/16] new lines added --- products/spanner/api.yaml | 2 +- products/spanner/terraform.yaml | 2 +- templates/terraform/update_encoder/spanner_database.go.erb | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/products/spanner/api.yaml b/products/spanner/api.yaml index caf83f96f20d..39b69ea1bc73 100644 --- a/products/spanner/api.yaml +++ b/products/spanner/api.yaml @@ -184,4 +184,4 @@ objects: exclude: true values: - :READY - - :CREATING \ No newline at end of file + - :CREATING diff --git a/products/spanner/terraform.yaml b/products/spanner/terraform.yaml index beca997a4014..a6557e4cc78c 100644 --- a/products/spanner/terraform.yaml +++ b/products/spanner/terraform.yaml @@ -95,4 +95,4 @@ files: !ruby/object:Provider::Config::Files # These files have templating (ERB) code that will be run. # This is usually to add licensing info, autogeneration notices, etc. compile: -<%= lines(indent(compile('provider/terraform/product~compile.yaml'), 4)) -%> \ No newline at end of file +<%= lines(indent(compile('provider/terraform/product~compile.yaml'), 4)) -%> diff --git a/templates/terraform/update_encoder/spanner_database.go.erb b/templates/terraform/update_encoder/spanner_database.go.erb index 35c82b2a805b..6291995e54da 100644 --- a/templates/terraform/update_encoder/spanner_database.go.erb +++ b/templates/terraform/update_encoder/spanner_database.go.erb @@ -26,4 +26,4 @@ obj["statements"] = strings.Join(updateDdls, ",") delete(obj, "name") delete(obj, "instance") delete(obj, "extraStatements") -return obj, nil \ No newline at end of file +return obj, nil From c1772136448957e069cdd093103ec6e10a4a570d Mon Sep 17 00:00:00 2001 From: venkykuberan Date: Thu, 3 Sep 2020 12:01:36 -0700 Subject: [PATCH 05/16] indent fixed --- templates/terraform/constants/spanner_database.go.erb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/templates/terraform/constants/spanner_database.go.erb b/templates/terraform/constants/spanner_database.go.erb index 0fadc35d4063..e2b7595e5484 100644 --- a/templates/terraform/constants/spanner_database.go.erb +++ b/templates/terraform/constants/spanner_database.go.erb @@ -15,8 +15,8 @@ // customizeDiff func for additional checks on google_spanner_database properties: func resourceSpannerDBDdlCustomDiff(diff *schema.ResourceDiff, meta interface{}) error { old, new := diff.GetChange("ddl") - oldDdls := old.([]interface{}) - newDdls := new.([]interface{}) + oldDdls := old.([]interface{}) + newDdls := new.([]interface{}) if len(newDdls) < len(oldDdls) { diff.ForceNew("ddl") From aac19da629d66de7944432baea69e80908c4c982 Mon Sep 17 00:00:00 2001 From: venkykuberan Date: Thu, 3 Sep 2020 12:04:15 -0700 Subject: [PATCH 06/16] indent fixed for tests --- third_party/terraform/tests/resource_spanner_database_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/third_party/terraform/tests/resource_spanner_database_test.go b/third_party/terraform/tests/resource_spanner_database_test.go index bac157655144..75280f36b5fa 100644 --- a/third_party/terraform/tests/resource_spanner_database_test.go +++ b/third_party/terraform/tests/resource_spanner_database_test.go @@ -74,7 +74,7 @@ resource "google_spanner_database" "basic" { name = "%s" ddl = [ "CREATE TABLE t1 (t1 INT64 NOT NULL,) PRIMARY KEY(t1)", - "CREATE TABLE t2 (t2 INT64 NOT NULL,) PRIMARY KEY(t2)", + "CREATE TABLE t2 (t2 INT64 NOT NULL,) PRIMARY KEY(t2)", ] } `, instanceName, instanceName, databaseName) @@ -94,7 +94,7 @@ resource "google_spanner_database" "basic" { name = "%s" ddl = [ "CREATE TABLE t1 (t1 INT64 NOT NULL,) PRIMARY KEY(t1)", - "CREATE TABLE t3 (t3 INT64 NOT NULL,) PRIMARY KEY(t3)", + "CREATE TABLE t3 (t3 INT64 NOT NULL,) PRIMARY KEY(t3)", ] } `, instanceName, instanceName, databaseName) From 6eed28a600749d3595905abbed38e7b3672a7010 Mon Sep 17 00:00:00 2001 From: venkykuberan Date: Fri, 4 Sep 2020 06:22:59 -0700 Subject: [PATCH 07/16] test added for ddl update condition --- .../tests/resource_spanner_database_test.go | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/third_party/terraform/tests/resource_spanner_database_test.go b/third_party/terraform/tests/resource_spanner_database_test.go index 75280f36b5fa..ba9ee64e02d6 100644 --- a/third_party/terraform/tests/resource_spanner_database_test.go +++ b/third_party/terraform/tests/resource_spanner_database_test.go @@ -32,6 +32,12 @@ func TestAccSpannerDatabase_basic(t *testing.T) { resource.TestCheckResourceAttrSet("google_spanner_database.basic", "state"), ), }, + { + Config: testAccSpannerDatabase_basicForceNew(instanceName, databaseName), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrSet("google_spanner_database.basic", "state"), + ), + }, { // Test import with default Terraform ID ResourceName: "google_spanner_database.basic", @@ -89,6 +95,27 @@ resource "google_spanner_instance" "basic" { num_nodes = 1 } +resource "google_spanner_database" "basic" { + instance = google_spanner_instance.basic.name + name = "%s" + ddl = [ + "CREATE TABLE t1 (t1 INT64 NOT NULL,) PRIMARY KEY(t1)", + "CREATE TABLE t2 (t2 INT64 NOT NULL,) PRIMARY KEY(t2)", + "CREATE TABLE t3 (t3 INT64 NOT NULL,) PRIMARY KEY(t3)", + ] +} +`, instanceName, instanceName, databaseName) +} + +func testAccSpannerDatabase_basicForceNew(instanceName, databaseName string) string { + return fmt.Sprintf(` +resource "google_spanner_instance" "basic" { + name = "%s" + config = "regional-us-central1" + display_name = "display-%s" + num_nodes = 1 +} + resource "google_spanner_database" "basic" { instance = google_spanner_instance.basic.name name = "%s" From 9c319f29047609f6749e8aa20f6bbfd23f55e07a Mon Sep 17 00:00:00 2001 From: venkykuberan Date: Tue, 8 Sep 2020 09:47:36 -0700 Subject: [PATCH 08/16] mock added Terraformresourcediff, unit tests added --- .../constants/spanner_database.go.erb | 26 ++++++++++++++----- .../tests/resource_spanner_database_test.go | 18 +++++++++++++ third_party/terraform/utils/test_utils.go | 4 +++ third_party/terraform/utils/utils.go.erb | 1 + 4 files changed, 42 insertions(+), 7 deletions(-) diff --git a/templates/terraform/constants/spanner_database.go.erb b/templates/terraform/constants/spanner_database.go.erb index e2b7595e5484..86c986237b70 100644 --- a/templates/terraform/constants/spanner_database.go.erb +++ b/templates/terraform/constants/spanner_database.go.erb @@ -13,21 +13,33 @@ # limitations under the License. -%> // customizeDiff func for additional checks on google_spanner_database properties: -func resourceSpannerDBDdlCustomDiff(diff *schema.ResourceDiff, meta interface{}) error { - old, new := diff.GetChange("ddl") - oldDdls := old.([]interface{}) - newDdls := new.([]interface{}) +func resourceSpannerDBDdlCustomDiffFunc(diff TerraformResourceDiff) error { + old, new := diff.GetChange("ddl") + oldDdls := old.([]interface{}) + newDdls := new.([]interface{}) + var err error - if len(newDdls) < len(oldDdls) { - diff.ForceNew("ddl") + if len(newDdls) < len(oldDdls) { + err = diff.ForceNew("ddl") + if err != nil { + return fmt.Errorf("ForceNew failed for ddl, old - %s and new - %s", oldDdls, newDdls) + } return nil } for i := range oldDdls { if newDdls[i].(string) != oldDdls[i].(string) { - diff.ForceNew("ddl") + err = diff.ForceNew("ddl") + if err != nil { + return fmt.Errorf("ForceNew failed for ddl, old - %s and new - %s", oldDdls, newDdls) + } return nil } } return nil } + +func resourceSpannerDBDdlCustomDiff(diff *schema.ResourceDiff, meta interface{}) error { + // separate func to allow unit testing + return resourceSpannerDBDdlCustomDiffFunc(diff) +} \ No newline at end of file diff --git a/third_party/terraform/tests/resource_spanner_database_test.go b/third_party/terraform/tests/resource_spanner_database_test.go index ba9ee64e02d6..45192da9f71b 100644 --- a/third_party/terraform/tests/resource_spanner_database_test.go +++ b/third_party/terraform/tests/resource_spanner_database_test.go @@ -138,3 +138,21 @@ func TestDatabaseNameForApi(t *testing.T) { expected := "projects/project123/instances/instance456/databases/db789" expectEquals(t, expected, actual) } + +// Unit Tests for ForceNew when the change in ddl +func TestSpannerDatabase_resourceSpannerDBDdlCustomDiffFunc(t *testing.T) { + t.Parallel() + + d := &ResourceDiffMock{ + Before: map[string]interface{}{ + "ddl": []interface{}{"CREATE TABLE t1 (t1 INT64 NOT NULL,) PRIMARY KEY(t1)"}, + }, + After: map[string]interface{}{ + "ddl": []interface{}{"CREATE TABLE t2 (t2 INT64 NOT NULL,) PRIMARY KEY(t2)"}, + }, + } + err := resourceSpannerDBDdlCustomDiffFunc(d) + if err != nil { + t.Errorf("failed, expected no error but received one", err) + } +} diff --git a/third_party/terraform/utils/test_utils.go b/third_party/terraform/utils/test_utils.go index 3ad7b46b23d8..2b2e49a0f471 100644 --- a/third_party/terraform/utils/test_utils.go +++ b/third_party/terraform/utils/test_utils.go @@ -83,6 +83,10 @@ func (d *ResourceDiffMock) Clear(key string) error { return nil } +func (d *ResourceDiffMock) ForceNew(key string) error { + return nil +} + func checkDataSourceStateMatchesResourceState(dataSourceName, resourceName string) func(*terraform.State) error { return checkDataSourceStateMatchesResourceStateWithIgnores(dataSourceName, resourceName, map[string]struct{}{}) } diff --git a/third_party/terraform/utils/utils.go.erb b/third_party/terraform/utils/utils.go.erb index fe3aac9b171f..0b1273b7b144 100644 --- a/third_party/terraform/utils/utils.go.erb +++ b/third_party/terraform/utils/utils.go.erb @@ -33,6 +33,7 @@ type TerraformResourceDiff interface { GetChange(string) (interface{}, interface{}) Get(string) interface{} Clear(string) error + ForceNew(string) error } // getRegionFromZone returns the region from a zone for Google cloud. From 384004c1f72175eb7b424f0a1f38411050f0f50f Mon Sep 17 00:00:00 2001 From: venkykuberan Date: Tue, 8 Sep 2020 10:39:06 -0700 Subject: [PATCH 09/16] test fixed --- third_party/terraform/tests/resource_spanner_database_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/third_party/terraform/tests/resource_spanner_database_test.go b/third_party/terraform/tests/resource_spanner_database_test.go index 45192da9f71b..74f2584d1316 100644 --- a/third_party/terraform/tests/resource_spanner_database_test.go +++ b/third_party/terraform/tests/resource_spanner_database_test.go @@ -153,6 +153,6 @@ func TestSpannerDatabase_resourceSpannerDBDdlCustomDiffFunc(t *testing.T) { } err := resourceSpannerDBDdlCustomDiffFunc(d) if err != nil { - t.Errorf("failed, expected no error but received one", err) + t.Errorf("failed, expected no error but received one - %s", err) } } From a0d14098c617390d9abae0f9601a92b3553ffcce Mon Sep 17 00:00:00 2001 From: venkykuberan Date: Thu, 10 Sep 2020 18:12:59 -0700 Subject: [PATCH 10/16] more unit tests added --- .../constants/spanner_database.go.erb | 4 +- .../tests/resource_spanner_database_test.go | 110 +++++++++++++++++- third_party/terraform/utils/test_utils.go | 8 +- 3 files changed, 116 insertions(+), 6 deletions(-) diff --git a/templates/terraform/constants/spanner_database.go.erb b/templates/terraform/constants/spanner_database.go.erb index 86c986237b70..510e1e6d91a2 100644 --- a/templates/terraform/constants/spanner_database.go.erb +++ b/templates/terraform/constants/spanner_database.go.erb @@ -22,7 +22,7 @@ func resourceSpannerDBDdlCustomDiffFunc(diff TerraformResourceDiff) error { if len(newDdls) < len(oldDdls) { err = diff.ForceNew("ddl") if err != nil { - return fmt.Errorf("ForceNew failed for ddl, old - %s and new - %s", oldDdls, newDdls) + return fmt.Errorf("ForceNew failed for ddl, old - %v and new - %v", oldDdls, newDdls) } return nil } @@ -31,7 +31,7 @@ func resourceSpannerDBDdlCustomDiffFunc(diff TerraformResourceDiff) error { if newDdls[i].(string) != oldDdls[i].(string) { err = diff.ForceNew("ddl") if err != nil { - return fmt.Errorf("ForceNew failed for ddl, old - %s and new - %s", oldDdls, newDdls) + return fmt.Errorf("ForceNew failed for ddl, old - %v and new - %v", oldDdls, newDdls) } return nil } diff --git a/third_party/terraform/tests/resource_spanner_database_test.go b/third_party/terraform/tests/resource_spanner_database_test.go index 74f2584d1316..bdd4bd7708e7 100644 --- a/third_party/terraform/tests/resource_spanner_database_test.go +++ b/third_party/terraform/tests/resource_spanner_database_test.go @@ -26,12 +26,22 @@ func TestAccSpannerDatabase_basic(t *testing.T) { resource.TestCheckResourceAttrSet("google_spanner_database.basic", "state"), ), }, + { + // Test import with default Terraform ID + ResourceName: "google_spanner_database.basic", + ImportState: true, + }, { Config: testAccSpannerDatabase_basicUpdate(instanceName, databaseName), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttrSet("google_spanner_database.basic", "state"), ), }, + { + // Test import with default Terraform ID + ResourceName: "google_spanner_database.basic", + ImportState: true, + }, { Config: testAccSpannerDatabase_basicForceNew(instanceName, databaseName), Check: resource.ComposeTestCheckFunc( @@ -140,7 +150,7 @@ func TestDatabaseNameForApi(t *testing.T) { } // Unit Tests for ForceNew when the change in ddl -func TestSpannerDatabase_resourceSpannerDBDdlCustomDiffFunc(t *testing.T) { +func TestSpannerDatabase_resourceSpannerDBDdlCustomDiffFuncForceNew(t *testing.T) { t.Parallel() d := &ResourceDiffMock{ @@ -155,4 +165,102 @@ func TestSpannerDatabase_resourceSpannerDBDdlCustomDiffFunc(t *testing.T) { if err != nil { t.Errorf("failed, expected no error but received one - %s", err) } + if !d.IsForceNew { + t.Errorf("Resource should ForceNew when older ddl statements are removed") + } +} + +func TestSpannerDatabase_resourceSpannerDBDdlCustomDiffFuncNewStatements(t *testing.T) { + t.Parallel() + + d := &ResourceDiffMock{ + Before: map[string]interface{}{ + "ddl": []interface{}{"CREATE TABLE t1 (t1 INT64 NOT NULL,) PRIMARY KEY(t1)"}, + }, + After: map[string]interface{}{ + "ddl": []interface{}{ + "CREATE TABLE t1 (t1 INT64 NOT NULL,) PRIMARY KEY(t1)", + "CREATE TABLE t2 (t2 INT64 NOT NULL,) PRIMARY KEY(t2)"}, + }, + } + resourceSpannerDBDdlCustomDiffFunc(d) + + if d.IsForceNew { + t.Errorf("Resource shouldn't ForceNew for new ddl statements append") + } +} + +func TestSpannerDatabase_resourceSpannerDBDdlCustomDiffFuncNoChange(t *testing.T) { + t.Parallel() + + d := &ResourceDiffMock{ + Before: map[string]interface{}{ + "ddl": []interface{}{ + "CREATE TABLE t1 (t1 INT64 NOT NULL,) PRIMARY KEY(t1)", + "CREATE TABLE t2 (t2 INT64 NOT NULL,) PRIMARY KEY(t2)", + }, + }, + After: map[string]interface{}{ + "ddl": []interface{}{ + "CREATE TABLE t1 (t1 INT64 NOT NULL,) PRIMARY KEY(t1)", + "CREATE TABLE t2 (t2 INT64 NOT NULL,) PRIMARY KEY(t2)", + }, + }, + } + resourceSpannerDBDdlCustomDiffFunc(d) + + if d.IsForceNew { + t.Errorf("Resource shouldn't ForceNew if older and new ddl statements are same") + } +} + +func TestSpannerDatabase_resourceSpannerDBDdlCustomDiffFuncOrderChange(t *testing.T) { + t.Parallel() + + d := &ResourceDiffMock{ + Before: map[string]interface{}{ + "ddl": []interface{}{ + "CREATE TABLE t1 (t1 INT64 NOT NULL,) PRIMARY KEY(t1)", + "CREATE TABLE t2 (t2 INT64 NOT NULL,) PRIMARY KEY(t2)", + "CREATE TABLE t3 (t3 INT64 NOT NULL,) PRIMARY KEY(t3)", + }, + }, + After: map[string]interface{}{ + "ddl": []interface{}{ + "CREATE TABLE t1 (t1 INT64 NOT NULL,) PRIMARY KEY(t1)", + "CREATE TABLE t3 (t3 INT64 NOT NULL,) PRIMARY KEY(t3)", + "CREATE TABLE t2 (t2 INT64 NOT NULL,) PRIMARY KEY(t2)", + }, + }, + } + resourceSpannerDBDdlCustomDiffFunc(d) + + if !d.IsForceNew { + t.Errorf("Resource should ForceNew if order of statments are different between older and new") + } +} + +func TestSpannerDatabase_resourceSpannerDBDdlCustomDiffFuncMissingStatements(t *testing.T) { + t.Parallel() + + d := &ResourceDiffMock{ + Before: map[string]interface{}{ + "ddl": []interface{}{ + "CREATE TABLE t1 (t1 INT64 NOT NULL,) PRIMARY KEY(t1)", + "CREATE TABLE t2 (t2 INT64 NOT NULL,) PRIMARY KEY(t2)", + "CREATE TABLE t3 (t3 INT64 NOT NULL,) PRIMARY KEY(t3)", + }, + }, + After: map[string]interface{}{ + "ddl": []interface{}{ + "CREATE TABLE t1 (t1 INT64 NOT NULL,) PRIMARY KEY(t1)", + "CREATE TABLE t2 (t2 INT64 NOT NULL,) PRIMARY KEY(t2)", + }, + }, + } + resourceSpannerDBDdlCustomDiffFunc(d) + + if !d.IsForceNew { + t.Errorf("Resource should ForceNew if older ddl statments are removed") + } } diff --git a/third_party/terraform/utils/test_utils.go b/third_party/terraform/utils/test_utils.go index 2b2e49a0f471..f43e067327d7 100644 --- a/third_party/terraform/utils/test_utils.go +++ b/third_party/terraform/utils/test_utils.go @@ -62,9 +62,10 @@ func (d *ResourceDataMock) Id() string { } type ResourceDiffMock struct { - Before map[string]interface{} - After map[string]interface{} - Cleared map[string]struct{} + Before map[string]interface{} + After map[string]interface{} + Cleared map[string]struct{} + IsForceNew bool } func (d *ResourceDiffMock) GetChange(key string) (interface{}, interface{}) { @@ -84,6 +85,7 @@ func (d *ResourceDiffMock) Clear(key string) error { } func (d *ResourceDiffMock) ForceNew(key string) error { + d.IsForceNew = true return nil } From 91e97a499bc66d4462ccd2cedbb4a1e7d94e224e Mon Sep 17 00:00:00 2001 From: venkykuberan Date: Fri, 11 Sep 2020 10:50:11 -0700 Subject: [PATCH 11/16] tests fixed --- .../tests/resource_spanner_database_test.go | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/third_party/terraform/tests/resource_spanner_database_test.go b/third_party/terraform/tests/resource_spanner_database_test.go index bdd4bd7708e7..ba7093f6151d 100644 --- a/third_party/terraform/tests/resource_spanner_database_test.go +++ b/third_party/terraform/tests/resource_spanner_database_test.go @@ -183,7 +183,10 @@ func TestSpannerDatabase_resourceSpannerDBDdlCustomDiffFuncNewStatements(t *test "CREATE TABLE t2 (t2 INT64 NOT NULL,) PRIMARY KEY(t2)"}, }, } - resourceSpannerDBDdlCustomDiffFunc(d) + err := resourceSpannerDBDdlCustomDiffFunc(d) + if err != nil { + t.Errorf("failed, expected no error but received one - %s", err) + } if d.IsForceNew { t.Errorf("Resource shouldn't ForceNew for new ddl statements append") @@ -207,7 +210,10 @@ func TestSpannerDatabase_resourceSpannerDBDdlCustomDiffFuncNoChange(t *testing.T }, }, } - resourceSpannerDBDdlCustomDiffFunc(d) + err := resourceSpannerDBDdlCustomDiffFunc(d) + if err != nil { + t.Errorf("failed, expected no error but received one - %s", err) + } if d.IsForceNew { t.Errorf("Resource shouldn't ForceNew if older and new ddl statements are same") @@ -233,7 +239,10 @@ func TestSpannerDatabase_resourceSpannerDBDdlCustomDiffFuncOrderChange(t *testin }, }, } - resourceSpannerDBDdlCustomDiffFunc(d) + err := resourceSpannerDBDdlCustomDiffFunc(d) + if err != nil { + t.Errorf("failed, expected no error but received one - %s", err) + } if !d.IsForceNew { t.Errorf("Resource should ForceNew if order of statments are different between older and new") @@ -258,7 +267,10 @@ func TestSpannerDatabase_resourceSpannerDBDdlCustomDiffFuncMissingStatements(t * }, }, } - resourceSpannerDBDdlCustomDiffFunc(d) + err := resourceSpannerDBDdlCustomDiffFunc(d) + if err != nil { + t.Errorf("failed, expected no error but received one - %s", err) + } if !d.IsForceNew { t.Errorf("Resource should ForceNew if older ddl statments are removed") From d9492e4900ecb594bde5307caa70ec1bd712b417 Mon Sep 17 00:00:00 2001 From: venkykuberan Date: Sun, 13 Sep 2020 22:23:36 -0700 Subject: [PATCH 12/16] PR comments implemented --- .../terraform/tests/resource_spanner_database_test.go | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/third_party/terraform/tests/resource_spanner_database_test.go b/third_party/terraform/tests/resource_spanner_database_test.go index ba7093f6151d..2202d07f4cd5 100644 --- a/third_party/terraform/tests/resource_spanner_database_test.go +++ b/third_party/terraform/tests/resource_spanner_database_test.go @@ -37,17 +37,6 @@ func TestAccSpannerDatabase_basic(t *testing.T) { resource.TestCheckResourceAttrSet("google_spanner_database.basic", "state"), ), }, - { - // Test import with default Terraform ID - ResourceName: "google_spanner_database.basic", - ImportState: true, - }, - { - Config: testAccSpannerDatabase_basicForceNew(instanceName, databaseName), - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttrSet("google_spanner_database.basic", "state"), - ), - }, { // Test import with default Terraform ID ResourceName: "google_spanner_database.basic", From 57fd94b445d67c9ec6357e646d0dd405135610b6 Mon Sep 17 00:00:00 2001 From: venkykuberan Date: Mon, 14 Sep 2020 14:57:34 -0700 Subject: [PATCH 13/16] unit tests converted to table driven tests --- .../tests/resource_spanner_database_test.go | 160 +++++------------- 1 file changed, 45 insertions(+), 115 deletions(-) diff --git a/third_party/terraform/tests/resource_spanner_database_test.go b/third_party/terraform/tests/resource_spanner_database_test.go index 2202d07f4cd5..becb6a45f826 100644 --- a/third_party/terraform/tests/resource_spanner_database_test.go +++ b/third_party/terraform/tests/resource_spanner_database_test.go @@ -106,26 +106,6 @@ resource "google_spanner_database" "basic" { `, instanceName, instanceName, databaseName) } -func testAccSpannerDatabase_basicForceNew(instanceName, databaseName string) string { - return fmt.Sprintf(` -resource "google_spanner_instance" "basic" { - name = "%s" - config = "regional-us-central1" - display_name = "display-%s" - num_nodes = 1 -} - -resource "google_spanner_database" "basic" { - instance = google_spanner_instance.basic.name - name = "%s" - ddl = [ - "CREATE TABLE t1 (t1 INT64 NOT NULL,) PRIMARY KEY(t1)", - "CREATE TABLE t3 (t3 INT64 NOT NULL,) PRIMARY KEY(t3)", - ] -} -`, instanceName, instanceName, databaseName) -} - // Unit Tests for type spannerDatabaseId func TestDatabaseNameForApi(t *testing.T) { id := spannerDatabaseId{ @@ -142,126 +122,76 @@ func TestDatabaseNameForApi(t *testing.T) { func TestSpannerDatabase_resourceSpannerDBDdlCustomDiffFuncForceNew(t *testing.T) { t.Parallel() - d := &ResourceDiffMock{ - Before: map[string]interface{}{ - "ddl": []interface{}{"CREATE TABLE t1 (t1 INT64 NOT NULL,) PRIMARY KEY(t1)"}, - }, - After: map[string]interface{}{ - "ddl": []interface{}{"CREATE TABLE t2 (t2 INT64 NOT NULL,) PRIMARY KEY(t2)"}, - }, - } - err := resourceSpannerDBDdlCustomDiffFunc(d) - if err != nil { - t.Errorf("failed, expected no error but received one - %s", err) - } - if !d.IsForceNew { - t.Errorf("Resource should ForceNew when older ddl statements are removed") - } -} - -func TestSpannerDatabase_resourceSpannerDBDdlCustomDiffFuncNewStatements(t *testing.T) { - t.Parallel() - - d := &ResourceDiffMock{ - Before: map[string]interface{}{ - "ddl": []interface{}{"CREATE TABLE t1 (t1 INT64 NOT NULL,) PRIMARY KEY(t1)"}, - }, - After: map[string]interface{}{ - "ddl": []interface{}{ - "CREATE TABLE t1 (t1 INT64 NOT NULL,) PRIMARY KEY(t1)", + cases := map[string]struct { + before interface{} + after interface{} + forcenew bool + }{ + "remove_old_statements": { + before: []interface{}{ + "CREATE TABLE t1 (t1 INT64 NOT NULL,) PRIMARY KEY(t1)"}, + after: []interface{}{ "CREATE TABLE t2 (t2 INT64 NOT NULL,) PRIMARY KEY(t2)"}, + forcenew: true, }, - } - err := resourceSpannerDBDdlCustomDiffFunc(d) - if err != nil { - t.Errorf("failed, expected no error but received one - %s", err) - } - - if d.IsForceNew { - t.Errorf("Resource shouldn't ForceNew for new ddl statements append") - } -} - -func TestSpannerDatabase_resourceSpannerDBDdlCustomDiffFuncNoChange(t *testing.T) { - t.Parallel() - - d := &ResourceDiffMock{ - Before: map[string]interface{}{ - "ddl": []interface{}{ + "append_new_statements": { + before: []interface{}{ + "CREATE TABLE t1 (t1 INT64 NOT NULL,) PRIMARY KEY(t1)"}, + after: []interface{}{ "CREATE TABLE t1 (t1 INT64 NOT NULL,) PRIMARY KEY(t1)", "CREATE TABLE t2 (t2 INT64 NOT NULL,) PRIMARY KEY(t2)", }, + forcenew: false, }, - After: map[string]interface{}{ - "ddl": []interface{}{ - "CREATE TABLE t1 (t1 INT64 NOT NULL,) PRIMARY KEY(t1)", - "CREATE TABLE t2 (t2 INT64 NOT NULL,) PRIMARY KEY(t2)", - }, + "no_change": { + before: []interface{}{ + "CREATE TABLE t1 (t1 INT64 NOT NULL,) PRIMARY KEY(t1)"}, + after: []interface{}{ + "CREATE TABLE t1 (t1 INT64 NOT NULL,) PRIMARY KEY(t1)"}, + forcenew: false, }, - } - err := resourceSpannerDBDdlCustomDiffFunc(d) - if err != nil { - t.Errorf("failed, expected no error but received one - %s", err) - } - - if d.IsForceNew { - t.Errorf("Resource shouldn't ForceNew if older and new ddl statements are same") - } -} - -func TestSpannerDatabase_resourceSpannerDBDdlCustomDiffFuncOrderChange(t *testing.T) { - t.Parallel() - - d := &ResourceDiffMock{ - Before: map[string]interface{}{ - "ddl": []interface{}{ + "order_of_statments_change": { + before: []interface{}{ "CREATE TABLE t1 (t1 INT64 NOT NULL,) PRIMARY KEY(t1)", "CREATE TABLE t2 (t2 INT64 NOT NULL,) PRIMARY KEY(t2)", "CREATE TABLE t3 (t3 INT64 NOT NULL,) PRIMARY KEY(t3)", }, - }, - After: map[string]interface{}{ - "ddl": []interface{}{ + after: []interface{}{ "CREATE TABLE t1 (t1 INT64 NOT NULL,) PRIMARY KEY(t1)", "CREATE TABLE t3 (t3 INT64 NOT NULL,) PRIMARY KEY(t3)", "CREATE TABLE t2 (t2 INT64 NOT NULL,) PRIMARY KEY(t2)", }, + forcenew: true, }, - } - err := resourceSpannerDBDdlCustomDiffFunc(d) - if err != nil { - t.Errorf("failed, expected no error but received one - %s", err) - } - - if !d.IsForceNew { - t.Errorf("Resource should ForceNew if order of statments are different between older and new") - } -} - -func TestSpannerDatabase_resourceSpannerDBDdlCustomDiffFuncMissingStatements(t *testing.T) { - t.Parallel() - - d := &ResourceDiffMock{ - Before: map[string]interface{}{ - "ddl": []interface{}{ + "missing_an_old_statement": { + before: []interface{}{ "CREATE TABLE t1 (t1 INT64 NOT NULL,) PRIMARY KEY(t1)", "CREATE TABLE t2 (t2 INT64 NOT NULL,) PRIMARY KEY(t2)", "CREATE TABLE t3 (t3 INT64 NOT NULL,) PRIMARY KEY(t3)", }, - }, - After: map[string]interface{}{ - "ddl": []interface{}{ + after: []interface{}{ "CREATE TABLE t1 (t1 INT64 NOT NULL,) PRIMARY KEY(t1)", "CREATE TABLE t2 (t2 INT64 NOT NULL,) PRIMARY KEY(t2)", }, + forcenew: true, }, } - err := resourceSpannerDBDdlCustomDiffFunc(d) - if err != nil { - t.Errorf("failed, expected no error but received one - %s", err) - } - if !d.IsForceNew { - t.Errorf("Resource should ForceNew if older ddl statments are removed") + for tn, tc := range cases { + d := &ResourceDiffMock{ + Before: map[string]interface{}{ + "ddl": tc.before, + }, + After: map[string]interface{}{ + "ddl": tc.after, + }, + } + err := resourceSpannerDBDdlCustomDiffFunc(d) + if err != nil { + t.Errorf("failed, expected no error but received - %s for the condition %s", err, tn) + } + if d.IsForceNew != tc.forcenew { + t.Errorf("ForceNew not setup correctly for the condition-'%s', expected:%v;actual:%v", tn, tc.forcenew, d.IsForceNew) + } } } From 441e226faad48dc085621a3ad44824d791b36a44 Mon Sep 17 00:00:00 2001 From: venkykuberan Date: Tue, 15 Sep 2020 12:18:16 -0700 Subject: [PATCH 14/16] ImportStateVerifyIgnore flag added to tests --- .../terraform/tests/resource_spanner_database_test.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/third_party/terraform/tests/resource_spanner_database_test.go b/third_party/terraform/tests/resource_spanner_database_test.go index becb6a45f826..278636d18fc4 100644 --- a/third_party/terraform/tests/resource_spanner_database_test.go +++ b/third_party/terraform/tests/resource_spanner_database_test.go @@ -30,6 +30,8 @@ func TestAccSpannerDatabase_basic(t *testing.T) { // Test import with default Terraform ID ResourceName: "google_spanner_database.basic", ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"ddl"} }, { Config: testAccSpannerDatabase_basicUpdate(instanceName, databaseName), @@ -42,24 +44,28 @@ func TestAccSpannerDatabase_basic(t *testing.T) { ResourceName: "google_spanner_database.basic", ImportState: true, ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"ddl"} }, { ResourceName: "google_spanner_database.basic", ImportStateId: fmt.Sprintf("projects/%s/instances/%s/databases/%s", project, instanceName, databaseName), ImportState: true, ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"ddl"} }, { ResourceName: "google_spanner_database.basic", ImportStateId: fmt.Sprintf("instances/%s/databases/%s", instanceName, databaseName), ImportState: true, ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"ddl"} }, { ResourceName: "google_spanner_database.basic", ImportStateId: fmt.Sprintf("%s/%s", instanceName, databaseName), ImportState: true, ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"ddl"} }, }, }) From d73d613c3a0d7a72aef6b562855dd0eef736fab8 Mon Sep 17 00:00:00 2001 From: venkykuberan Date: Tue, 15 Sep 2020 12:44:34 -0700 Subject: [PATCH 15/16] ImportStateVerifyIgnore flag added to tests --- .../terraform/tests/resource_spanner_database_test.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/third_party/terraform/tests/resource_spanner_database_test.go b/third_party/terraform/tests/resource_spanner_database_test.go index 278636d18fc4..da4ee35356a7 100644 --- a/third_party/terraform/tests/resource_spanner_database_test.go +++ b/third_party/terraform/tests/resource_spanner_database_test.go @@ -44,28 +44,28 @@ func TestAccSpannerDatabase_basic(t *testing.T) { ResourceName: "google_spanner_database.basic", ImportState: true, ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"ddl"} + ImportStateVerifyIgnore: []string{"ddl"}, }, { ResourceName: "google_spanner_database.basic", ImportStateId: fmt.Sprintf("projects/%s/instances/%s/databases/%s", project, instanceName, databaseName), ImportState: true, ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"ddl"} + ImportStateVerifyIgnore: []string{"ddl"}, }, { ResourceName: "google_spanner_database.basic", ImportStateId: fmt.Sprintf("instances/%s/databases/%s", instanceName, databaseName), ImportState: true, ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"ddl"} + ImportStateVerifyIgnore: []string{"ddl"}, }, { ResourceName: "google_spanner_database.basic", ImportStateId: fmt.Sprintf("%s/%s", instanceName, databaseName), ImportState: true, ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"ddl"} + ImportStateVerifyIgnore: []string{"ddl"}, }, }, }) From f5ce472df9092826cf1f19bee8393b3052fb6741 Mon Sep 17 00:00:00 2001 From: venkykuberan Date: Tue, 15 Sep 2020 12:57:51 -0700 Subject: [PATCH 16/16] syntax corrected in test --- .../tests/resource_spanner_database_test.go | 38 +++++++++---------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/third_party/terraform/tests/resource_spanner_database_test.go b/third_party/terraform/tests/resource_spanner_database_test.go index da4ee35356a7..54ba9f1efce8 100644 --- a/third_party/terraform/tests/resource_spanner_database_test.go +++ b/third_party/terraform/tests/resource_spanner_database_test.go @@ -28,10 +28,10 @@ func TestAccSpannerDatabase_basic(t *testing.T) { }, { // Test import with default Terraform ID - ResourceName: "google_spanner_database.basic", - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"ddl"} + ResourceName: "google_spanner_database.basic", + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"ddl"}, }, { Config: testAccSpannerDatabase_basicUpdate(instanceName, databaseName), @@ -41,30 +41,30 @@ func TestAccSpannerDatabase_basic(t *testing.T) { }, { // Test import with default Terraform ID - ResourceName: "google_spanner_database.basic", - ImportState: true, - ImportStateVerify: true, + ResourceName: "google_spanner_database.basic", + ImportState: true, + ImportStateVerify: true, ImportStateVerifyIgnore: []string{"ddl"}, }, { - ResourceName: "google_spanner_database.basic", - ImportStateId: fmt.Sprintf("projects/%s/instances/%s/databases/%s", project, instanceName, databaseName), - ImportState: true, - ImportStateVerify: true, + ResourceName: "google_spanner_database.basic", + ImportStateId: fmt.Sprintf("projects/%s/instances/%s/databases/%s", project, instanceName, databaseName), + ImportState: true, + ImportStateVerify: true, ImportStateVerifyIgnore: []string{"ddl"}, }, { - ResourceName: "google_spanner_database.basic", - ImportStateId: fmt.Sprintf("instances/%s/databases/%s", instanceName, databaseName), - ImportState: true, - ImportStateVerify: true, + ResourceName: "google_spanner_database.basic", + ImportStateId: fmt.Sprintf("instances/%s/databases/%s", instanceName, databaseName), + ImportState: true, + ImportStateVerify: true, ImportStateVerifyIgnore: []string{"ddl"}, }, { - ResourceName: "google_spanner_database.basic", - ImportStateId: fmt.Sprintf("%s/%s", instanceName, databaseName), - ImportState: true, - ImportStateVerify: true, + ResourceName: "google_spanner_database.basic", + ImportStateId: fmt.Sprintf("%s/%s", instanceName, databaseName), + ImportState: true, + ImportStateVerify: true, ImportStateVerifyIgnore: []string{"ddl"}, }, },