From 425e09571c75127865efda09e33954b1e8dc2fc8 Mon Sep 17 00:00:00 2001 From: Mahamed Date: Tue, 3 Aug 2021 23:04:09 +0100 Subject: [PATCH] Add support for `processing_units` to `google_spanner_instance` (#4993) Co-authored-by: upodroid Co-authored-by: Cameron Thornton --- mmv1/products/spanner/api.yaml | 11 ++++-- mmv1/products/spanner/terraform.yaml | 8 +++++ .../encoders/spanner_instance.go.erb | 4 +++ .../spanner_instance_processing_units.tf.erb | 8 +++++ .../tests/resource_spanner_instance_test.go | 34 +++++++++++++++++++ 5 files changed, 62 insertions(+), 3 deletions(-) create mode 100644 mmv1/templates/terraform/examples/spanner_instance_processing_units.tf.erb diff --git a/mmv1/products/spanner/api.yaml b/mmv1/products/spanner/api.yaml index 52e73f4e12b6..33ea9c230c6c 100644 --- a/mmv1/products/spanner/api.yaml +++ b/mmv1/products/spanner/api.yaml @@ -102,8 +102,14 @@ objects: required: true - !ruby/object:Api::Type::Integer name: 'nodeCount' - description: 'The number of nodes allocated to this instance.' - default_value: 1 + description: | + The number of nodes allocated to this instance. At most one of either node_count or processing_units + can be present in terraform. + - !ruby/object:Api::Type::Integer + name: 'processingUnits' + description: | + The number of processing units allocated to this instance. At most one of processing_units + or node_count can be present in terraform. - !ruby/object:Api::Type::KeyValuePairs name: 'labels' description: | @@ -197,4 +203,3 @@ objects: description: | Fully qualified name of the KMS key to use to encrypt this database. This key must exist in the same location as the Spanner Database. - diff --git a/mmv1/products/spanner/terraform.yaml b/mmv1/products/spanner/terraform.yaml index 56adc332daf4..5dea49730e89 100644 --- a/mmv1/products/spanner/terraform.yaml +++ b/mmv1/products/spanner/terraform.yaml @@ -81,6 +81,11 @@ overrides: !ruby/object:Overrides::ResourceOverrides primary_resource_id: "example" # Randomness skip_vcr: true + - !ruby/object:Provider::Terraform::Examples + name: "spanner_instance_processing_units" + primary_resource_id: "example" + # Randomness + skip_vcr: true - !ruby/object:Provider::Terraform::Examples name: "spanner_instance_multi_regional" primary_resource_id: "example" @@ -108,6 +113,9 @@ overrides: !ruby/object:Overrides::ResourceOverrides custom_flatten: 'templates/terraform/custom_flatten/name_from_self_link.erb' nodeCount: !ruby/object:Overrides::Terraform::PropertyOverride name: num_nodes + default_from_api: true + processingUnits: !ruby/object:Overrides::Terraform::PropertyOverride + default_from_api: true config: !ruby/object:Overrides::Terraform::PropertyOverride custom_expand: templates/terraform/custom_expand/spanner_instance_config.go.erb state: !ruby/object:Overrides::Terraform::PropertyOverride diff --git a/mmv1/templates/terraform/encoders/spanner_instance.go.erb b/mmv1/templates/terraform/encoders/spanner_instance.go.erb index f5c189b777ca..2a7df752ee8f 100644 --- a/mmv1/templates/terraform/encoders/spanner_instance.go.erb +++ b/mmv1/templates/terraform/encoders/spanner_instance.go.erb @@ -1,3 +1,7 @@ +// Temp Logic to accomodate processing_units and num_nodes +if obj["processingUnits"] == nil && obj["nodeCount"] == nil { + obj["nodeCount"] = 1 +} newObj := make(map[string]interface{}) newObj["instance"] = obj if obj["name"] == nil { diff --git a/mmv1/templates/terraform/examples/spanner_instance_processing_units.tf.erb b/mmv1/templates/terraform/examples/spanner_instance_processing_units.tf.erb new file mode 100644 index 000000000000..b26e40e59763 --- /dev/null +++ b/mmv1/templates/terraform/examples/spanner_instance_processing_units.tf.erb @@ -0,0 +1,8 @@ +resource "google_spanner_instance" "example" { + config = "regional-us-central1" + display_name = "Test Spanner Instance" + processing_units = 200 + labels = { + "foo" = "bar" + } +} diff --git a/mmv1/third_party/terraform/tests/resource_spanner_instance_test.go b/mmv1/third_party/terraform/tests/resource_spanner_instance_test.go index 1754eb77d498..f7dd4c1f6443 100644 --- a/mmv1/third_party/terraform/tests/resource_spanner_instance_test.go +++ b/mmv1/third_party/terraform/tests/resource_spanner_instance_test.go @@ -71,6 +71,30 @@ func TestAccSpannerInstance_basic(t *testing.T) { }) } +func TestAccSpannerInstance_noNodeCountSpecified(t *testing.T) { + t.Parallel() + + idName := fmt.Sprintf("spanner-test-%s", randString(t, 10)) + vcrTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckSpannerInstanceDestroyProducer(t), + Steps: []resource.TestStep{ + { + Config: testAccSpannerInstance_noNodeCountSpecified(idName), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrSet("google_spanner_instance.basic", "state"), + ), + }, + { + ResourceName: "google_spanner_instance.basic", + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + func TestAccSpannerInstance_basicWithAutogenName(t *testing.T) { // Randomness skipIfVcr(t) @@ -140,6 +164,16 @@ resource "google_spanner_instance" "basic" { `, name, name) } +func testAccSpannerInstance_noNodeCountSpecified(name string) string { + return fmt.Sprintf(` +resource "google_spanner_instance" "basic" { + name = "%s" + config = "regional-us-central1" + display_name = "%s-dname" +} +`, name, name) +} + func testAccSpannerInstance_basicWithAutogenName(name string) string { return fmt.Sprintf(` resource "google_spanner_instance" "basic" {