Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(spanner): add support for defaultBackupScheduleType in spanner instance #20213

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/12254.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
spanner: added `default_backup_schedule_type` field to `google_spanner_instance`
```
35 changes: 35 additions & 0 deletions google/services/spanner/resource_spanner_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,15 @@ This number is on a scale from 0 (no utilization) to 100 (full utilization).`,
},
ExactlyOneOf: []string{"num_nodes", "processing_units", "autoscaling_config"},
},
"default_backup_schedule_type": {
Type: schema.TypeString,
Computed: true,
Optional: true,
ValidateFunc: verify.ValidateEnum([]string{"NONE", "AUTOMATIC", ""}),
Description: `Controls the default backup behavior for new databases within the instance.
Note that 'AUTOMATIC' is not permitted for free instances, as backups and backup schedules are not allowed for free instances.
if unset or NONE, no default backup schedule will be created for new databases within the instance. Possible values: ["NONE", "AUTOMATIC"]`,
},
"edition": {
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -403,6 +412,12 @@ func resourceSpannerInstanceCreate(d *schema.ResourceData, meta interface{}) err
} else if v, ok := d.GetOkExists("edition"); !tpgresource.IsEmptyValue(reflect.ValueOf(editionProp)) && (ok || !reflect.DeepEqual(v, editionProp)) {
obj["edition"] = editionProp
}
defaultBackupScheduleTypeProp, err := expandSpannerInstanceDefaultBackupScheduleType(d.Get("default_backup_schedule_type"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("default_backup_schedule_type"); !tpgresource.IsEmptyValue(reflect.ValueOf(defaultBackupScheduleTypeProp)) && (ok || !reflect.DeepEqual(v, defaultBackupScheduleTypeProp)) {
obj["defaultBackupScheduleType"] = defaultBackupScheduleTypeProp
}
labelsProp, err := expandSpannerInstanceEffectiveLabels(d.Get("effective_labels"), d, config)
if err != nil {
return err
Expand Down Expand Up @@ -585,6 +600,9 @@ func resourceSpannerInstanceRead(d *schema.ResourceData, meta interface{}) error
if err := d.Set("edition", flattenSpannerInstanceEdition(res["edition"], d, config)); err != nil {
return fmt.Errorf("Error reading Instance: %s", err)
}
if err := d.Set("default_backup_schedule_type", flattenSpannerInstanceDefaultBackupScheduleType(res["defaultBackupScheduleType"], d, config)); err != nil {
return fmt.Errorf("Error reading Instance: %s", err)
}
if err := d.Set("terraform_labels", flattenSpannerInstanceTerraformLabels(res["labels"], d, config)); err != nil {
return fmt.Errorf("Error reading Instance: %s", err)
}
Expand Down Expand Up @@ -641,6 +659,12 @@ func resourceSpannerInstanceUpdate(d *schema.ResourceData, meta interface{}) err
} else if v, ok := d.GetOkExists("edition"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, editionProp)) {
obj["edition"] = editionProp
}
defaultBackupScheduleTypeProp, err := expandSpannerInstanceDefaultBackupScheduleType(d.Get("default_backup_schedule_type"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("default_backup_schedule_type"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, defaultBackupScheduleTypeProp)) {
obj["defaultBackupScheduleType"] = defaultBackupScheduleTypeProp
}
labelsProp, err := expandSpannerInstanceEffectiveLabels(d.Get("effective_labels"), d, config)
if err != nil {
return err
Expand Down Expand Up @@ -1125,6 +1149,10 @@ func flattenSpannerInstanceEdition(v interface{}, d *schema.ResourceData, config
return v
}

func flattenSpannerInstanceDefaultBackupScheduleType(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
return v
}

func flattenSpannerInstanceTerraformLabels(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
if v == nil {
return v
Expand Down Expand Up @@ -1406,6 +1434,10 @@ func expandSpannerInstanceEdition(v interface{}, d tpgresource.TerraformResource
return v, nil
}

func expandSpannerInstanceDefaultBackupScheduleType(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
return v, nil
}

func expandSpannerInstanceEffectiveLabels(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (map[string]string, error) {
if v == nil {
return map[string]string{}, nil
Expand Down Expand Up @@ -1448,6 +1480,9 @@ func resourceSpannerInstanceUpdateEncoder(d *schema.ResourceData, meta interface
if d.HasChange("edition") {
updateMask = append(updateMask, "edition")
}
if d.HasChange("default_backup_schedule_type") {
updateMask = append(updateMask, "defaultBackupScheduleType")
}
if d.HasChange("num_nodes") {
updateMask = append(updateMask, "nodeCount")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ resource "google_spanner_instance" "example" {
display_name = "Test Spanner Instance"
num_nodes = 2
edition = "STANDARD"
default_backup_schedule_type = "AUTOMATIC"
labels = {
"foo" = "bar"
}
Expand Down
2 changes: 2 additions & 0 deletions google/services/spanner/resource_spanner_instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,7 @@ resource "google_spanner_instance" "basic" {
display_name = "%s-dname"
num_nodes = 1
edition = "ENTERPRISE"
default_backup_schedule_type = "NONE"
}
`, name, name)
}
Expand Down Expand Up @@ -462,6 +463,7 @@ resource "google_spanner_instance" "basic" {
}
}
edition = "ENTERPRISE"
default_backup_schedule_type = "AUTOMATIC"
}
`, name, name, maxProcessingUnits, minProcessingUnits, cupUtilizationPercent, storageUtilizationPercent)
}
Expand Down
8 changes: 8 additions & 0 deletions website/docs/r/spanner_instance.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ resource "google_spanner_instance" "example" {
display_name = "Test Spanner Instance"
num_nodes = 2
edition = "STANDARD"
default_backup_schedule_type = "AUTOMATIC"
labels = {
"foo" = "bar"
}
Expand Down Expand Up @@ -177,6 +178,13 @@ The following arguments are supported:
The edition selected for this instance. Different editions provide different capabilities at different price points.
Possible values are: `EDITION_UNSPECIFIED`, `STANDARD`, `ENTERPRISE`, `ENTERPRISE_PLUS`.

* `default_backup_schedule_type` -
(Optional)
Controls the default backup behavior for new databases within the instance.
Note that `AUTOMATIC` is not permitted for free instances, as backups and backup schedules are not allowed for free instances.
if unset or NONE, no default backup schedule will be created for new databases within the instance.
Possible values are: `NONE`, `AUTOMATIC`.

* `project` - (Optional) The ID of the project in which the resource belongs.
If it is not provided, the provider project is used.

Expand Down