Skip to content

Commit

Permalink
Add support for processing_units to google_spanner_instance (#4993)
Browse files Browse the repository at this point in the history
Co-authored-by: upodroid <[email protected]>
Co-authored-by: Cameron Thornton <[email protected]>
  • Loading branch information
upodroid and c2thorn authored Aug 3, 2021
1 parent 509318c commit d9c69c1
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 3 deletions.
11 changes: 8 additions & 3 deletions mmv1/products/spanner/api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down Expand Up @@ -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.
8 changes: 8 additions & 0 deletions mmv1/products/spanner/terraform.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions mmv1/templates/terraform/encoders/spanner_instance.go.erb
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
resource "google_spanner_instance" "example" {
config = "regional-us-central1"
display_name = "Test Spanner Instance"
processing_units = 200
labels = {
"foo" = "bar"
}
}
34 changes: 34 additions & 0 deletions mmv1/third_party/terraform/tests/resource_spanner_instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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" {
Expand Down

0 comments on commit d9c69c1

Please sign in to comment.