From 025e43eba8417187f018c3ea5a6461030b391b5c Mon Sep 17 00:00:00 2001 From: Zhenhua Li Date: Sat, 16 Sep 2023 22:56:50 -0700 Subject: [PATCH] Modify tests --- .../terraform/acctest/bootstrap_test_utils.go | 19 +- .../alloydb/resource_alloydb_backup_test.go | 6 +- .../resource_alloydb_cluster_restore_test.go | 2 +- .../alloydb/resource_alloydb_instance_test.go | 10 +- ...esource_cloudbuild_worker_pool_test.go.erb | 2 +- .../resource_cloudids_endpoint_test.go | 2 +- .../resource_memcache_instance_test.go | 2 +- .../resource_service_networking_connection.go | 73 +++---- .../resource_sql_database_instance_test.go | 181 ++++++------------ .../resource_vertex_ai_endpoint_test.go | 19 +- .../resource_vertex_ai_index_endpoint_test.go | 24 +-- 11 files changed, 127 insertions(+), 213 deletions(-) diff --git a/mmv1/third_party/terraform/acctest/bootstrap_test_utils.go b/mmv1/third_party/terraform/acctest/bootstrap_test_utils.go index 38d8fad4d51f..6e7fd8587405 100644 --- a/mmv1/third_party/terraform/acctest/bootstrap_test_utils.go +++ b/mmv1/third_party/terraform/acctest/bootstrap_test_utils.go @@ -410,9 +410,26 @@ func BootstrapSharedTestGlobalAddress(t *testing.T, testId, networkId string) st return address.Name } +// BootstrapSharedServiceNetworkingConnection will create a shared network +// if it hasn't been created in the test project, a global address +// if it hasn't been created in the test project, and a service networking connection +// if it hasn't been created in the test project. +// +// BootstrapSharedServiceNetworkingConnection returns a persistent compute network name +// for a test or set of tests. +// +// To delete a service networking conneciton, all of the service instances that use that connection +// must be deleted first. After the service instances are deleted, some service producers delay the deletion +// utnil a waiting period has passed. For example, after four days that you delete a SQL instance, +// the service networking connection can be deleted. +// That is the reason to use the shared service networking connection for thest resources. +// https://cloud.google.com/vpc/docs/configure-private-services-access#removing-connection +// +// testId specifies the test for which a shared network and a gobal address are used/initialized. func BootstrapSharedServiceNetworkingConnection(t *testing.T, testId string) string { parentService := "services/servicenetworking.googleapis.com" project := envvar.GetTestProjectFromEnv() + projectNumber := envvar.GetTestProjectNumberFromEnv() config := BootstrapConfig(t) if config == nil { @@ -420,7 +437,7 @@ func BootstrapSharedServiceNetworkingConnection(t *testing.T, testId string) str } networkName := BootstrapSharedTestNetwork(t, testId) - networkId := fmt.Sprintf("projects/%v/global/networks/%v", project, networkName) + networkId := fmt.Sprintf("projects/%v/global/networks/%v", projectNumber, networkName) globalAddressName := BootstrapSharedTestGlobalAddress(t, testId, networkId) readCall := config.NewServiceNetworkingClient(config.UserAgent).Services.Connections.List(parentService).Network(networkId) diff --git a/mmv1/third_party/terraform/services/alloydb/resource_alloydb_backup_test.go b/mmv1/third_party/terraform/services/alloydb/resource_alloydb_backup_test.go index c9cf55dd85c8..b4332cf2770b 100644 --- a/mmv1/third_party/terraform/services/alloydb/resource_alloydb_backup_test.go +++ b/mmv1/third_party/terraform/services/alloydb/resource_alloydb_backup_test.go @@ -12,7 +12,7 @@ func TestAccAlloydbBackup_update(t *testing.T) { random_suffix := acctest.RandString(t, 10) context := map[string]interface{}{ - "network_name": acctest.BootstrapSharedServiceNetworkingConnection(t, "alloydb-network"), + "network_name": acctest.BootstrapSharedServiceNetworkingConnection(t, "alloydb-backup-update-1"), "random_suffix": random_suffix, } @@ -83,7 +83,7 @@ func TestAccAlloydbBackup_createBackupWithMandatoryFields(t *testing.T) { context := map[string]interface{}{ "random_suffix": acctest.RandString(t, 10), - "network_name": acctest.BootstrapSharedServiceNetworkingConnection(t, "alloydbbackup-mandatory"), + "network_name": acctest.BootstrapSharedServiceNetworkingConnection(t, "alloydb-backup-mandatory-1"), } acctest.VcrTest(t, resource.TestCase{ @@ -131,7 +131,7 @@ func TestAccAlloydbBackup_usingCMEK(t *testing.T) { t.Parallel() context := map[string]interface{}{ - "network_name": acctest.BootstrapSharedServiceNetworkingConnection(t, "alloydb-backup-cmek"), + "network_name": acctest.BootstrapSharedServiceNetworkingConnection(t, "alloydb-backup-cmek-1"), "random_suffix": acctest.RandString(t, 10), "key_name": "tf-test-key-" + acctest.RandString(t, 10), } diff --git a/mmv1/third_party/terraform/services/alloydb/resource_alloydb_cluster_restore_test.go b/mmv1/third_party/terraform/services/alloydb/resource_alloydb_cluster_restore_test.go index 967fd3df7c55..5288d8ea62f8 100644 --- a/mmv1/third_party/terraform/services/alloydb/resource_alloydb_cluster_restore_test.go +++ b/mmv1/third_party/terraform/services/alloydb/resource_alloydb_cluster_restore_test.go @@ -19,7 +19,7 @@ func TestAccAlloydbCluster_restore(t *testing.T) { context := map[string]interface{}{ "random_suffix": acctest.RandString(t, 10), - "network_name": acctest.BootstrapSharedServiceNetworkingConnection(t, "alloydbinstance-restore"), + "network_name": acctest.BootstrapSharedServiceNetworkingConnection(t, "alloydb-instance-restore-1"), } acctest.VcrTest(t, resource.TestCase{ diff --git a/mmv1/third_party/terraform/services/alloydb/resource_alloydb_instance_test.go b/mmv1/third_party/terraform/services/alloydb/resource_alloydb_instance_test.go index bdcca42ad97f..b27b15df76e0 100644 --- a/mmv1/third_party/terraform/services/alloydb/resource_alloydb_instance_test.go +++ b/mmv1/third_party/terraform/services/alloydb/resource_alloydb_instance_test.go @@ -13,7 +13,7 @@ func TestAccAlloydbInstance_update(t *testing.T) { random_suffix := acctest.RandString(t, 10) context := map[string]interface{}{ "random_suffix": random_suffix, - "network_name": acctest.BootstrapSharedServiceNetworkingConnection(t, "alloydbinstance-update"), + "network_name": acctest.BootstrapSharedServiceNetworkingConnection(t, "alloydb-instance-update-1"), } acctest.VcrTest(t, resource.TestCase{ @@ -84,7 +84,7 @@ func TestAccAlloydbInstance_createInstanceWithMandatoryFields(t *testing.T) { context := map[string]interface{}{ "random_suffix": acctest.RandString(t, 10), - "network_name": acctest.BootstrapSharedServiceNetworkingConnection(t, "alloydbinstance-mandatory"), + "network_name": acctest.BootstrapSharedServiceNetworkingConnection(t, "alloydb-instance-mandatory-1"), } acctest.VcrTest(t, resource.TestCase{ @@ -127,7 +127,7 @@ func TestAccAlloydbInstance_createInstanceWithMaximumFields(t *testing.T) { context := map[string]interface{}{ "random_suffix": acctest.RandString(t, 10), - "network_name": acctest.BootstrapSharedServiceNetworkingConnection(t, "alloydbinstance-maximum"), + "network_name": acctest.BootstrapSharedServiceNetworkingConnection(t, "alloydb-instance-maximum-1"), } acctest.VcrTest(t, resource.TestCase{ @@ -190,7 +190,7 @@ func TestAccAlloydbInstance_createPrimaryAndReadPoolInstance(t *testing.T) { context := map[string]interface{}{ "random_suffix": acctest.RandString(t, 10), - "network_name": acctest.BootstrapSharedServiceNetworkingConnection(t, "alloydbinstance-readpool"), + "network_name": acctest.BootstrapSharedServiceNetworkingConnection(t, "alloydb-instance-readpool-1"), } acctest.VcrTest(t, resource.TestCase{ @@ -243,7 +243,7 @@ func TestAccAlloydbInstance_updateDatabaseFlagInPrimaryInstance(t *testing.T) { context := map[string]interface{}{ "random_suffix": acctest.RandString(t, 10), - "network_name": acctest.BootstrapSharedServiceNetworkingConnection(t, "alloydbinstance-updatedb"), + "network_name": acctest.BootstrapSharedServiceNetworkingConnection(t, "alloydb-instance-updatedb-1"), } acctest.VcrTest(t, resource.TestCase{ diff --git a/mmv1/third_party/terraform/services/cloudbuild/resource_cloudbuild_worker_pool_test.go.erb b/mmv1/third_party/terraform/services/cloudbuild/resource_cloudbuild_worker_pool_test.go.erb index b3fe7b4d418f..2954e203a654 100644 --- a/mmv1/third_party/terraform/services/cloudbuild/resource_cloudbuild_worker_pool_test.go.erb +++ b/mmv1/third_party/terraform/services/cloudbuild/resource_cloudbuild_worker_pool_test.go.erb @@ -104,7 +104,7 @@ func TestAccCloudbuildWorkerPool_withNetwork(t *testing.T) { context := map[string]interface{}{ "random_suffix": acctest.RandString(t, 10), "project": envvar.GetTestProjectFromEnv(), - "network_name": acctest.BootstrapSharedServiceNetworkingConnection(t, "cloudbuild-workerpool"), + "network_name": acctest.BootstrapSharedServiceNetworkingConnection(t, "cloudbuild-workerpool-1"), } acctest.VcrTest(t, resource.TestCase{ diff --git a/mmv1/third_party/terraform/services/cloudids/resource_cloudids_endpoint_test.go b/mmv1/third_party/terraform/services/cloudids/resource_cloudids_endpoint_test.go index c46a3cca58b5..9983e66e0feb 100644 --- a/mmv1/third_party/terraform/services/cloudids/resource_cloudids_endpoint_test.go +++ b/mmv1/third_party/terraform/services/cloudids/resource_cloudids_endpoint_test.go @@ -18,7 +18,7 @@ func TestAccCloudIdsEndpoint_basic(t *testing.T) { context := map[string]interface{}{ "random_suffix": acctest.RandString(t, 10), - "network_name": acctest.BootstrapSharedServiceNetworkingConnection(t, "cloud-ids-endpoint"), + "network_name": acctest.BootstrapSharedServiceNetworkingConnection(t, "cloud-ids-endpoint-1"), } acctest.VcrTest(t, resource.TestCase{ diff --git a/mmv1/third_party/terraform/services/memcache/resource_memcache_instance_test.go b/mmv1/third_party/terraform/services/memcache/resource_memcache_instance_test.go index d2607ab9806b..02d4db15a19e 100644 --- a/mmv1/third_party/terraform/services/memcache/resource_memcache_instance_test.go +++ b/mmv1/third_party/terraform/services/memcache/resource_memcache_instance_test.go @@ -13,7 +13,7 @@ func TestAccMemcacheInstance_update(t *testing.T) { prefix := fmt.Sprintf("%d", acctest.RandInt(t)) name := fmt.Sprintf("tf-test-%s", prefix) - network := acctest.BootstrapSharedServiceNetworkingConnection(t, "memcache-instance-update") + network := acctest.BootstrapSharedServiceNetworkingConnection(t, "memcache-instance-update-1") acctest.VcrTest(t, resource.TestCase{ PreCheck: func() { acctest.AccTestPreCheck(t) }, diff --git a/mmv1/third_party/terraform/services/servicenetworking/resource_service_networking_connection.go b/mmv1/third_party/terraform/services/servicenetworking/resource_service_networking_connection.go index 38cf8bd6f9da..2d098a318110 100644 --- a/mmv1/third_party/terraform/services/servicenetworking/resource_service_networking_connection.go +++ b/mmv1/third_party/terraform/services/servicenetworking/resource_service_networking_connection.go @@ -8,11 +8,13 @@ import ( "strings" "time" + tpgcompute "github.com/hashicorp/terraform-provider-google/google/services/compute" "github.com/hashicorp/terraform-provider-google/google/tpgresource" transport_tpg "github.com/hashicorp/terraform-provider-google/google/transport" "github.com/hashicorp/errwrap" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "google.golang.org/api/compute/v1" "google.golang.org/api/servicenetworking/v1" ) @@ -285,42 +287,41 @@ func resourceServiceNetworkingConnectionDelete(d *schema.ResourceData, meta inte } if err := ServiceNetworkingOperationWaitTime(config, op, "Delete Service Networking Connection", userAgent, project, d.Timeout(schema.TimeoutCreate)); err != nil { - return err - // obj := make(map[string]interface{}) - // peering := d.Get("peering").(string) - // obj["name"] = peering - // url := fmt.Sprintf("%s%s/removePeering", config.ComputeBasePath, serviceNetworkingNetworkName) - - // networkFieldValue, err := tpgresource.ParseNetworkFieldValue(network, d, config) - // if err != nil { - // return errwrap.Wrapf("Failed to retrieve network field value, err: {{err}}", err) - // } - - // project := networkFieldValue.Project - // res, err := transport_tpg.SendRequest(transport_tpg.SendRequestOptions{ - // Config: config, - // Method: "POST", - // Project: project, - // RawURL: url, - // UserAgent: userAgent, - // Body: obj, - // Timeout: d.Timeout(schema.TimeoutDelete), - // }) - // if err != nil { - // return transport_tpg.HandleNotFoundError(err, d, fmt.Sprintf("ServiceNetworkingConnection %q", d.Id())) - // } - - // op := &compute.Operation{} - // err = tpgresource.Convert(res, op) - // if err != nil { - // return err - // } - - // err = tpgcompute.ComputeOperationWaitTime( - // config, op, project, "Updating Network", userAgent, d.Timeout(schema.TimeoutDelete)) - // if err != nil { - // return err - // } + obj := make(map[string]interface{}) + peering := d.Get("peering").(string) + obj["name"] = peering + url := fmt.Sprintf("%s%s/removePeering", config.ComputeBasePath, serviceNetworkingNetworkName) + + networkFieldValue, err := tpgresource.ParseNetworkFieldValue(network, d, config) + if err != nil { + return errwrap.Wrapf("Failed to retrieve network field value, err: {{err}}", err) + } + + project := networkFieldValue.Project + res, err := transport_tpg.SendRequest(transport_tpg.SendRequestOptions{ + Config: config, + Method: "POST", + Project: project, + RawURL: url, + UserAgent: userAgent, + Body: obj, + Timeout: d.Timeout(schema.TimeoutDelete), + }) + if err != nil { + return transport_tpg.HandleNotFoundError(err, d, fmt.Sprintf("ServiceNetworkingConnection %q", d.Id())) + } + + op := &compute.Operation{} + err = tpgresource.Convert(res, op) + if err != nil { + return err + } + + err = tpgcompute.ComputeOperationWaitTime( + config, op, project, "Updating Network", userAgent, d.Timeout(schema.TimeoutDelete)) + if err != nil { + return err + } } d.SetId("") diff --git a/mmv1/third_party/terraform/services/sql/resource_sql_database_instance_test.go b/mmv1/third_party/terraform/services/sql/resource_sql_database_instance_test.go index b73c625038d4..34625e3461b7 100644 --- a/mmv1/third_party/terraform/services/sql/resource_sql_database_instance_test.go +++ b/mmv1/third_party/terraform/services/sql/resource_sql_database_instance_test.go @@ -178,8 +178,12 @@ func TestAccSqlDatabaseInstance_deleteDefaultUserBeforeSubsequentApiCalls(t *tes t.Parallel() databaseName := "tf-test-" + acctest.RandString(t, 10) - addressName := "tf-test-" + acctest.RandString(t, 10) - networkName := acctest.BootstrapSharedServiceNetworkingConnection(t, "sql-instance-clone-2") + testId := "sql-instance-clone-2" + networkName := acctest.BootstrapSharedTestNetwork(t, testId) + projectNumber := envvar.GetTestProjectNumberFromEnv() + networkId := fmt.Sprintf("projects/%v/global/networks/%v", projectNumber, networkName) + addressName := acctest.BootstrapSharedTestGlobalAddress(t, testId, networkId) + acctest.BootstrapSharedServiceNetworkingConnection(t, testId) // 1. Create an instance. // 2. Add a root@'%' user. @@ -191,7 +195,7 @@ func TestAccSqlDatabaseInstance_deleteDefaultUserBeforeSubsequentApiCalls(t *tes CheckDestroy: testAccSqlDatabaseInstanceDestroyProducer(t), Steps: []resource.TestStep{ { - Config: testAccSqlDatabaseInstance_withPrivateNetwork_withoutAllocatedIpRange(databaseName, networkName, addressName, false, false), + Config: testAccSqlDatabaseInstance_withPrivateNetwork_withoutAllocatedIpRange(databaseName, networkName, false, false), }, { PreConfig: func() { @@ -736,8 +740,7 @@ func TestAccSqlDatabaseInstance_withPrivateNetwork_withoutAllocatedIpRange(t *te t.Parallel() databaseName := "tf-test-" + acctest.RandString(t, 10) - addressName := "tf-test-" + acctest.RandString(t, 10) - networkName := acctest.BootstrapSharedServiceNetworkingConnection(t, "sql-instance-private-network") + networkName := acctest.BootstrapSharedServiceNetworkingConnection(t, "sql-instance-1") acctest.VcrTest(t, resource.TestCase{ PreCheck: func() { acctest.AccTestPreCheck(t) }, @@ -745,7 +748,7 @@ func TestAccSqlDatabaseInstance_withPrivateNetwork_withoutAllocatedIpRange(t *te CheckDestroy: testAccSqlDatabaseInstanceDestroyProducer(t), Steps: []resource.TestStep{ { - Config: testAccSqlDatabaseInstance_withPrivateNetwork_withoutAllocatedIpRange(databaseName, networkName, addressName, false, false), + Config: testAccSqlDatabaseInstance_withPrivateNetwork_withoutAllocatedIpRange(databaseName, networkName, false, false), }, { ResourceName: "google_sql_database_instance.instance", @@ -754,7 +757,7 @@ func TestAccSqlDatabaseInstance_withPrivateNetwork_withoutAllocatedIpRange(t *te ImportStateVerifyIgnore: []string{"deletion_protection"}, }, { - Config: testAccSqlDatabaseInstance_withPrivateNetwork_withoutAllocatedIpRange(databaseName, networkName, addressName, true, false), + Config: testAccSqlDatabaseInstance_withPrivateNetwork_withoutAllocatedIpRange(databaseName, networkName, true, false), }, { ResourceName: "google_sql_database_instance.instance", @@ -763,7 +766,7 @@ func TestAccSqlDatabaseInstance_withPrivateNetwork_withoutAllocatedIpRange(t *te ImportStateVerifyIgnore: []string{"deletion_protection"}, }, { - Config: testAccSqlDatabaseInstance_withPrivateNetwork_withoutAllocatedIpRange(databaseName, networkName, addressName, true, true), + Config: testAccSqlDatabaseInstance_withPrivateNetwork_withoutAllocatedIpRange(databaseName, networkName, true, true), }, { ResourceName: "google_sql_database_instance.instance", @@ -772,7 +775,7 @@ func TestAccSqlDatabaseInstance_withPrivateNetwork_withoutAllocatedIpRange(t *te ImportStateVerifyIgnore: []string{"deletion_protection"}, }, { - Config: testAccSqlDatabaseInstance_withPrivateNetwork_withoutAllocatedIpRange(databaseName, networkName, addressName, true, false), + Config: testAccSqlDatabaseInstance_withPrivateNetwork_withoutAllocatedIpRange(databaseName, networkName, true, false), }, { ResourceName: "google_sql_database_instance.instance", @@ -964,15 +967,24 @@ func TestAccSqlDatabaseInstance_withPSCEnabled_withIpV4Enabled(t *testing.T) { }) } -func TestAccSqlDatabaseInstance_withPrivateNetwork_withAllocatedIpRange1(t *testing.T) { +func TestAccSqlDatabaseInstance_withPrivateNetwork_withAllocatedIpRange(t *testing.T) { t.Parallel() databaseName := "tf-test-" + acctest.RandString(t, 10) - addressName := "tf-test-" + acctest.RandString(t, 10) - networkName := acctest.BootstrapSharedServiceNetworkingConnection(t, "sql-instance-private-network-allocated") - addressName_update := "tf-test-" + acctest.RandString(t, 10) + "update" - networkName_update := acctest.BootstrapSharedServiceNetworkingConnection(t, "sql-instance-private-network-allocated-update") + + projectNumber := envvar.GetTestProjectNumberFromEnv() + testId := "sql-instance-allocated-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) + + updateTestId := "sql-instance-allocated-update-1" + networkName_update := acctest.BootstrapSharedTestNetwork(t, updateTestId) + networkId_update := fmt.Sprintf("projects/%v/global/networks/%v", projectNumber, networkName_update) + addressName_update := acctest.BootstrapSharedTestGlobalAddress(t, updateTestId, networkId_update) + acctest.BootstrapSharedServiceNetworkingConnection(t, updateTestId) acctest.VcrTest(t, resource.TestCase{ PreCheck: func() { acctest.AccTestPreCheck(t) }, @@ -1006,8 +1018,13 @@ func TestAccSqlDatabaseInstance_withPrivateNetwork_withAllocatedIpRangeReplica(t t.Parallel() databaseName := "tf-test-" + acctest.RandString(t, 10) - addressName := "tf-test-" + acctest.RandString(t, 10) - networkName := acctest.BootstrapSharedServiceNetworkingConnection(t, "sql-instance-private-network-replica") + + projectNumber := envvar.GetTestProjectNumberFromEnv() + testId := "sql-instance-replica-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) acctest.VcrTest(t, resource.TestCase{ PreCheck: func() { acctest.AccTestPreCheck(t) }, @@ -1038,8 +1055,12 @@ func TestAccSqlDatabaseInstance_withPrivateNetwork_withAllocatedIpRangeClone(t * t.Parallel() databaseName := "tf-test-" + acctest.RandString(t, 10) - addressName := "tf-test-" + acctest.RandString(t, 10) - networkName := acctest.BootstrapSharedServiceNetworkingConnection(t, "sql-instance-private-network-clone") + projectNumber := envvar.GetTestProjectNumberFromEnv() + testId := "sql-instance-clone-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) acctest.VcrTest(t, resource.TestCase{ PreCheck: func() { acctest.AccTestPreCheck(t) }, @@ -1439,8 +1460,7 @@ func TestAccSqlDatabaseInstance_ActiveDirectory(t *testing.T) { t.Parallel() databaseName := "tf-test-" + acctest.RandString(t, 10) - networkName := acctest.BootstrapSharedServiceNetworkingConnection(t, "sql-instance-private-test-ad") - addressName := "tf-test-" + acctest.RandString(t, 10) + networkName := acctest.BootstrapSharedServiceNetworkingConnection(t, "sql-instance-ad-1") rootPassword := acctest.RandString(t, 15) adDomainName := acctest.BootstrapSharedTestADDomain(t, "test-domain", networkName) @@ -1450,7 +1470,7 @@ func TestAccSqlDatabaseInstance_ActiveDirectory(t *testing.T) { CheckDestroy: testAccSqlDatabaseInstanceDestroyProducer(t), Steps: []resource.TestStep{ { - Config: testGoogleSqlDatabaseInstance_ActiveDirectoryConfig(databaseName, networkName, addressName, rootPassword, adDomainName), + Config: testGoogleSqlDatabaseInstance_ActiveDirectoryConfig(databaseName, networkName, rootPassword, adDomainName), }, { ResourceName: "google_sql_database_instance.instance-with-ad", @@ -2168,28 +2188,13 @@ resource "google_sql_database_instance" "instance" { } ` -func testGoogleSqlDatabaseInstance_ActiveDirectoryConfig(databaseName, networkName, addressRangeName, rootPassword, adDomainName string) string { +func testGoogleSqlDatabaseInstance_ActiveDirectoryConfig(databaseName, networkName, rootPassword, adDomainName string) string { return fmt.Sprintf(` data "google_compute_network" "servicenet" { name = "%s" } -resource "google_compute_global_address" "foobar" { - name = "%s" - purpose = "VPC_PEERING" - address_type = "INTERNAL" - prefix_length = 16 - network = data.google_compute_network.servicenet.self_link -} - -resource "google_service_networking_connection" "foobar" { - network = data.google_compute_network.servicenet.self_link - service = "servicenetworking.googleapis.com" - reserved_peering_ranges = [google_compute_global_address.foobar.name] -} - resource "google_sql_database_instance" "instance-with-ad" { - depends_on = [google_service_networking_connection.foobar] name = "%s" region = "us-central1" database_version = "SQLSERVER_2017_STANDARD" @@ -2206,7 +2211,7 @@ resource "google_sql_database_instance" "instance-with-ad" { domain = "%s" } } -}`, networkName, addressRangeName, databaseName, rootPassword, adDomainName) +}`, networkName, databaseName, rootPassword, adDomainName) } func testGoogleSqlDatabaseInstance_DenyMaintenancePeriodConfig(databaseName, endDate, startDate, time string) string { @@ -2791,7 +2796,7 @@ func verifyPscOperation(resourceName string, isPscConfigExpected bool, expectedP } } -func testAccSqlDatabaseInstance_withPrivateNetwork_withoutAllocatedIpRange(databaseName, networkName, addressRangeName string, specifyPrivatePathOption bool, enablePrivatePath bool) string { +func testAccSqlDatabaseInstance_withPrivateNetwork_withoutAllocatedIpRange(databaseName, networkName string, specifyPrivatePathOption bool, enablePrivatePath bool) string { privatePathOption := "" if specifyPrivatePathOption { privatePathOption = fmt.Sprintf("enable_private_path_for_google_cloud_services = %t", enablePrivatePath) @@ -2802,22 +2807,7 @@ data "google_compute_network" "servicenet" { name = "%s" } -resource "google_compute_global_address" "foobar" { - name = "%s" - purpose = "VPC_PEERING" - address_type = "INTERNAL" - prefix_length = 16 - network = data.google_compute_network.servicenet.self_link -} - -resource "google_service_networking_connection" "foobar" { - network = data.google_compute_network.servicenet.self_link - service = "servicenetworking.googleapis.com" - reserved_peering_ranges = [google_compute_global_address.foobar.name] -} - resource "google_sql_database_instance" "instance" { - depends_on = [google_service_networking_connection.foobar] name = "%s" region = "us-central1" database_version = "MYSQL_5_7" @@ -2831,31 +2821,16 @@ resource "google_sql_database_instance" "instance" { } } } -`, networkName, addressRangeName, databaseName, privatePathOption) +`, networkName, databaseName, privatePathOption) } func testAccSqlDatabaseInstance_withPrivateNetwork_withAllocatedIpRange(databaseName, networkName, addressRangeName string) string { return fmt.Sprintf(` -resource "google_compute_network" "servicenet" { +data "google_compute_network" "servicenet" { name = "%s" } -resource "google_compute_global_address" "foobar" { - name = "%s" - purpose = "VPC_PEERING" - address_type = "INTERNAL" - prefix_length = 16 - network = google_compute_network.servicenet.self_link -} - -resource "google_service_networking_connection" "foobar" { - network = google_compute_network.servicenet.self_link - service = "servicenetworking.googleapis.com" - reserved_peering_ranges = [google_compute_global_address.foobar.name] -} - resource "google_sql_database_instance" "instance" { - depends_on = [google_service_networking_connection.foobar] name = "%s" region = "us-central1" database_version = "MYSQL_5_7" @@ -2864,12 +2839,12 @@ resource "google_sql_database_instance" "instance" { tier = "db-f1-micro" ip_configuration { ipv4_enabled = "false" - private_network = google_compute_network.servicenet.self_link - # allocated_ip_range = google_compute_global_address.foobar.name + private_network = data.google_compute_network.servicenet.self_link + allocated_ip_range = "%s" } } } -`, networkName, addressRangeName, databaseName) +`, networkName, databaseName, addressRangeName) } func testAccSqlDatabaseInstance_withPrivateNetwork_withAllocatedIpRangeReplica(databaseName, networkName, addressRangeName string) string { @@ -2878,20 +2853,6 @@ data "google_compute_network" "servicenet" { name = "%s" } -resource "google_compute_global_address" "foobar" { - name = "%s" - purpose = "VPC_PEERING" - address_type = "INTERNAL" - prefix_length = 16 - network = data.google_compute_network.servicenet.self_link -} - -resource "google_service_networking_connection" "foobar" { - network = data.google_compute_network.servicenet.self_link - service = "servicenetworking.googleapis.com" - reserved_peering_ranges = [google_compute_global_address.foobar.name] -} - resource "google_sql_database_instance" "instance" { depends_on = [google_service_networking_connection.foobar] name = "%s" @@ -2922,7 +2883,7 @@ resource "google_sql_database_instance" "replica1" { ip_configuration { ipv4_enabled = "false" private_network = data.google_compute_network.servicenet.self_link - allocated_ip_range = google_compute_global_address.foobar.name + allocated_ip_range = "%s" } } @@ -2937,7 +2898,7 @@ resource "google_sql_database_instance" "replica1" { verify_server_certificate = false } } -`, networkName, addressRangeName, databaseName, databaseName) +`, networkName, databaseName, databaseName, addressRangeName) } func testAccSqlDatabaseInstance_withPrivateNetwork_withAllocatedIpRangeClone(databaseName, networkName, addressRangeName string) string { @@ -2946,22 +2907,7 @@ data "google_compute_network" "servicenet" { name = "%s" } -resource "google_compute_global_address" "foobar" { - name = "%s" - purpose = "VPC_PEERING" - address_type = "INTERNAL" - prefix_length = 16 - network = data.google_compute_network.servicenet.self_link -} - -resource "google_service_networking_connection" "foobar" { - network = data.google_compute_network.servicenet.self_link - service = "servicenetworking.googleapis.com" - reserved_peering_ranges = [google_compute_global_address.foobar.name] -} - resource "google_sql_database_instance" "instance" { - depends_on = [google_service_networking_connection.foobar] name = "%s" region = "us-central1" database_version = "MYSQL_5_7" @@ -2988,11 +2934,11 @@ resource "google_sql_database_instance" "clone1" { clone { source_instance_name = google_sql_database_instance.instance.name - allocated_ip_range = google_compute_global_address.foobar.name + allocated_ip_range = "%s" } } -`, networkName, addressRangeName, databaseName, databaseName) +`, networkName, databaseName, databaseName, addressRangeName) } func testAccSqlDatabaseInstance_withPrivateNetwork_withAllocatedIpRangeClone_withSettings(databaseName, networkName, addressRangeName string) string { @@ -3001,22 +2947,7 @@ data "google_compute_network" "servicenet" { name = "%s" } -resource "google_compute_global_address" "foobar" { - name = "%s" - purpose = "VPC_PEERING" - address_type = "INTERNAL" - prefix_length = 16 - network = data.google_compute_network.servicenet.self_link -} - -resource "google_service_networking_connection" "foobar" { - network = data.google_compute_network.servicenet.self_link - service = "servicenetworking.googleapis.com" - reserved_peering_ranges = [google_compute_global_address.foobar.name] -} - resource "google_sql_database_instance" "instance" { - depends_on = [google_service_networking_connection.foobar] name = "%s" region = "us-central1" database_version = "MYSQL_5_7" @@ -3043,7 +2974,7 @@ resource "google_sql_database_instance" "clone1" { clone { source_instance_name = google_sql_database_instance.instance.name - allocated_ip_range = google_compute_global_address.foobar.name + allocated_ip_range = "%s" } settings { @@ -3053,7 +2984,7 @@ resource "google_sql_database_instance" "clone1" { } } } -`, networkName, addressRangeName, databaseName, databaseName) +`, networkName, databaseName, databaseName, addressRangeName) } var testGoogleSqlDatabaseInstance_settings = ` @@ -3193,7 +3124,7 @@ resource "google_sql_database_instance" "instance" { tier = "db-f1-micro" ip_configuration { ipv4_enabled = "false" - private_network = google_compute_network.servicenet.self_link + private_network = data.google_compute_network.servicenet.self_link } } } diff --git a/mmv1/third_party/terraform/services/vertexai/resource_vertex_ai_endpoint_test.go b/mmv1/third_party/terraform/services/vertexai/resource_vertex_ai_endpoint_test.go index f14b9b7c45ab..bc35379f7539 100644 --- a/mmv1/third_party/terraform/services/vertexai/resource_vertex_ai_endpoint_test.go +++ b/mmv1/third_party/terraform/services/vertexai/resource_vertex_ai_endpoint_test.go @@ -18,7 +18,7 @@ func TestAccVertexAIEndpoint_vertexAiEndpointNetwork(t *testing.T) { context := map[string]interface{}{ "endpoint_name": fmt.Sprint(acctest.RandInt(t) % 9999999999), "kms_key_name": acctest.BootstrapKMSKeyInLocation(t, "us-central1").CryptoKey.Name, - "network_name": acctest.BootstrapSharedServiceNetworkingConnection(t, "vertex-ai-endpoint-update"), + "network_name": acctest.BootstrapSharedServiceNetworkingConnection(t, "vertex-ai-endpoint-update-1"), "random_suffix": acctest.RandString(t, 10), } @@ -64,23 +64,6 @@ resource "google_vertex_ai_endpoint" "endpoint" { encryption_spec { kms_key_name = "%{kms_key_name}" } - depends_on = [ - google_service_networking_connection.vertex_vpc_connection - ] -} - -resource "google_service_networking_connection" "vertex_vpc_connection" { - network = data.google_compute_network.vertex_network.id - service = "servicenetworking.googleapis.com" - reserved_peering_ranges = [google_compute_global_address.vertex_range.name] -} - -resource "google_compute_global_address" "vertex_range" { - name = "tf-test-address-name%{random_suffix}" - purpose = "VPC_PEERING" - address_type = "INTERNAL" - prefix_length = 24 - network = data.google_compute_network.vertex_network.id } data "google_compute_network" "vertex_network" { diff --git a/mmv1/third_party/terraform/services/vertexai/resource_vertex_ai_index_endpoint_test.go b/mmv1/third_party/terraform/services/vertexai/resource_vertex_ai_index_endpoint_test.go index 1ddcac555bcd..3a8f34c3f4a7 100644 --- a/mmv1/third_party/terraform/services/vertexai/resource_vertex_ai_index_endpoint_test.go +++ b/mmv1/third_party/terraform/services/vertexai/resource_vertex_ai_index_endpoint_test.go @@ -12,7 +12,7 @@ func TestAccVertexAIIndexEndpoint_updated(t *testing.T) { t.Parallel() context := map[string]interface{}{ - "network_name": acctest.BootstrapSharedServiceNetworkingConnection(t, "vertex-ai-index-endpoint-update"), + "network_name": acctest.BootstrapSharedServiceNetworkingConnection(t, "vertex-ai-index-endpoint-update-1"), "random_suffix": acctest.RandString(t, 10), } @@ -53,15 +53,8 @@ resource "google_vertex_ai_index_endpoint" "index_endpoint" { label-one = "value-one" } network = "projects/${data.google_project.project.number}/global/networks/${data.google_compute_network.vertex_network.name}" - depends_on = [ - google_service_networking_connection.vertex_vpc_connection - ] -} -resource "google_service_networking_connection" "vertex_vpc_connection" { - network = data.google_compute_network.vertex_network.id - service = "servicenetworking.googleapis.com" - reserved_peering_ranges = [google_compute_global_address.vertex_range.name] } + resource "google_compute_global_address" "vertex_range" { name = "tf-test-address-name%{random_suffix}" purpose = "VPC_PEERING" @@ -91,18 +84,7 @@ resource "google_vertex_ai_index_endpoint" "index_endpoint" { google_service_networking_connection.vertex_vpc_connection ] } -resource "google_service_networking_connection" "vertex_vpc_connection" { - network = data.google_compute_network.vertex_network.id - service = "servicenetworking.googleapis.com" - reserved_peering_ranges = [google_compute_global_address.vertex_range.name] -} -resource "google_compute_global_address" "vertex_range" { - name = "tf-test-address-name%{random_suffix}" - purpose = "VPC_PEERING" - address_type = "INTERNAL" - prefix_length = 24 - network = data.google_compute_network.vertex_network.id -} + data "google_compute_network" "vertex_network" { name = "%{network_name}" }