Skip to content

Commit

Permalink
Fix test TestAccAlloydbInstance_createInstanceWithNetworkConfigAndAll…
Browse files Browse the repository at this point in the history
…ocatedIPRange
  • Loading branch information
zli82016 committed Sep 20, 2023
1 parent b1f4420 commit 40e1dc1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package alloydb_test

import (
"fmt"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-provider-google/google/acctest"
"github.com/hashicorp/terraform-provider-google/google/envvar"
)

func TestAccAlloydbInstance_update(t *testing.T) {
Expand Down Expand Up @@ -345,9 +347,17 @@ data "google_compute_network" "default" {
func TestAccAlloydbInstance_createInstanceWithNetworkConfigAndAllocatedIPRange(t *testing.T) {
t.Parallel()

projectNumber := envvar.GetTestProjectNumberFromEnv()
testId := "alloydbinstance-network-config-1"
networkName := acctest.BootstrapSharedTestNetwork(t, testId)
networkId := fmt.Sprintf("projects/%v/global/networks/%v", projectNumber, networkName)
addressName := acctest.BootstrapSharedTestGlobalAddress(t, testId, networkId)
acctest.BootstrapSharedServiceNetworkingConnection(t, testId)

context := map[string]interface{}{
"random_suffix": acctest.RandString(t, 10),
"network_name": acctest.BootstrapSharedTestNetwork(t, "alloydbinstance-network-config"),
"network_name": networkName,
"address_name": addressName,
}

acctest.VcrTest(t, resource.TestCase{
Expand All @@ -368,37 +378,23 @@ 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_alloydb_cluster" "default" {
cluster_id = "tf-test-alloydb-cluster%{random_suffix}"
location = "us-central1"
network_config {
network = data.google_compute_network.default.id
allocated_ip_range = google_compute_global_address.private_ip_alloc.name
allocated_ip_range = data.google_compute_global_address.private_ip_alloc.name
}
}
data "google_project" "project" {}
data "google_compute_network" "default" {
name = "%{network_name}"
}
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 = data.google_compute_network.default.id
}
resource "google_service_networking_connection" "vpc_connection" {
network = data.google_compute_network.default.id
service = "servicenetworking.googleapis.com"
reserved_peering_ranges = [google_compute_global_address.private_ip_alloc.name]
data "google_compute_global_address" "private_ip_alloc" {
name = "%{address_name}"
}
`, context)
}
Original file line number Diff line number Diff line change
Expand Up @@ -285,8 +285,7 @@ func resourceServiceNetworkingConnectionDelete(d *schema.ResourceData, meta inte
}

if err := ServiceNetworkingOperationWaitTime(config, op, "Delete Service Networking Connection", userAgent, project, d.Timeout(schema.TimeoutCreate)); err != nil {
log.Printf("[INFO] Error deleting Service Networking Connection: %s", err)
return nil
return errwrap.Wrapf("Unable to remove Service Networking Connection, err: {{err}}", err)
}

d.SetId("")
Expand Down

0 comments on commit 40e1dc1

Please sign in to comment.