Skip to content

Commit

Permalink
Mark location as a required field for AlloyDB on-demand backup (#7688) (
Browse files Browse the repository at this point in the history
#14334)

Signed-off-by: Modular Magician <magic-modules@google.com>
  • Loading branch information
modular-magician authored Apr 17, 2023
1 parent ab21e8a commit 2d793bd
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 10 deletions.
3 changes: 3 additions & 0 deletions .changelog/7688.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
alloydb: changed `location` from `optional` to `required` for `google_alloydb_backup`. `location` had previously been marked as optional, but operations failed if it was omitted, and there was no way for `location` to be inherited from the provider configuration or from an environment variable. This means there was no way to have a working configuration without `location` specified.
```
12 changes: 6 additions & 6 deletions google/resource_alloydb_backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ func ResourceAlloydbBackup() *schema.Resource {
DiffSuppressFunc: ProjectNumberDiffSuppress,
Description: `The full resource name of the backup source cluster (e.g., projects/{project}/locations/{location}/clusters/{clusterId}).`,
},
"location": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
Description: `The location where the alloydb backup should reside.`,
},
"description": {
Type: schema.TypeString,
Optional: true,
Expand All @@ -67,12 +73,6 @@ func ResourceAlloydbBackup() *schema.Resource {
Description: `User-defined labels for the alloydb backup.`,
Elem: &schema.Schema{Type: schema.TypeString},
},
"location": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Description: `The location where the alloydb backup should reside.`,
},
"create_time": {
Type: schema.TypeString,
Computed: true,
Expand Down
67 changes: 67 additions & 0 deletions google/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)
}
8 changes: 4 additions & 4 deletions website/docs/r/alloydb_backup.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,10 @@ The following arguments are supported:
(Required)
The ID of the alloydb backup.

* `location` -
(Required)
The location where the alloydb backup should reside.


- - -

Expand All @@ -156,10 +160,6 @@ The following arguments are supported:
(Optional)
User-provided description of the backup.

* `location` -
(Optional)
The location where the alloydb backup should reside.

* `project` - (Optional) The ID of the project in which the resource belongs.
If it is not provided, the provider project is used.

Expand Down

0 comments on commit 2d793bd

Please sign in to comment.