Skip to content

Commit

Permalink
Mark location as a required field for AlloyDB on-demand backup (Googl…
Browse files Browse the repository at this point in the history
  • Loading branch information
GauravJain21 authored and ericayyliu committed Jul 26, 2023
1 parent e3f1b55 commit a1efe06
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 0 deletions.
1 change: 1 addition & 0 deletions mmv1/products/alloydb/Backup.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
The ID of the alloydb backup.
- !ruby/object:Api::Type::String
name: "location"
required: true
immutable: true
url_param_only: true
description: |
Expand Down
67 changes: 67 additions & 0 deletions mmv1/third_party/terraform/tests/resource_alloydb_backup_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package google

import (
"regexp"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
Expand Down Expand Up @@ -90,3 +91,69 @@ data "google_compute_network" "default" {
}
`, context)
}

// We expect an error when creating an on-demand backup without location.
// Location is a `required` field.
func TestAccAlloydbBackup_missingLocation(t *testing.T) {
t.Parallel()

context := map[string]interface{}{
"random_suffix": RandString(t, 10),
}

VcrTest(t, resource.TestCase{
PreCheck: func() { AccTestPreCheck(t) },
ProtoV5ProviderFactories: ProtoV5ProviderFactories(t),
CheckDestroy: testAccCheckAlloydbBackupDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccAlloydbBackup_missingLocation(context),
ExpectError: regexp.MustCompile("Missing required argument"),
},
},
})
}

func testAccAlloydbBackup_missingLocation(context map[string]interface{}) string {
return Nprintf(`
resource "google_alloydb_backup" "default" {
backup_id = "tf-test-alloydb-backup%{random_suffix}"
cluster_name = google_alloydb_cluster.default.name
depends_on = [google_alloydb_instance.default]
}
resource "google_alloydb_cluster" "default" {
location = "us-central1"
cluster_id = "tf-test-alloydb-cluster%{random_suffix}"
network = "projects/${data.google_project.project.number}/global/networks/${google_compute_network.default.name}"
}
data "google_project" "project" { }
resource "google_compute_network" "default" {
name = "tf-test-alloydb-cluster%{random_suffix}"
}
resource "google_alloydb_instance" "default" {
cluster = google_alloydb_cluster.default.name
instance_id = "tf-test-alloydb-instance%{random_suffix}"
instance_type = "PRIMARY"
depends_on = [google_service_networking_connection.vpc_connection]
}
resource "google_compute_global_address" "private_ip_alloc" {
name = "tf-test-alloydb-cluster%{random_suffix}"
address_type = "INTERNAL"
purpose = "VPC_PEERING"
prefix_length = 16
network = "projects/${data.google_project.project.number}/global/networks/${google_compute_network.default.name}"
}
resource "google_service_networking_connection" "vpc_connection" {
network = "projects/${data.google_project.project.number}/global/networks/${google_compute_network.default.name}"
service = "servicenetworking.googleapis.com"
reserved_peering_ranges = [google_compute_global_address.private_ip_alloc.name]
}
`, context)
}

0 comments on commit a1efe06

Please sign in to comment.