Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions mmv1/products/bigqueryreservation/Reservation.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
46 changes: 46 additions & 0 deletions mmv1/products/bigqueryreservation/ReservationGroup.yaml
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
resource "google_bigquery_reservation_group" "{{$.PrimaryResourceId}}" {
name = "{{index $.Vars "name"}}"
location = "us-west2"
}
2 changes: 2 additions & 0 deletions mmv1/templates/terraform/resource.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
Original file line number Diff line number Diff line change
@@ -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)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down Expand Up @@ -154,4 +230,4 @@ resource "google_bigquery_reservation" "reservation" {
`, context)
}

{{ end }}
{{ end }}
Loading