Skip to content

Commit

Permalink
bigqueryreservation: move beta to v1 + add fields (#6567) (#12687)
Browse files Browse the repository at this point in the history
* move to v1 + fields

* default value

Signed-off-by: Modular Magician <magic-modules@google.com>

Signed-off-by: Modular Magician <magic-modules@google.com>
  • Loading branch information
modular-magician committed Sep 30, 2022
1 parent 4ffd911 commit 301043d
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 3 deletions.
3 changes: 3 additions & 0 deletions .changelog/6567.txt
@@ -0,0 +1,3 @@
```release-note:enhancement
bigqueryreservation: add `concurrency` and `multiRegionAuxiliary` to `google_bigquery_reservation`
```
79 changes: 79 additions & 0 deletions google/resource_bigquery_reservation.go
Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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 {
Expand All @@ -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, ",")})
Expand Down Expand Up @@ -327,10 +377,39 @@ 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
}

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
}
3 changes: 2 additions & 1 deletion google/resource_bigquery_reservation_generated_test.go
Expand Up @@ -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)
}
Expand Down
14 changes: 12 additions & 2 deletions website/docs/r/bigquery_reservation.html.markdown
Expand Up @@ -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)

Expand All @@ -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
}
```

Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 301043d

Please sign in to comment.