Skip to content

Commit 1cc9897

Browse files
authored
feat(spanner): add instance asymmetric autoscaling options support in spanner instance resource (#12100)
1 parent 075e151 commit 1cc9897

File tree

3 files changed

+145
-1
lines changed

3 files changed

+145
-1
lines changed

mmv1/products/spanner/Instance.yaml

+34
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,40 @@ properties:
228228
should be trying to achieve for the instance.
229229
This number is on a scale from 0 (no utilization) to 100 (full utilization).
230230
231+
- name: 'asymmetricAutoscalingOptions'
232+
type: Array
233+
description: |
234+
Asymmetric autoscaling options for specific replicas.
235+
item_type:
236+
type: NestedObject
237+
properties:
238+
- name: 'replicaSelection'
239+
type: NestedObject
240+
required: true
241+
properties:
242+
- name: 'location'
243+
type: String
244+
required: true
245+
description: |
246+
The location of the replica to apply asymmetric autoscaling options.
247+
- name: 'overrides'
248+
type: NestedObject
249+
required: true
250+
properties:
251+
- name: 'autoscalingLimits'
252+
type: NestedObject
253+
required: true
254+
properties:
255+
- name: 'minNodes'
256+
type: Integer
257+
required: true
258+
description: |
259+
The minimum number of nodes for this specific replica.
260+
- name: 'maxNodes'
261+
type: Integer
262+
required: true
263+
description: |
264+
The maximum number of nodes for this specific replica.
231265
- name: 'edition'
232266
type: Enum
233267
description: |

mmv1/templates/terraform/encoders/spanner_instance_update.go.tmpl

+3
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ if d.HasChange("autoscaling_config") {
4646
if d.HasChange("autoscaling_config.0.autoscaling_targets.0.storage_utilization_percent") {
4747
updateMask = append(updateMask, "autoscalingConfig.autoscalingTargets.storageUtilizationPercent")
4848
}
49+
if d.HasChange("autoscaling_config.0.asymmetric_autoscaling_options") {
50+
updateMask = append(updateMask, "autoscalingConfig.asymmetricAutoscalingOptions")
51+
}
4952
}
5053
}
5154
newObj["fieldMask"] = strings.Join(updateMask, ",")

mmv1/third_party/terraform/services/spanner/resource_spanner_instance_test.go

+108-1
Original file line numberDiff line numberDiff line change
@@ -312,14 +312,61 @@ func TestAccSpannerInstance_basicWithAutoscalingUsingNodeConfigUpdate(t *testing
312312
})
313313
}
314314

315+
func TestAccSpannerInstance_basicWithAsymmetricAutoscalingConfigsUpdate(t *testing.T) {
316+
displayName := fmt.Sprintf("tf-test-%s", acctest.RandString(t, 10))
317+
acctest.VcrTest(t, resource.TestCase{
318+
PreCheck: func() { acctest.AccTestPreCheck(t) },
319+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
320+
CheckDestroy: testAccCheckSpannerInstanceDestroyProducer(t),
321+
Steps: []resource.TestStep{
322+
{
323+
Config: testAccSpannerInstance_main(displayName),
324+
Check: resource.ComposeTestCheckFunc(
325+
resource.TestCheckResourceAttrSet("google_spanner_instance.main", "state"),
326+
),
327+
},
328+
{
329+
ResourceName: "google_spanner_instance.main",
330+
ImportState: true,
331+
ImportStateVerify: true,
332+
ImportStateVerifyIgnore: []string{"labels", "terraform_labels"},
333+
},
334+
{
335+
Config: testAccSpannerInstance_basicWithAsymmetricAutoscalingConfigsUpdate(displayName, 1, 10),
336+
Check: resource.ComposeTestCheckFunc(
337+
resource.TestCheckResourceAttrSet("google_spanner_instance.main", "state"),
338+
),
339+
},
340+
{
341+
ResourceName: "google_spanner_instance.main",
342+
ImportState: true,
343+
ImportStateVerify: true,
344+
ImportStateVerifyIgnore: []string{"labels", "terraform_labels"},
345+
},
346+
{
347+
Config: testAccSpannerInstance_basicWithAsymmetricAutoscalingConfigsUpdate(displayName, 3, 5),
348+
Check: resource.ComposeTestCheckFunc(
349+
resource.TestCheckResourceAttrSet("google_spanner_instance.main", "state"),
350+
),
351+
},
352+
{
353+
ResourceName: "google_spanner_instance.main",
354+
ImportState: true,
355+
ImportStateVerify: true,
356+
ImportStateVerifyIgnore: []string{"labels", "terraform_labels"},
357+
},
358+
},
359+
})
360+
}
361+
315362
func testAccSpannerInstance_basic(name string) string {
316363
return fmt.Sprintf(`
317364
resource "google_spanner_instance" "basic" {
318365
name = "%s"
319366
config = "regional-us-central1"
320367
display_name = "%s-dname"
321368
num_nodes = 1
322-
edition = "ENTERPRISE"
369+
edition = "ENTERPRISE"
323370
}
324371
`, name, name)
325372
}
@@ -458,3 +505,63 @@ resource "google_spanner_instance" "basic" {
458505
}
459506
`, name, name, maxNodes, minNodes, cupUtilizationPercent, storageUtilizationPercent)
460507
}
508+
509+
func testAccSpannerInstance_main(name string) string {
510+
return fmt.Sprintf(`
511+
resource "google_spanner_instance" "main" {
512+
name = "%s"
513+
config = "nam-eur-asia3"
514+
display_name = "%s"
515+
num_nodes = 1
516+
edition = "ENTERPRISE_PLUS"
517+
}
518+
`, name, name)
519+
}
520+
521+
func testAccSpannerInstance_basicWithAsymmetricAutoscalingConfigsUpdate(name string, minNodes, maxNodes int) string {
522+
return fmt.Sprintf(`
523+
provider "google" {
524+
alias = "user-project-override"
525+
user_project_override = true
526+
}
527+
528+
resource "google_spanner_instance" "main" {
529+
provider = google.user-project-override
530+
name = "%s"
531+
config = "nam-eur-asia3"
532+
display_name = "%s"
533+
autoscaling_config {
534+
autoscaling_limits {
535+
max_nodes = 3
536+
min_nodes = 1
537+
}
538+
autoscaling_targets {
539+
high_priority_cpu_utilization_percent = 75
540+
storage_utilization_percent = 90
541+
}
542+
asymmetric_autoscaling_options {
543+
replica_selection {
544+
location = "europe-west1"
545+
}
546+
overrides {
547+
autoscaling_limits {
548+
min_nodes = 3
549+
max_nodes = 30
550+
}
551+
}
552+
}
553+
asymmetric_autoscaling_options {
554+
replica_selection {
555+
location = "asia-east1"
556+
}
557+
overrides {
558+
autoscaling_limits {
559+
min_nodes = %d
560+
max_nodes = %d
561+
}
562+
}
563+
}
564+
}
565+
edition = "ENTERPRISE_PLUS"
566+
}`, name, name, minNodes, maxNodes)
567+
}

0 commit comments

Comments
 (0)