Skip to content

Commit 301043d

Browse files
bigqueryreservation: move beta to v1 + add fields (#6567) (#12687)
* move to v1 + fields * default value Signed-off-by: Modular Magician <[email protected]> Signed-off-by: Modular Magician <[email protected]>
1 parent 4ffd911 commit 301043d

File tree

4 files changed

+96
-3
lines changed

4 files changed

+96
-3
lines changed

.changelog/6567.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
bigqueryreservation: add `concurrency` and `multiRegionAuxiliary` to `google_bigquery_reservation`
3+
```

google/resource_bigquery_reservation.go

+79
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,12 @@ func resourceBigqueryReservationReservation() *schema.Resource {
5454
Description: `Minimum slots available to this reservation. A slot is a unit of computational power in BigQuery, and serves as the
5555
unit of parallelism. Queries using this reservation might use more slots during runtime if ignoreIdleSlots is set to false.`,
5656
},
57+
"concurrency": {
58+
Type: schema.TypeInt,
59+
Optional: true,
60+
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.`,
61+
Default: 0,
62+
},
5763
"ignore_idle_slots": {
5864
Type: schema.TypeBool,
5965
Optional: true,
@@ -70,6 +76,12 @@ capacity specified above at most.`,
7076
Examples: US, EU, asia-northeast1. The default value is US.`,
7177
Default: "US",
7278
},
79+
"multi_region_auxiliary": {
80+
Type: schema.TypeBool,
81+
Optional: true,
82+
Description: `Applicable only for reservations located within one of the BigQuery multi-regions (US or EU).
83+
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.`,
84+
},
7385
"project": {
7486
Type: schema.TypeString,
7587
Optional: true,
@@ -101,6 +113,18 @@ func resourceBigqueryReservationReservationCreate(d *schema.ResourceData, meta i
101113
} else if v, ok := d.GetOkExists("ignore_idle_slots"); !isEmptyValue(reflect.ValueOf(ignoreIdleSlotsProp)) && (ok || !reflect.DeepEqual(v, ignoreIdleSlotsProp)) {
102114
obj["ignoreIdleSlots"] = ignoreIdleSlotsProp
103115
}
116+
concurrencyProp, err := expandBigqueryReservationReservationConcurrency(d.Get("concurrency"), d, config)
117+
if err != nil {
118+
return err
119+
} else if v, ok := d.GetOkExists("concurrency"); !isEmptyValue(reflect.ValueOf(concurrencyProp)) && (ok || !reflect.DeepEqual(v, concurrencyProp)) {
120+
obj["concurrency"] = concurrencyProp
121+
}
122+
multiRegionAuxiliaryProp, err := expandBigqueryReservationReservationMultiRegionAuxiliary(d.Get("multi_region_auxiliary"), d, config)
123+
if err != nil {
124+
return err
125+
} else if v, ok := d.GetOkExists("multi_region_auxiliary"); !isEmptyValue(reflect.ValueOf(multiRegionAuxiliaryProp)) && (ok || !reflect.DeepEqual(v, multiRegionAuxiliaryProp)) {
126+
obj["multiRegionAuxiliary"] = multiRegionAuxiliaryProp
127+
}
104128

105129
url, err := replaceVars(d, config, "{{BigqueryReservationBasePath}}projects/{{project}}/locations/{{location}}/reservations?reservationId={{name}}")
106130
if err != nil {
@@ -178,6 +202,12 @@ func resourceBigqueryReservationReservationRead(d *schema.ResourceData, meta int
178202
if err := d.Set("ignore_idle_slots", flattenBigqueryReservationReservationIgnoreIdleSlots(res["ignoreIdleSlots"], d, config)); err != nil {
179203
return fmt.Errorf("Error reading Reservation: %s", err)
180204
}
205+
if err := d.Set("concurrency", flattenBigqueryReservationReservationConcurrency(res["concurrency"], d, config)); err != nil {
206+
return fmt.Errorf("Error reading Reservation: %s", err)
207+
}
208+
if err := d.Set("multi_region_auxiliary", flattenBigqueryReservationReservationMultiRegionAuxiliary(res["multiRegionAuxiliary"], d, config)); err != nil {
209+
return fmt.Errorf("Error reading Reservation: %s", err)
210+
}
181211

182212
return nil
183213
}
@@ -210,6 +240,18 @@ func resourceBigqueryReservationReservationUpdate(d *schema.ResourceData, meta i
210240
} else if v, ok := d.GetOkExists("ignore_idle_slots"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, ignoreIdleSlotsProp)) {
211241
obj["ignoreIdleSlots"] = ignoreIdleSlotsProp
212242
}
243+
concurrencyProp, err := expandBigqueryReservationReservationConcurrency(d.Get("concurrency"), d, config)
244+
if err != nil {
245+
return err
246+
} else if v, ok := d.GetOkExists("concurrency"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, concurrencyProp)) {
247+
obj["concurrency"] = concurrencyProp
248+
}
249+
multiRegionAuxiliaryProp, err := expandBigqueryReservationReservationMultiRegionAuxiliary(d.Get("multi_region_auxiliary"), d, config)
250+
if err != nil {
251+
return err
252+
} else if v, ok := d.GetOkExists("multi_region_auxiliary"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, multiRegionAuxiliaryProp)) {
253+
obj["multiRegionAuxiliary"] = multiRegionAuxiliaryProp
254+
}
213255

214256
url, err := replaceVars(d, config, "{{BigqueryReservationBasePath}}projects/{{project}}/locations/{{location}}/reservations/{{name}}")
215257
if err != nil {
@@ -226,6 +268,14 @@ func resourceBigqueryReservationReservationUpdate(d *schema.ResourceData, meta i
226268
if d.HasChange("ignore_idle_slots") {
227269
updateMask = append(updateMask, "ignoreIdleSlots")
228270
}
271+
272+
if d.HasChange("concurrency") {
273+
updateMask = append(updateMask, "concurrency")
274+
}
275+
276+
if d.HasChange("multi_region_auxiliary") {
277+
updateMask = append(updateMask, "multiRegionAuxiliary")
278+
}
229279
// updateMask is a URL parameter but not present in the schema, so replaceVars
230280
// won't set it
231281
url, err = addQueryParams(url, map[string]string{"updateMask": strings.Join(updateMask, ",")})
@@ -327,10 +377,39 @@ func flattenBigqueryReservationReservationIgnoreIdleSlots(v interface{}, d *sche
327377
return v
328378
}
329379

380+
func flattenBigqueryReservationReservationConcurrency(v interface{}, d *schema.ResourceData, config *Config) interface{} {
381+
// Handles the string fixed64 format
382+
if strVal, ok := v.(string); ok {
383+
if intVal, err := stringToFixed64(strVal); err == nil {
384+
return intVal
385+
}
386+
}
387+
388+
// number values are represented as float64
389+
if floatVal, ok := v.(float64); ok {
390+
intVal := int(floatVal)
391+
return intVal
392+
}
393+
394+
return v // let terraform core handle it otherwise
395+
}
396+
397+
func flattenBigqueryReservationReservationMultiRegionAuxiliary(v interface{}, d *schema.ResourceData, config *Config) interface{} {
398+
return v
399+
}
400+
330401
func expandBigqueryReservationReservationSlotCapacity(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
331402
return v, nil
332403
}
333404

334405
func expandBigqueryReservationReservationIgnoreIdleSlots(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
335406
return v, nil
336407
}
408+
409+
func expandBigqueryReservationReservationConcurrency(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
410+
return v, nil
411+
}
412+
413+
func expandBigqueryReservationReservationMultiRegionAuxiliary(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
414+
return v, nil
415+
}

google/resource_bigquery_reservation_generated_test.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,9 @@ resource "google_bigquery_reservation" "reservation" {
5555
location = "asia-northeast1"
5656
// Set to 0 for testing purposes
5757
// In reality this would be larger than zero
58-
slot_capacity = 0
58+
slot_capacity = 0
5959
ignore_idle_slots = false
60+
concurrency = 0
6061
}
6162
`, context)
6263
}

website/docs/r/bigquery_reservation.html.markdown

+12-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ A reservation is a mechanism used to guarantee BigQuery slots to users.
2525

2626
To get more information about Reservation, see:
2727

28-
* [API documentation](https://cloud.google.com/bigquery/docs/reference/reservations/rest/v1beta1/projects.locations.reservations/create)
28+
* [API documentation](https://cloud.google.com/bigquery/docs/reference/reservations/rest/v1/projects.locations.reservations/create)
2929
* How-to Guides
3030
* [Introduction to Reservations](https://cloud.google.com/bigquery/docs/reservations-intro)
3131

@@ -43,8 +43,9 @@ resource "google_bigquery_reservation" "reservation" {
4343
location = "asia-northeast1"
4444
// Set to 0 for testing purposes
4545
// In reality this would be larger than zero
46-
slot_capacity = 0
46+
slot_capacity = 0
4747
ignore_idle_slots = false
48+
concurrency = 0
4849
}
4950
```
5051

@@ -72,6 +73,15 @@ The following arguments are supported:
7273
the same admin project. If true, a query using this reservation will execute with the slot
7374
capacity specified above at most.
7475

76+
* `concurrency` -
77+
(Optional)
78+
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.
79+
80+
* `multi_region_auxiliary` -
81+
(Optional)
82+
Applicable only for reservations located within one of the BigQuery multi-regions (US or EU).
83+
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.
84+
7585
* `location` -
7686
(Optional)
7787
The geographic location where the transfer config should reside.

0 commit comments

Comments
 (0)