From da0e7684e1838f189f204332d625f1eee92b50fe Mon Sep 17 00:00:00 2001 From: Modular Magician Date: Fri, 30 Sep 2022 12:25:38 +0000 Subject: [PATCH] bigqueryreservation: move beta to v1 + add fields (#6567) * move to v1 + fields * default value Signed-off-by: Modular Magician --- .changelog/6567.txt | 3 + google/resource_bigquery_reservation.go | 79 +++++++++++++++++++ ...rce_bigquery_reservation_generated_test.go | 3 +- .../docs/r/bigquery_reservation.html.markdown | 14 +++- 4 files changed, 96 insertions(+), 3 deletions(-) create mode 100644 .changelog/6567.txt diff --git a/.changelog/6567.txt b/.changelog/6567.txt new file mode 100644 index 00000000000..bb1f32964ef --- /dev/null +++ b/.changelog/6567.txt @@ -0,0 +1,3 @@ +```release-note:enhancement +bigqueryreservation: add `concurrency` and `multiRegionAuxiliary` to `google_bigquery_reservation` +``` diff --git a/google/resource_bigquery_reservation.go b/google/resource_bigquery_reservation.go index 1f20e60ccbb..e7847105d45 100644 --- a/google/resource_bigquery_reservation.go +++ b/google/resource_bigquery_reservation.go @@ -54,6 +54,12 @@ func resourceBigqueryReservationReservation() *schema.Resource { Description: `Minimum slots available to this reservation. A slot is a unit of computational power in BigQuery, and serves as the unit of parallelism. Queries using this reservation might use more slots during runtime if ignoreIdleSlots is set to false.`, }, + "concurrency": { + Type: schema.TypeInt, + Optional: true, + Description: `Maximum number of queries that are allowed to run concurrently in this reservation. This is a soft limit due to asynchronous nature of the system and various optimizations for small queries. Default value is 0 which means that concurrency will be automatically set based on the reservation size.`, + Default: 0, + }, "ignore_idle_slots": { Type: schema.TypeBool, Optional: true, @@ -70,6 +76,12 @@ capacity specified above at most.`, Examples: US, EU, asia-northeast1. The default value is US.`, Default: "US", }, + "multi_region_auxiliary": { + Type: schema.TypeBool, + Optional: true, + Description: `Applicable only for reservations located within one of the BigQuery multi-regions (US or EU). +If set to true, this reservation is placed in the organization's secondary region which is designated for disaster recovery purposes. If false, this reservation is placed in the organization's default region.`, + }, "project": { Type: schema.TypeString, Optional: true, @@ -101,6 +113,18 @@ func resourceBigqueryReservationReservationCreate(d *schema.ResourceData, meta i } else if v, ok := d.GetOkExists("ignore_idle_slots"); !isEmptyValue(reflect.ValueOf(ignoreIdleSlotsProp)) && (ok || !reflect.DeepEqual(v, ignoreIdleSlotsProp)) { obj["ignoreIdleSlots"] = ignoreIdleSlotsProp } + concurrencyProp, err := expandBigqueryReservationReservationConcurrency(d.Get("concurrency"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("concurrency"); !isEmptyValue(reflect.ValueOf(concurrencyProp)) && (ok || !reflect.DeepEqual(v, concurrencyProp)) { + obj["concurrency"] = concurrencyProp + } + multiRegionAuxiliaryProp, err := expandBigqueryReservationReservationMultiRegionAuxiliary(d.Get("multi_region_auxiliary"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("multi_region_auxiliary"); !isEmptyValue(reflect.ValueOf(multiRegionAuxiliaryProp)) && (ok || !reflect.DeepEqual(v, multiRegionAuxiliaryProp)) { + obj["multiRegionAuxiliary"] = multiRegionAuxiliaryProp + } url, err := replaceVars(d, config, "{{BigqueryReservationBasePath}}projects/{{project}}/locations/{{location}}/reservations?reservationId={{name}}") if err != nil { @@ -178,6 +202,12 @@ func resourceBigqueryReservationReservationRead(d *schema.ResourceData, meta int if err := d.Set("ignore_idle_slots", flattenBigqueryReservationReservationIgnoreIdleSlots(res["ignoreIdleSlots"], d, config)); err != nil { return fmt.Errorf("Error reading Reservation: %s", err) } + if err := d.Set("concurrency", flattenBigqueryReservationReservationConcurrency(res["concurrency"], d, config)); err != nil { + return fmt.Errorf("Error reading Reservation: %s", err) + } + if err := d.Set("multi_region_auxiliary", flattenBigqueryReservationReservationMultiRegionAuxiliary(res["multiRegionAuxiliary"], d, config)); err != nil { + return fmt.Errorf("Error reading Reservation: %s", err) + } return nil } @@ -210,6 +240,18 @@ func resourceBigqueryReservationReservationUpdate(d *schema.ResourceData, meta i } else if v, ok := d.GetOkExists("ignore_idle_slots"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, ignoreIdleSlotsProp)) { obj["ignoreIdleSlots"] = ignoreIdleSlotsProp } + concurrencyProp, err := expandBigqueryReservationReservationConcurrency(d.Get("concurrency"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("concurrency"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, concurrencyProp)) { + obj["concurrency"] = concurrencyProp + } + multiRegionAuxiliaryProp, err := expandBigqueryReservationReservationMultiRegionAuxiliary(d.Get("multi_region_auxiliary"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("multi_region_auxiliary"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, multiRegionAuxiliaryProp)) { + obj["multiRegionAuxiliary"] = multiRegionAuxiliaryProp + } url, err := replaceVars(d, config, "{{BigqueryReservationBasePath}}projects/{{project}}/locations/{{location}}/reservations/{{name}}") if err != nil { @@ -226,6 +268,14 @@ func resourceBigqueryReservationReservationUpdate(d *schema.ResourceData, meta i if d.HasChange("ignore_idle_slots") { updateMask = append(updateMask, "ignoreIdleSlots") } + + if d.HasChange("concurrency") { + updateMask = append(updateMask, "concurrency") + } + + if d.HasChange("multi_region_auxiliary") { + updateMask = append(updateMask, "multiRegionAuxiliary") + } // updateMask is a URL parameter but not present in the schema, so replaceVars // won't set it url, err = addQueryParams(url, map[string]string{"updateMask": strings.Join(updateMask, ",")}) @@ -327,6 +377,27 @@ func flattenBigqueryReservationReservationIgnoreIdleSlots(v interface{}, d *sche return v } +func flattenBigqueryReservationReservationConcurrency(v interface{}, d *schema.ResourceData, config *Config) interface{} { + // Handles the string fixed64 format + if strVal, ok := v.(string); ok { + if intVal, err := stringToFixed64(strVal); err == nil { + return intVal + } + } + + // number values are represented as float64 + if floatVal, ok := v.(float64); ok { + intVal := int(floatVal) + return intVal + } + + return v // let terraform core handle it otherwise +} + +func flattenBigqueryReservationReservationMultiRegionAuxiliary(v interface{}, d *schema.ResourceData, config *Config) interface{} { + return v +} + func expandBigqueryReservationReservationSlotCapacity(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { return v, nil } @@ -334,3 +405,11 @@ func expandBigqueryReservationReservationSlotCapacity(v interface{}, d Terraform func expandBigqueryReservationReservationIgnoreIdleSlots(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { return v, nil } + +func expandBigqueryReservationReservationConcurrency(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandBigqueryReservationReservationMultiRegionAuxiliary(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} diff --git a/google/resource_bigquery_reservation_generated_test.go b/google/resource_bigquery_reservation_generated_test.go index 66739291c1c..40984154231 100644 --- a/google/resource_bigquery_reservation_generated_test.go +++ b/google/resource_bigquery_reservation_generated_test.go @@ -55,8 +55,9 @@ resource "google_bigquery_reservation" "reservation" { location = "asia-northeast1" // Set to 0 for testing purposes // In reality this would be larger than zero - slot_capacity = 0 + slot_capacity = 0 ignore_idle_slots = false + concurrency = 0 } `, context) } diff --git a/website/docs/r/bigquery_reservation.html.markdown b/website/docs/r/bigquery_reservation.html.markdown index cf4c93bfdc3..36eecbeea9f 100644 --- a/website/docs/r/bigquery_reservation.html.markdown +++ b/website/docs/r/bigquery_reservation.html.markdown @@ -25,7 +25,7 @@ A reservation is a mechanism used to guarantee BigQuery slots to users. To get more information about Reservation, see: -* [API documentation](https://cloud.google.com/bigquery/docs/reference/reservations/rest/v1beta1/projects.locations.reservations/create) +* [API documentation](https://cloud.google.com/bigquery/docs/reference/reservations/rest/v1/projects.locations.reservations/create) * How-to Guides * [Introduction to Reservations](https://cloud.google.com/bigquery/docs/reservations-intro) @@ -43,8 +43,9 @@ resource "google_bigquery_reservation" "reservation" { location = "asia-northeast1" // Set to 0 for testing purposes // In reality this would be larger than zero - slot_capacity = 0 + slot_capacity = 0 ignore_idle_slots = false + concurrency = 0 } ``` @@ -72,6 +73,15 @@ The following arguments are supported: the same admin project. If true, a query using this reservation will execute with the slot capacity specified above at most. +* `concurrency` - + (Optional) + Maximum number of queries that are allowed to run concurrently in this reservation. This is a soft limit due to asynchronous nature of the system and various optimizations for small queries. Default value is 0 which means that concurrency will be automatically set based on the reservation size. + +* `multi_region_auxiliary` - + (Optional) + Applicable only for reservations located within one of the BigQuery multi-regions (US or EU). + If set to true, this reservation is placed in the organization's secondary region which is designated for disaster recovery purposes. If false, this reservation is placed in the organization's default region. + * `location` - (Optional) The geographic location where the transfer config should reside.