Skip to content

Commit 727d3fa

Browse files
feat(spanner): add support for defaultBackupScheduleType in spanner instance (#12254) (#20213)
[upstream:b551152e1e2375ddd6208b18c1970292b8ff583c] Signed-off-by: Modular Magician <[email protected]>
1 parent dcd2690 commit 727d3fa

File tree

5 files changed

+49
-0
lines changed

5 files changed

+49
-0
lines changed

.changelog/12254.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
spanner: added `default_backup_schedule_type` field to `google_spanner_instance`
3+
```

google/services/spanner/resource_spanner_instance.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,15 @@ This number is on a scale from 0 (no utilization) to 100 (full utilization).`,
283283
},
284284
ExactlyOneOf: []string{"num_nodes", "processing_units", "autoscaling_config"},
285285
},
286+
"default_backup_schedule_type": {
287+
Type: schema.TypeString,
288+
Computed: true,
289+
Optional: true,
290+
ValidateFunc: verify.ValidateEnum([]string{"NONE", "AUTOMATIC", ""}),
291+
Description: `Controls the default backup behavior for new databases within the instance.
292+
Note that 'AUTOMATIC' is not permitted for free instances, as backups and backup schedules are not allowed for free instances.
293+
if unset or NONE, no default backup schedule will be created for new databases within the instance. Possible values: ["NONE", "AUTOMATIC"]`,
294+
},
286295
"edition": {
287296
Type: schema.TypeString,
288297
Computed: true,
@@ -403,6 +412,12 @@ func resourceSpannerInstanceCreate(d *schema.ResourceData, meta interface{}) err
403412
} else if v, ok := d.GetOkExists("edition"); !tpgresource.IsEmptyValue(reflect.ValueOf(editionProp)) && (ok || !reflect.DeepEqual(v, editionProp)) {
404413
obj["edition"] = editionProp
405414
}
415+
defaultBackupScheduleTypeProp, err := expandSpannerInstanceDefaultBackupScheduleType(d.Get("default_backup_schedule_type"), d, config)
416+
if err != nil {
417+
return err
418+
} else if v, ok := d.GetOkExists("default_backup_schedule_type"); !tpgresource.IsEmptyValue(reflect.ValueOf(defaultBackupScheduleTypeProp)) && (ok || !reflect.DeepEqual(v, defaultBackupScheduleTypeProp)) {
419+
obj["defaultBackupScheduleType"] = defaultBackupScheduleTypeProp
420+
}
406421
labelsProp, err := expandSpannerInstanceEffectiveLabels(d.Get("effective_labels"), d, config)
407422
if err != nil {
408423
return err
@@ -585,6 +600,9 @@ func resourceSpannerInstanceRead(d *schema.ResourceData, meta interface{}) error
585600
if err := d.Set("edition", flattenSpannerInstanceEdition(res["edition"], d, config)); err != nil {
586601
return fmt.Errorf("Error reading Instance: %s", err)
587602
}
603+
if err := d.Set("default_backup_schedule_type", flattenSpannerInstanceDefaultBackupScheduleType(res["defaultBackupScheduleType"], d, config)); err != nil {
604+
return fmt.Errorf("Error reading Instance: %s", err)
605+
}
588606
if err := d.Set("terraform_labels", flattenSpannerInstanceTerraformLabels(res["labels"], d, config)); err != nil {
589607
return fmt.Errorf("Error reading Instance: %s", err)
590608
}
@@ -641,6 +659,12 @@ func resourceSpannerInstanceUpdate(d *schema.ResourceData, meta interface{}) err
641659
} else if v, ok := d.GetOkExists("edition"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, editionProp)) {
642660
obj["edition"] = editionProp
643661
}
662+
defaultBackupScheduleTypeProp, err := expandSpannerInstanceDefaultBackupScheduleType(d.Get("default_backup_schedule_type"), d, config)
663+
if err != nil {
664+
return err
665+
} else if v, ok := d.GetOkExists("default_backup_schedule_type"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, defaultBackupScheduleTypeProp)) {
666+
obj["defaultBackupScheduleType"] = defaultBackupScheduleTypeProp
667+
}
644668
labelsProp, err := expandSpannerInstanceEffectiveLabels(d.Get("effective_labels"), d, config)
645669
if err != nil {
646670
return err
@@ -1125,6 +1149,10 @@ func flattenSpannerInstanceEdition(v interface{}, d *schema.ResourceData, config
11251149
return v
11261150
}
11271151

1152+
func flattenSpannerInstanceDefaultBackupScheduleType(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
1153+
return v
1154+
}
1155+
11281156
func flattenSpannerInstanceTerraformLabels(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
11291157
if v == nil {
11301158
return v
@@ -1406,6 +1434,10 @@ func expandSpannerInstanceEdition(v interface{}, d tpgresource.TerraformResource
14061434
return v, nil
14071435
}
14081436

1437+
func expandSpannerInstanceDefaultBackupScheduleType(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
1438+
return v, nil
1439+
}
1440+
14091441
func expandSpannerInstanceEffectiveLabels(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (map[string]string, error) {
14101442
if v == nil {
14111443
return map[string]string{}, nil
@@ -1448,6 +1480,9 @@ func resourceSpannerInstanceUpdateEncoder(d *schema.ResourceData, meta interface
14481480
if d.HasChange("edition") {
14491481
updateMask = append(updateMask, "edition")
14501482
}
1483+
if d.HasChange("default_backup_schedule_type") {
1484+
updateMask = append(updateMask, "defaultBackupScheduleType")
1485+
}
14511486
if d.HasChange("num_nodes") {
14521487
updateMask = append(updateMask, "nodeCount")
14531488
}

google/services/spanner/resource_spanner_instance_generated_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ resource "google_spanner_instance" "example" {
6363
display_name = "Test Spanner Instance"
6464
num_nodes = 2
6565
edition = "STANDARD"
66+
default_backup_schedule_type = "AUTOMATIC"
6667
labels = {
6768
"foo" = "bar"
6869
}

google/services/spanner/resource_spanner_instance_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,7 @@ resource "google_spanner_instance" "basic" {
369369
display_name = "%s-dname"
370370
num_nodes = 1
371371
edition = "ENTERPRISE"
372+
default_backup_schedule_type = "NONE"
372373
}
373374
`, name, name)
374375
}
@@ -462,6 +463,7 @@ resource "google_spanner_instance" "basic" {
462463
}
463464
}
464465
edition = "ENTERPRISE"
466+
default_backup_schedule_type = "AUTOMATIC"
465467
}
466468
`, name, name, maxProcessingUnits, minProcessingUnits, cupUtilizationPercent, storageUtilizationPercent)
467469
}

website/docs/r/spanner_instance.html.markdown

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ resource "google_spanner_instance" "example" {
4444
display_name = "Test Spanner Instance"
4545
num_nodes = 2
4646
edition = "STANDARD"
47+
default_backup_schedule_type = "AUTOMATIC"
4748
labels = {
4849
"foo" = "bar"
4950
}
@@ -177,6 +178,13 @@ The following arguments are supported:
177178
The edition selected for this instance. Different editions provide different capabilities at different price points.
178179
Possible values are: `EDITION_UNSPECIFIED`, `STANDARD`, `ENTERPRISE`, `ENTERPRISE_PLUS`.
179180

181+
* `default_backup_schedule_type` -
182+
(Optional)
183+
Controls the default backup behavior for new databases within the instance.
184+
Note that `AUTOMATIC` is not permitted for free instances, as backups and backup schedules are not allowed for free instances.
185+
if unset or NONE, no default backup schedule will be created for new databases within the instance.
186+
Possible values are: `NONE`, `AUTOMATIC`.
187+
180188
* `project` - (Optional) The ID of the project in which the resource belongs.
181189
If it is not provided, the provider project is used.
182190

0 commit comments

Comments
 (0)