diff --git a/.changelog/12254.txt b/.changelog/12254.txt new file mode 100644 index 0000000000..8b92b959fd --- /dev/null +++ b/.changelog/12254.txt @@ -0,0 +1,3 @@ +```release-note:enhancement +spanner: added `default_backup_schedule_type` field to `google_spanner_instance` +``` \ No newline at end of file diff --git a/google-beta/services/spanner/resource_spanner_instance.go b/google-beta/services/spanner/resource_spanner_instance.go index 5615d3e2de..dd295ad1f3 100644 --- a/google-beta/services/spanner/resource_spanner_instance.go +++ b/google-beta/services/spanner/resource_spanner_instance.go @@ -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, @@ -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 @@ -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) } @@ -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 @@ -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 @@ -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 @@ -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") } diff --git a/google-beta/services/spanner/resource_spanner_instance_generated_test.go b/google-beta/services/spanner/resource_spanner_instance_generated_test.go index ef4cf97c01..9160b361d8 100644 --- a/google-beta/services/spanner/resource_spanner_instance_generated_test.go +++ b/google-beta/services/spanner/resource_spanner_instance_generated_test.go @@ -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" } diff --git a/google-beta/services/spanner/resource_spanner_instance_test.go b/google-beta/services/spanner/resource_spanner_instance_test.go index 54cdac3548..730baa6794 100644 --- a/google-beta/services/spanner/resource_spanner_instance_test.go +++ b/google-beta/services/spanner/resource_spanner_instance_test.go @@ -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) } @@ -462,6 +463,7 @@ resource "google_spanner_instance" "basic" { } } edition = "ENTERPRISE" + default_backup_schedule_type = "AUTOMATIC" } `, name, name, maxProcessingUnits, minProcessingUnits, cupUtilizationPercent, storageUtilizationPercent) } diff --git a/website/docs/r/spanner_instance.html.markdown b/website/docs/r/spanner_instance.html.markdown index 5fb750b724..617d98e5bb 100644 --- a/website/docs/r/spanner_instance.html.markdown +++ b/website/docs/r/spanner_instance.html.markdown @@ -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" } @@ -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.