From 27c076869428737af8afc1674b0a54e7c0a12620 Mon Sep 17 00:00:00 2001 From: Jie Lin Date: Thu, 19 Mar 2026 05:52:56 +0000 Subject: [PATCH] Add new resource ReservationGroup and add reservationGroup as a new property to resource Reservation in bigqueryreservation --- .../bigqueryreservation/Reservation.yaml | 7 ++ .../bigqueryreservation/ReservationGroup.yaml | 46 +++++++++++ .../bigquery_reservation_group_basic.tf.tmpl | 4 + mmv1/templates/terraform/resource.go.tmpl | 2 + ...esource_bigquery_reservation_group_test.go | 40 ++++++++++ ...resource_bigquery_reservation_test.go.tmpl | 78 ++++++++++++++++++- 6 files changed, 176 insertions(+), 1 deletion(-) create mode 100644 mmv1/products/bigqueryreservation/ReservationGroup.yaml create mode 100644 mmv1/templates/terraform/examples/bigquery_reservation_group_basic.tf.tmpl create mode 100644 mmv1/third_party/terraform/services/bigqueryreservation/resource_bigquery_reservation_group_test.go diff --git a/mmv1/products/bigqueryreservation/Reservation.yaml b/mmv1/products/bigqueryreservation/Reservation.yaml index 981fd0eca05a..746652182f83 100644 --- a/mmv1/products/bigqueryreservation/Reservation.yaml +++ b/mmv1/products/bigqueryreservation/Reservation.yaml @@ -248,3 +248,10 @@ properties: - autoscale required_with: - scalingMode + - name: reservationGroup + type: ResourceRef + description: | + The reservation group that this reservation belongs to. + resource: ReservationGroup + imports: name + diff_suppress_func: tpgresource.CompareSelfLinkOrResourceName diff --git a/mmv1/products/bigqueryreservation/ReservationGroup.yaml b/mmv1/products/bigqueryreservation/ReservationGroup.yaml new file mode 100644 index 000000000000..42152f81b6b6 --- /dev/null +++ b/mmv1/products/bigqueryreservation/ReservationGroup.yaml @@ -0,0 +1,46 @@ +# Copyright 2024 Google Inc. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +--- +name: ReservationGroup +description: | + A reservation group is a container for reservations. +references: + api: https://cloud.google.com/bigquery/docs/reference/reservations/rest/v1/projects.locations.reservationGroups +base_url: projects/{{project}}/locations/{{location}}/reservationGroups +create_url: projects/{{project}}/locations/{{location}}/reservationGroups?reservationGroupId={{name}} +immutable: true +id_format: projects/{{project}}/locations/{{location}}/reservationGroups/{{name}} +examples: + - name: bigquery_reservation_group_basic + primary_resource_id: reservation_group + vars: + name: my-reservation-group +parameters: + - name: location + type: String + default_value: US + description: | + The geographic location where the transfer config should reside. + Examples: US, EU, asia-northeast1. The default value is US. + immutable: true + url_param_only: true +properties: + - name: name + type: String + required: true + description: | + The name of the reservation group. This field must only contain alphanumeric characters or dash. + immutable: true + url_param_only: true + diff_suppress_func: tpgresource.CompareSelfLinkOrResourceName diff --git a/mmv1/templates/terraform/examples/bigquery_reservation_group_basic.tf.tmpl b/mmv1/templates/terraform/examples/bigquery_reservation_group_basic.tf.tmpl new file mode 100644 index 000000000000..c7c91d23f7aa --- /dev/null +++ b/mmv1/templates/terraform/examples/bigquery_reservation_group_basic.tf.tmpl @@ -0,0 +1,4 @@ +resource "google_bigquery_reservation_group" "{{$.PrimaryResourceId}}" { + name = "{{index $.Vars "name"}}" + location = "us-west2" +} diff --git a/mmv1/templates/terraform/resource.go.tmpl b/mmv1/templates/terraform/resource.go.tmpl index 53432da9d9db..bd7a5d519f0e 100644 --- a/mmv1/templates/terraform/resource.go.tmpl +++ b/mmv1/templates/terraform/resource.go.tmpl @@ -629,6 +629,8 @@ func resource{{ $.ResourceName -}}Read(d *schema.ResourceData, meta interface{}) return transport_tpg.HandleNotFoundError(err, d, fmt.Sprintf("{{ $.ResourceName }} %q", d.Id())) {{- end}} } + + log.Printf("[DEBUG] Finished reading {{ $.ResourceName }} %q: %#v", d.Id(), res) {{- if $.CustomCode.PostRead }} {{ customTemplate $ $.CustomCode.PostRead false -}} {{- end }} diff --git a/mmv1/third_party/terraform/services/bigqueryreservation/resource_bigquery_reservation_group_test.go b/mmv1/third_party/terraform/services/bigqueryreservation/resource_bigquery_reservation_group_test.go new file mode 100644 index 000000000000..b103976e2371 --- /dev/null +++ b/mmv1/third_party/terraform/services/bigqueryreservation/resource_bigquery_reservation_group_test.go @@ -0,0 +1,40 @@ +package bigqueryreservation_test + +import ( + "testing" + + "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/hashicorp/terraform-provider-google/google/acctest" +) + +func TestAccBigqueryReservationGroup_basic(t *testing.T) { + t.Parallel() + + context := map[string]interface{}{ + "random_suffix": acctest.RandString(t, 10), + } + + acctest.VcrTest(t, resource.TestCase{ + PreCheck: func() { acctest.AccTestPreCheck(t) }, + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t), + Steps: []resource.TestStep{ + { + Config: testAccBigqueryReservationGroup_basic(context), + }, + { + ResourceName: "google_bigquery_reservation_group.reservation_group", + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func testAccBigqueryReservationGroup_basic(context map[string]interface{}) string { + return acctest.Nprintf(` +resource "google_bigquery_reservation_group" "reservation_group" { + name = "tf-test-res-group-%{random_suffix}" + location = "us-west2" +} +`, context) +} diff --git a/mmv1/third_party/terraform/services/bigqueryreservation/resource_bigquery_reservation_test.go.tmpl b/mmv1/third_party/terraform/services/bigqueryreservation/resource_bigquery_reservation_test.go.tmpl index 66fcc9c455e4..19a56a2a9a79 100644 --- a/mmv1/third_party/terraform/services/bigqueryreservation/resource_bigquery_reservation_test.go.tmpl +++ b/mmv1/third_party/terraform/services/bigqueryreservation/resource_bigquery_reservation_test.go.tmpl @@ -73,6 +73,82 @@ func TestAccBigqueryReservation_withScalingMode_update(t *testing.T) { {{ end }} +func TestAccBigqueryReservation_reservationGroup_update(t *testing.T) { + t.Parallel() + + context := map[string]interface{}{ + "random_suffix": acctest.RandString(t, 10), + } + + acctest.VcrTest(t, resource.TestCase{ + PreCheck: func() { acctest.AccTestPreCheck(t) }, + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t), + Steps: []resource.TestStep{ + { + Config: testAccBigqueryReservation_reservationGroup_basic(context), + }, + { + ResourceName: "google_bigquery_reservation.reservation", + ImportState: true, + ImportStateVerify: true, + }, + { + Config: testAccBigqueryReservation_reservationGroup_update(context), + }, + { + ResourceName: "google_bigquery_reservation.reservation", + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func testAccBigqueryReservation_reservationGroup_basic(context map[string]interface{}) string { + return acctest.Nprintf(` +resource "google_bigquery_reservation_group" "reservation_group" { + name = "tf-test-res-group-%{random_suffix}" + location = "us-west2" +} + +resource "google_bigquery_reservation" "reservation" { + name = "tf-test-reservation-%{random_suffix}" + location = "us-west2" + slot_capacity = 0 + edition = "ENTERPRISE" + ignore_idle_slots = true + reservation_group = google_bigquery_reservation_group.reservation_group.name + + autoscale { + max_slots = 100 + } +} +`, context) +} + +func testAccBigqueryReservation_reservationGroup_update(context map[string]interface{}) string { + return acctest.Nprintf(` +resource "google_bigquery_reservation_group" "reservation_group" { + name = "tf-test-res-group-%{random_suffix}" + location = "us-west2" +} + +resource "google_bigquery_reservation" "reservation" { + name = "tf-test-reservation-%{random_suffix}" + location = "us-west2" + slot_capacity = 0 + edition = "ENTERPRISE" + ignore_idle_slots = true + + // reservation_group is removed + + autoscale { + max_slots = 100 + } +} +`, context) +} + func testAccBigqueryReservation_withDisasterRecovery_basic(context map[string]interface{}) string { return acctest.Nprintf(` resource "google_bigquery_reservation" "reservation" { @@ -154,4 +230,4 @@ resource "google_bigquery_reservation" "reservation" { `, context) } -{{ end }} \ No newline at end of file +{{ end }}