From 568801c027542c63caefd6133bf3b9b06e2f076d Mon Sep 17 00:00:00 2001 From: Zhenhua Li Date: Tue, 5 Sep 2023 16:12:32 -0700 Subject: [PATCH 1/4] Use Create instead of Patch to create google_service_networking_connection --- .../resource_service_networking_connection.go | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) 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 ac1ff4a07912..249b268ba58f 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 @@ -94,27 +94,16 @@ func resourceServiceNetworkingConnectionCreate(d *schema.ResourceData, meta inte project := networkFieldValue.Project parentService := formatParentService(d.Get("service").(string)) - // We use Patch instead of Create, because we're getting - // "Error waiting for Create Service Networking Connection: - // Error code 9, message: Cannot modify allocated ranges in - // CreateConnection. Please use UpdateConnection." - // if we're creating peerings to more than one VPC (like two - // CloudSQL instances within one project, peered with two - // clusters.) - // - // This is a workaround for: - // https://issuetracker.google.com/issues/131908322 - // - // The API docs don't specify that you can do connections/-, - // but that's what gcloud does, and it's easier than grabbing - // the connection name. + + // There is no blocker to use Create method, as the bug in CloudSQL has been fixed (https://b.corp.google.com/issues/123276199). + // Read more in https://stackoverflow.com/questions/55135559/unable-to-recreate-private-service-access-on-gcp // err == nil indicates that the billing_project value was found if bp, err := tpgresource.GetBillingProject(d, config); err == nil { project = bp } - createCall := config.NewServiceNetworkingClient(userAgent).Services.Connections.Patch(parentService+"/connections/-", connection).UpdateMask("reservedPeeringRanges").Force(true) + createCall := config.NewServiceNetworkingClient(userAgent).Services.Connections.Create(parentService, connection) if config.UserProjectOverride { createCall.Header().Add("X-Goog-User-Project", project) } From 9f81798e0b94f6a7cd93d6ff95e181d0412e8713 Mon Sep 17 00:00:00 2001 From: Zhenhua Li Date: Tue, 5 Sep 2023 22:58:01 -0700 Subject: [PATCH 2/4] Remove bootstraped networks for service networking connection --- .../examples/alloydb_backup_basic.tf.erb | 8 ++-- .../examples/alloydb_backup_full.tf.erb | 8 ++-- .../examples/alloydb_instance_basic.tf.erb | 8 ++-- ..._service_connection_profile_alloydb.tf.erb | 8 ++-- .../looker_instance_enterprise_full.tf.erb | 8 ++-- .../examples/memcache_instance_basic.tf.erb | 6 +-- .../redis_instance_private_service.tf.erb | 8 ++-- .../alloydb/resource_alloydb_backup_test.go | 22 ++++----- .../resource_alloydb_cluster_restore_test.go | 10 ++-- .../alloydb/resource_alloydb_instance_test.go | 42 ++++++++--------- ...esource_cloudbuild_worker_pool_test.go.erb | 10 ++-- .../resource_cloudids_endpoint_test.go | 10 ++-- .../resource_memcache_instance_test.go | 10 ++-- .../resource_sql_database_instance_test.go | 46 +++++++++---------- 14 files changed, 102 insertions(+), 102 deletions(-) diff --git a/mmv1/templates/terraform/examples/alloydb_backup_basic.tf.erb b/mmv1/templates/terraform/examples/alloydb_backup_basic.tf.erb index 418ccb67c8ed..41521891bfec 100644 --- a/mmv1/templates/terraform/examples/alloydb_backup_basic.tf.erb +++ b/mmv1/templates/terraform/examples/alloydb_backup_basic.tf.erb @@ -9,7 +9,7 @@ resource "google_alloydb_backup" "<%= ctx[:primary_resource_id] %>" { resource "google_alloydb_cluster" "<%= ctx[:primary_resource_id] %>" { cluster_id = "<%= ctx[:vars]['alloydb_cluster_name'] %>" location = "us-central1" - network = data.google_compute_network.default.id + network = google_compute_network.default.id } resource "google_alloydb_instance" "<%= ctx[:primary_resource_id] %>" { @@ -25,15 +25,15 @@ resource "google_compute_global_address" "private_ip_alloc" { address_type = "INTERNAL" purpose = "VPC_PEERING" prefix_length = 16 - network = data.google_compute_network.default.id + network = google_compute_network.default.id } resource "google_service_networking_connection" "vpc_connection" { - network = data.google_compute_network.default.id + network = google_compute_network.default.id service = "servicenetworking.googleapis.com" reserved_peering_ranges = [google_compute_global_address.private_ip_alloc.name] } -data "google_compute_network" "default" { +resource "google_compute_network" "default" { name = "<%= ctx[:vars]['network_name'] %>" } diff --git a/mmv1/templates/terraform/examples/alloydb_backup_full.tf.erb b/mmv1/templates/terraform/examples/alloydb_backup_full.tf.erb index bb280b783894..cb4e7b45bfde 100644 --- a/mmv1/templates/terraform/examples/alloydb_backup_full.tf.erb +++ b/mmv1/templates/terraform/examples/alloydb_backup_full.tf.erb @@ -13,7 +13,7 @@ resource "google_alloydb_backup" "<%= ctx[:primary_resource_id] %>" { resource "google_alloydb_cluster" "<%= ctx[:primary_resource_id] %>" { cluster_id = "<%= ctx[:vars]['alloydb_cluster_name'] %>" location = "us-central1" - network = data.google_compute_network.default.id + network = google_compute_network.default.id } resource "google_alloydb_instance" "<%= ctx[:primary_resource_id] %>" { @@ -29,15 +29,15 @@ resource "google_compute_global_address" "private_ip_alloc" { address_type = "INTERNAL" purpose = "VPC_PEERING" prefix_length = 16 - network = data.google_compute_network.default.id + network = google_compute_network.default.id } resource "google_service_networking_connection" "vpc_connection" { - network = data.google_compute_network.default.id + network = google_compute_network.default.id service = "servicenetworking.googleapis.com" reserved_peering_ranges = [google_compute_global_address.private_ip_alloc.name] } -data "google_compute_network" "default" { +resource "google_compute_network" "default" { name = "<%= ctx[:vars]['network_name'] %>" } diff --git a/mmv1/templates/terraform/examples/alloydb_instance_basic.tf.erb b/mmv1/templates/terraform/examples/alloydb_instance_basic.tf.erb index f6907cd44237..479245a01cb2 100644 --- a/mmv1/templates/terraform/examples/alloydb_instance_basic.tf.erb +++ b/mmv1/templates/terraform/examples/alloydb_instance_basic.tf.erb @@ -13,7 +13,7 @@ resource "google_alloydb_instance" "<%= ctx[:primary_resource_id] %>" { resource "google_alloydb_cluster" "<%= ctx[:primary_resource_id] %>" { cluster_id = "<%= ctx[:vars]['alloydb_cluster_name'] %>" location = "us-central1" - network = data.google_compute_network.default.id + network = google_compute_network.default.id initial_user { password = "<%= ctx[:vars]['alloydb_cluster_name'] %>" @@ -22,7 +22,7 @@ resource "google_alloydb_cluster" "<%= ctx[:primary_resource_id] %>" { data "google_project" "project" {} -data "google_compute_network" "default" { +resource "google_compute_network" "default" { name = "<%= ctx[:vars]['network_name'] %>" } @@ -31,11 +31,11 @@ resource "google_compute_global_address" "private_ip_alloc" { address_type = "INTERNAL" purpose = "VPC_PEERING" prefix_length = 16 - network = data.google_compute_network.default.id + network = google_compute_network.default.id } resource "google_service_networking_connection" "vpc_connection" { - network = data.google_compute_network.default.id + network = google_compute_network.default.id service = "servicenetworking.googleapis.com" reserved_peering_ranges = [google_compute_global_address.private_ip_alloc.name] } \ No newline at end of file diff --git a/mmv1/templates/terraform/examples/database_migration_service_connection_profile_alloydb.tf.erb b/mmv1/templates/terraform/examples/database_migration_service_connection_profile_alloydb.tf.erb index 68a6ea686b57..96384e6e4b58 100644 --- a/mmv1/templates/terraform/examples/database_migration_service_connection_profile_alloydb.tf.erb +++ b/mmv1/templates/terraform/examples/database_migration_service_connection_profile_alloydb.tf.erb @@ -1,7 +1,7 @@ data "google_project" "project" { } -data "google_compute_network" "default" { +resource "google_compute_network" "default" { name = "<%= ctx[:vars]['network_name'] %>" } @@ -10,11 +10,11 @@ resource "google_compute_global_address" "private_ip_alloc" { address_type = "INTERNAL" purpose = "VPC_PEERING" prefix_length = 16 - network = data.google_compute_network.default.id + network = google_compute_network.default.id } resource "google_service_networking_connection" "vpc_connection" { - network = data.google_compute_network.default.id + network = google_compute_network.default.id service = "servicenetworking.googleapis.com" reserved_peering_ranges = [google_compute_global_address.private_ip_alloc.name] } @@ -34,7 +34,7 @@ resource "google_database_migration_service_connection_profile" "<%= ctx[:primar user = "alloyuser%{random_suffix}" password = "alloypass%{random_suffix}" } - vpc_network = data.google_compute_network.default.id + vpc_network = google_compute_network.default.id labels = { alloyfoo = "alloybar" } diff --git a/mmv1/templates/terraform/examples/looker_instance_enterprise_full.tf.erb b/mmv1/templates/terraform/examples/looker_instance_enterprise_full.tf.erb index 5a223f1e21db..54d74ad63d8e 100644 --- a/mmv1/templates/terraform/examples/looker_instance_enterprise_full.tf.erb +++ b/mmv1/templates/terraform/examples/looker_instance_enterprise_full.tf.erb @@ -5,7 +5,7 @@ resource "google_looker_instance" "<%= ctx[:primary_resource_id] %>" { private_ip_enabled = true public_ip_enabled = false reserved_range = "${google_compute_global_address.looker_range.name}" - consumer_network = data.google_compute_network.looker_network.id + consumer_network = google_compute_network.looker_network.id admin_settings { allowed_email_domains = ["google.com"] } @@ -49,7 +49,7 @@ resource "google_looker_instance" "<%= ctx[:primary_resource_id] %>" { } resource "google_service_networking_connection" "looker_vpc_connection" { - network = data.google_compute_network.looker_network.id + network = google_compute_network.looker_network.id service = "servicenetworking.googleapis.com" reserved_peering_ranges = [google_compute_global_address.looker_range.name] } @@ -59,12 +59,12 @@ resource "google_compute_global_address" "looker_range" { purpose = "VPC_PEERING" address_type = "INTERNAL" prefix_length = 20 - network = data.google_compute_network.looker_network.id + network = google_compute_network.looker_network.id } data "google_project" "project" {} -data "google_compute_network" "looker_network" { +resource "google_compute_network" "looker_network" { name = "<%= ctx[:vars]["network_name"] %>" } diff --git a/mmv1/templates/terraform/examples/memcache_instance_basic.tf.erb b/mmv1/templates/terraform/examples/memcache_instance_basic.tf.erb index e021bacf3d63..0ad8d19378fd 100644 --- a/mmv1/templates/terraform/examples/memcache_instance_basic.tf.erb +++ b/mmv1/templates/terraform/examples/memcache_instance_basic.tf.erb @@ -6,7 +6,7 @@ // If this network hasn't been created and you are using this example in your // config, add an additional network resource or change // this from "data"to "resource" -data "google_compute_network" "memcache_network" { +resource "google_compute_network" "memcache_network" { name = "<%= ctx[:vars]['network_name'] %>" } @@ -15,11 +15,11 @@ resource "google_compute_global_address" "service_range" { purpose = "VPC_PEERING" address_type = "INTERNAL" prefix_length = 16 - network = data.google_compute_network.memcache_network.id + network = google_compute_network.memcache_network.id } resource "google_service_networking_connection" "private_service_connection" { - network = data.google_compute_network.memcache_network.id + network = google_compute_network.memcache_network.id service = "servicenetworking.googleapis.com" reserved_peering_ranges = [google_compute_global_address.service_range.name] } diff --git a/mmv1/templates/terraform/examples/redis_instance_private_service.tf.erb b/mmv1/templates/terraform/examples/redis_instance_private_service.tf.erb index 800df78e22aa..90e0e4ff5698 100644 --- a/mmv1/templates/terraform/examples/redis_instance_private_service.tf.erb +++ b/mmv1/templates/terraform/examples/redis_instance_private_service.tf.erb @@ -6,7 +6,7 @@ // If this network hasn't been created and you are using this example in your // config, add an additional network resource or change // this from "data"to "resource" -data "google_compute_network" "redis-network" { +resource "google_compute_network" "redis-network" { name = "<%= ctx[:vars]['network_name'] %>" } @@ -15,11 +15,11 @@ resource "google_compute_global_address" "service_range" { purpose = "VPC_PEERING" address_type = "INTERNAL" prefix_length = 16 - network = data.google_compute_network.redis-network.id + network = google_compute_network.redis-network.id } resource "google_service_networking_connection" "private_service_connection" { - network = data.google_compute_network.redis-network.id + network = google_compute_network.redis-network.id service = "servicenetworking.googleapis.com" reserved_peering_ranges = [google_compute_global_address.service_range.name] } @@ -32,7 +32,7 @@ resource "google_redis_instance" "<%= ctx[:primary_resource_id] %>" { location_id = "us-central1-a" alternative_location_id = "us-central1-f" - authorized_network = data.google_compute_network.redis-network.id + authorized_network = google_compute_network.redis-network.id connect_mode = "PRIVATE_SERVICE_ACCESS" redis_version = "REDIS_4_0" 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 4da0e5c86fa7..db2b9d690719 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 @@ -11,7 +11,7 @@ func TestAccAlloydbBackup_update(t *testing.T) { t.Parallel() context := map[string]interface{}{ - "network_name": acctest.BootstrapSharedTestNetwork(t, "alloydb-backup-update"), + "network_name": "tf-test-" + acctest.RandString(t, 10), "random_suffix": acctest.RandString(t, 10), } @@ -98,7 +98,7 @@ func TestAccAlloydbBackup_createBackupWithMandatoryFields(t *testing.T) { context := map[string]interface{}{ "random_suffix": acctest.RandString(t, 10), - "network_name": acctest.BootstrapSharedTestNetwork(t, "alloydbbackup-mandatory"), + "network_name": "tf-test-" + acctest.RandString(t, 10), } acctest.VcrTest(t, resource.TestCase{ @@ -125,12 +125,12 @@ resource "google_alloydb_backup" "default" { resource "google_alloydb_cluster" "default" { location = "us-central1" cluster_id = "tf-test-alloydb-cluster%{random_suffix}" - network = data.google_compute_network.default.id + network = google_compute_network.default.id } data "google_project" "project" { } -data "google_compute_network" "default" { +resource "google_compute_network" "default" { name = "%{network_name}" } @@ -147,7 +147,7 @@ resource "google_compute_global_address" "private_ip_alloc" { address_type = "INTERNAL" purpose = "VPC_PEERING" prefix_length = 16 - network = data.google_compute_network.default.id + network = google_compute_network.default.id lifecycle { ignore_changes = [ address, @@ -161,7 +161,7 @@ resource "google_compute_global_address" "private_ip_alloc" { } resource "google_service_networking_connection" "vpc_connection" { - network = data.google_compute_network.default.id + network = google_compute_network.default.id service = "servicenetworking.googleapis.com" reserved_peering_ranges = [google_compute_global_address.private_ip_alloc.name] } @@ -172,7 +172,7 @@ func TestAccAlloydbBackup_usingCMEK(t *testing.T) { t.Parallel() context := map[string]interface{}{ - "network_name": acctest.BootstrapSharedTestNetwork(t, "alloydb-backup-cmek"), + "network_name": "tf-test-" + acctest.RandString(t, 10), "random_suffix": acctest.RandString(t, 10), "key_name": "tf-test-key-" + acctest.RandString(t, 10), } @@ -215,7 +215,7 @@ resource "google_alloydb_backup" "default" { resource "google_alloydb_cluster" "default" { cluster_id = "tf-test-alloydb-cluster%{random_suffix}" location = "us-central1" - network = data.google_compute_network.default.id + network = google_compute_network.default.id } resource "google_alloydb_instance" "default" { @@ -231,16 +231,16 @@ resource "google_compute_global_address" "private_ip_alloc" { address_type = "INTERNAL" purpose = "VPC_PEERING" prefix_length = 16 - network = data.google_compute_network.default.id + network = google_compute_network.default.id } resource "google_service_networking_connection" "vpc_connection" { - network = data.google_compute_network.default.id + network = google_compute_network.default.id service = "servicenetworking.googleapis.com" reserved_peering_ranges = [google_compute_global_address.private_ip_alloc.name] } -data "google_compute_network" "default" { +resource "google_compute_network" "default" { name = "%{network_name}" } data "google_project" "project" {} 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 d6def69f6832..c4aa8de30b95 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.BootstrapSharedTestNetwork(t, "alloydbinstance-restore"), + "network_name": "tf-test-" + acctest.RandString(t, 10), } acctest.VcrTest(t, resource.TestCase{ @@ -86,7 +86,7 @@ func testAccAlloydbClusterAndInstanceAndBackup(context map[string]interface{}) s resource "google_alloydb_cluster" "source" { cluster_id = "tf-test-alloydb-cluster%{random_suffix}" location = "us-central1" - network = data.google_compute_network.default.id + network = google_compute_network.default.id } resource "google_alloydb_instance" "source" { @@ -107,7 +107,7 @@ resource "google_alloydb_backup" "default" { data "google_project" "project" {} -data "google_compute_network" "default" { +resource "google_compute_network" "default" { name = "%{network_name}" } @@ -116,11 +116,11 @@ resource "google_compute_global_address" "private_ip_alloc" { address_type = "INTERNAL" purpose = "VPC_PEERING" prefix_length = 16 - network = data.google_compute_network.default.id + network = google_compute_network.default.id } resource "google_service_networking_connection" "vpc_connection" { - network = data.google_compute_network.default.id + network = google_compute_network.default.id service = "servicenetworking.googleapis.com" reserved_peering_ranges = [google_compute_global_address.private_ip_alloc.name] } 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 944d04c25ad1..754f3c64d865 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 @@ -12,7 +12,7 @@ func TestAccAlloydbInstance_update(t *testing.T) { context := map[string]interface{}{ "random_suffix": acctest.RandString(t, 10), - "network_name": acctest.BootstrapSharedTestNetwork(t, "alloydbinstance-update"), + "network_name": "tf-test-" + acctest.RandString(t, 10), } acctest.VcrTest(t, resource.TestCase{ @@ -99,7 +99,7 @@ func TestAccAlloydbInstance_createInstanceWithMandatoryFields(t *testing.T) { context := map[string]interface{}{ "random_suffix": acctest.RandString(t, 10), - "network_name": acctest.BootstrapSharedTestNetwork(t, "alloydbinstance-mandatory"), + "network_name": "tf-test-" + acctest.RandString(t, 10), } acctest.VcrTest(t, resource.TestCase{ @@ -127,12 +127,12 @@ resource "google_alloydb_instance" "default" { resource "google_alloydb_cluster" "default" { cluster_id = "tf-test-alloydb-cluster%{random_suffix}" location = "us-central1" - network = data.google_compute_network.default.id + network = google_compute_network.default.id } data "google_project" "project" {} -data "google_compute_network" "default" { +resource "google_compute_network" "default" { name = "%{network_name}" } @@ -141,11 +141,11 @@ resource "google_compute_global_address" "private_ip_alloc" { address_type = "INTERNAL" purpose = "VPC_PEERING" prefix_length = 16 - network = data.google_compute_network.default.id + network = google_compute_network.default.id } resource "google_service_networking_connection" "vpc_connection" { - network = data.google_compute_network.default.id + network = google_compute_network.default.id service = "servicenetworking.googleapis.com" reserved_peering_ranges = [google_compute_global_address.private_ip_alloc.name] } @@ -158,7 +158,7 @@ func TestAccAlloydbInstance_createInstanceWithMaximumFields(t *testing.T) { context := map[string]interface{}{ "random_suffix": acctest.RandString(t, 10), - "network_name": acctest.BootstrapSharedTestNetwork(t, "alloydbinstance-maximum"), + "network_name": "tf-test-" + acctest.RandString(t, 10), } acctest.VcrTest(t, resource.TestCase{ @@ -205,12 +205,12 @@ resource "google_alloydb_instance" "default" { resource "google_alloydb_cluster" "default" { cluster_id = "tf-test-alloydb-cluster%{random_suffix}" location = "us-central1" - network = data.google_compute_network.default.id + network = google_compute_network.default.id } data "google_project" "project" {} -data "google_compute_network" "default" { +resource "google_compute_network" "default" { name = "%{network_name}" } @@ -219,11 +219,11 @@ resource "google_compute_global_address" "private_ip_alloc" { address_type = "INTERNAL" purpose = "VPC_PEERING" prefix_length = 16 - network = data.google_compute_network.default.id + network = google_compute_network.default.id } resource "google_service_networking_connection" "vpc_connection" { - network = data.google_compute_network.default.id + network = google_compute_network.default.id service = "servicenetworking.googleapis.com" reserved_peering_ranges = [google_compute_global_address.private_ip_alloc.name] } @@ -236,7 +236,7 @@ func TestAccAlloydbInstance_createPrimaryAndReadPoolInstance(t *testing.T) { context := map[string]interface{}{ "random_suffix": acctest.RandString(t, 10), - "network_name": acctest.BootstrapSharedTestNetwork(t, "alloydbinstance-readpool"), + "network_name": "tf-test-" + acctest.RandString(t, 10), } acctest.VcrTest(t, resource.TestCase{ @@ -273,12 +273,12 @@ resource "google_alloydb_instance" "read_pool" { resource "google_alloydb_cluster" "default" { cluster_id = "tf-test-alloydb-cluster%{random_suffix}" location = "us-central1" - network = data.google_compute_network.default.id + network = google_compute_network.default.id } data "google_project" "project" {} -data "google_compute_network" "default" { +resource "google_compute_network" "default" { name = "%{network_name}" } @@ -287,11 +287,11 @@ resource "google_compute_global_address" "private_ip_alloc" { address_type = "INTERNAL" purpose = "VPC_PEERING" prefix_length = 16 - network = data.google_compute_network.default.id + network = google_compute_network.default.id } resource "google_service_networking_connection" "vpc_connection" { - network = data.google_compute_network.default.id + network = google_compute_network.default.id service = "servicenetworking.googleapis.com" reserved_peering_ranges = [google_compute_global_address.private_ip_alloc.name] } @@ -304,7 +304,7 @@ func TestAccAlloydbInstance_updateDatabaseFlagInPrimaryInstance(t *testing.T) { context := map[string]interface{}{ "random_suffix": acctest.RandString(t, 10), - "network_name": acctest.BootstrapSharedTestNetwork(t, "alloydbinstance-updatedb"), + "network_name": "tf-test-" + acctest.RandString(t, 10), } acctest.VcrTest(t, resource.TestCase{ @@ -342,12 +342,12 @@ resource "google_alloydb_instance" "primary" { resource "google_alloydb_cluster" "default" { cluster_id = "tf-test-alloydb-cluster%{random_suffix}" location = "us-central1" - network = data.google_compute_network.default.id + network = google_compute_network.default.id } data "google_project" "project" {} -data "google_compute_network" "default" { +resource "google_compute_network" "default" { name = "%{network_name}" } @@ -356,11 +356,11 @@ resource "google_compute_global_address" "private_ip_alloc" { address_type = "INTERNAL" purpose = "VPC_PEERING" prefix_length = 16 - network = data.google_compute_network.default.id + network = google_compute_network.default.id } resource "google_service_networking_connection" "vpc_connection" { - network = data.google_compute_network.default.id + network = google_compute_network.default.id service = "servicenetworking.googleapis.com" reserved_peering_ranges = [google_compute_global_address.private_ip_alloc.name] } 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 601dc86d27d9..6cc7a87dd96c 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.BootstrapSharedTestNetwork(t, "cloudbuild-workerpool"), + "network_name": "tf-test-" + acctest.RandString(t, 10), } acctest.VcrTest(t, resource.TestCase{ @@ -127,7 +127,7 @@ func TestAccCloudbuildWorkerPool_withNetwork(t *testing.T) { func testAccCloudbuildWorkerPool_withNetwork(context map[string]interface{}) string { return acctest.Nprintf(` -data "google_compute_network" "network" { +resource "google_compute_network" "network" { name = "%{network_name}" } @@ -136,11 +136,11 @@ resource "google_compute_global_address" "worker_range" { purpose = "VPC_PEERING" address_type = "INTERNAL" prefix_length = 16 - network = data.google_compute_network.network.id + network = google_compute_network.network.id } resource "google_service_networking_connection" "worker_pool_conn" { - network = data.google_compute_network.network.id + network = google_compute_network.network.id service = "servicenetworking.googleapis.com" reserved_peering_ranges = [google_compute_global_address.worker_range.name] } @@ -154,7 +154,7 @@ resource "google_cloudbuild_worker_pool" "pool" { no_external_ip = false } network_config { - peered_network = data.google_compute_network.network.id + peered_network = google_compute_network.network.id peered_network_ip_range = "/29" } depends_on = [google_service_networking_connection.worker_pool_conn] 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 65153dada11c..befd7e26a0f4 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.BootstrapSharedTestNetwork(t, "cloud-ids-endpoint"), + "network_name": "tf-test-key-" + acctest.RandString(t, 10), } acctest.VcrTest(t, resource.TestCase{ @@ -48,7 +48,7 @@ func TestAccCloudIdsEndpoint_basic(t *testing.T) { func testCloudIds_basic(context map[string]interface{}) string { return acctest.Nprintf(` -data "google_compute_network" "default" { +resource "google_compute_network" "default" { name = "%{network_name}" } resource "google_compute_global_address" "service_range" { @@ -56,10 +56,10 @@ resource "google_compute_global_address" "service_range" { purpose = "VPC_PEERING" address_type = "INTERNAL" prefix_length = 16 - network = data.google_compute_network.default.id + network = google_compute_network.default.id } resource "google_service_networking_connection" "private_service_connection" { - network = data.google_compute_network.default.id + network = google_compute_network.default.id service = "servicenetworking.googleapis.com" reserved_peering_ranges = [google_compute_global_address.service_range.name] } @@ -67,7 +67,7 @@ resource "google_service_networking_connection" "private_service_connection" { resource "google_cloud_ids_endpoint" "endpoint" { name = "cloud-ids-test-%{random_suffix}" location = "us-central1-f" - network = data.google_compute_network.default.id + network = google_compute_network.default.id severity = "INFORMATIONAL" threat_exceptions = ["12", "67"] depends_on = [google_service_networking_connection.private_service_connection] 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 51b78686511e..8aee02618aed 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.BootstrapSharedTestNetwork(t, "memcache-instance-update") + network := "tf-test-" + acctest.RandString(t, 10) acctest.VcrTest(t, resource.TestCase{ PreCheck: func() { acctest.AccTestPreCheck(t) }, @@ -47,11 +47,11 @@ resource "google_compute_global_address" "service_range" { purpose = "VPC_PEERING" address_type = "INTERNAL" prefix_length = 16 - network = data.google_compute_network.memcache_network.id + network = google_compute_network.memcache_network.id } resource "google_service_networking_connection" "private_service_connection" { - network = data.google_compute_network.memcache_network.id + network = google_compute_network.memcache_network.id service = "servicenetworking.googleapis.com" reserved_peering_ranges = [google_compute_global_address.service_range.name] } @@ -75,7 +75,7 @@ resource "google_memcache_instance" "test" { } } -data "google_compute_network" "memcache_network" { +resource "google_compute_network" "memcache_network" { name = "%s" } `, prefix, name, network) @@ -116,7 +116,7 @@ resource "google_memcache_instance" "test" { } } -data "google_compute_network" "memcache_network" { +resource "google_compute_network" "memcache_network" { name = "%s" } `, prefix, name, network) 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 64607beb5cb0..4e6ae71c142c 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 @@ -179,7 +179,7 @@ func TestAccSqlDatabaseInstance_deleteDefaultUserBeforeSubsequentApiCalls(t *tes databaseName := "tf-test-" + acctest.RandString(t, 10) addressName := "tf-test-" + acctest.RandString(t, 10) - networkName := acctest.BootstrapSharedTestNetwork(t, "sql-instance-private-network-clone-2") + networkName := "tf-test-" + acctest.RandString(t, 10) // 1. Create an instance. // 2. Add a root@'%' user. @@ -737,7 +737,7 @@ func TestAccSqlDatabaseInstance_withPrivateNetwork_withoutAllocatedIpRange(t *te databaseName := "tf-test-" + acctest.RandString(t, 10) addressName := "tf-test-" + acctest.RandString(t, 10) - networkName := acctest.BootstrapSharedTestNetwork(t, "sql-instance-private-network") + networkName := "tf-test-" + acctest.RandString(t, 10) acctest.VcrTest(t, resource.TestCase{ PreCheck: func() { acctest.AccTestPreCheck(t) }, @@ -970,9 +970,9 @@ func TestAccSqlDatabaseInstance_withPrivateNetwork_withAllocatedIpRange(t *testi databaseName := "tf-test-" + acctest.RandString(t, 10) addressName := "tf-test-" + acctest.RandString(t, 10) - networkName := acctest.BootstrapSharedTestNetwork(t, "sql-instance-private-network-allocated") + networkName := "tf-test-" + acctest.RandString(t, 10) addressName_update := "tf-test-" + acctest.RandString(t, 10) + "update" - networkName_update := acctest.BootstrapSharedTestNetwork(t, "sql-instance-private-network-allocated-update") + networkName_update := "tf-test-" + acctest.RandString(t, 10) + "update" acctest.VcrTest(t, resource.TestCase{ PreCheck: func() { acctest.AccTestPreCheck(t) }, @@ -1007,7 +1007,7 @@ func TestAccSqlDatabaseInstance_withPrivateNetwork_withAllocatedIpRangeReplica(t databaseName := "tf-test-" + acctest.RandString(t, 10) addressName := "tf-test-" + acctest.RandString(t, 10) - networkName := acctest.BootstrapSharedTestNetwork(t, "sql-instance-private-network-replica") + networkName := "tf-test-" + acctest.RandString(t, 10) acctest.VcrTest(t, resource.TestCase{ PreCheck: func() { acctest.AccTestPreCheck(t) }, @@ -1039,7 +1039,7 @@ func TestAccSqlDatabaseInstance_withPrivateNetwork_withAllocatedIpRangeClone(t * databaseName := "tf-test-" + acctest.RandString(t, 10) addressName := "tf-test-" + acctest.RandString(t, 10) - networkName := acctest.BootstrapSharedTestNetwork(t, "sql-instance-private-network-clone") + networkName := "tf-test-" + acctest.RandString(t, 10) acctest.VcrTest(t, resource.TestCase{ PreCheck: func() { acctest.AccTestPreCheck(t) }, @@ -2798,7 +2798,7 @@ func testAccSqlDatabaseInstance_withPrivateNetwork_withoutAllocatedIpRange(datab } return fmt.Sprintf(` -data "google_compute_network" "servicenet" { +resource "google_compute_network" "servicenet" { name = "%s" } @@ -2807,11 +2807,11 @@ resource "google_compute_global_address" "foobar" { purpose = "VPC_PEERING" address_type = "INTERNAL" prefix_length = 16 - network = data.google_compute_network.servicenet.self_link + network = google_compute_network.servicenet.self_link } resource "google_service_networking_connection" "foobar" { - network = data.google_compute_network.servicenet.self_link + network = google_compute_network.servicenet.self_link service = "servicenetworking.googleapis.com" reserved_peering_ranges = [google_compute_global_address.foobar.name] } @@ -2826,7 +2826,7 @@ resource "google_sql_database_instance" "instance" { tier = "db-f1-micro" ip_configuration { ipv4_enabled = "false" - private_network = data.google_compute_network.servicenet.self_link + private_network = google_compute_network.servicenet.self_link %s } } @@ -2836,7 +2836,7 @@ resource "google_sql_database_instance" "instance" { func testAccSqlDatabaseInstance_withPrivateNetwork_withAllocatedIpRange(databaseName, networkName, addressRangeName string) string { return fmt.Sprintf(` -data "google_compute_network" "servicenet" { +resource "google_compute_network" "servicenet" { name = "%s" } @@ -2845,11 +2845,11 @@ resource "google_compute_global_address" "foobar" { purpose = "VPC_PEERING" address_type = "INTERNAL" prefix_length = 16 - network = data.google_compute_network.servicenet.self_link + network = google_compute_network.servicenet.self_link } resource "google_service_networking_connection" "foobar" { - network = data.google_compute_network.servicenet.self_link + network = google_compute_network.servicenet.self_link service = "servicenetworking.googleapis.com" reserved_peering_ranges = [google_compute_global_address.foobar.name] } @@ -2864,7 +2864,7 @@ resource "google_sql_database_instance" "instance" { tier = "db-f1-micro" ip_configuration { ipv4_enabled = "false" - private_network = data.google_compute_network.servicenet.self_link + private_network = google_compute_network.servicenet.self_link allocated_ip_range = google_compute_global_address.foobar.name } } @@ -2874,7 +2874,7 @@ resource "google_sql_database_instance" "instance" { func testAccSqlDatabaseInstance_withPrivateNetwork_withAllocatedIpRangeReplica(databaseName, networkName, addressRangeName string) string { return fmt.Sprintf(` -data "google_compute_network" "servicenet" { +resource "google_compute_network" "servicenet" { name = "%s" } @@ -2883,11 +2883,11 @@ resource "google_compute_global_address" "foobar" { purpose = "VPC_PEERING" address_type = "INTERNAL" prefix_length = 16 - network = data.google_compute_network.servicenet.self_link + network = google_compute_network.servicenet.self_link } resource "google_service_networking_connection" "foobar" { - network = data.google_compute_network.servicenet.self_link + network = google_compute_network.servicenet.self_link service = "servicenetworking.googleapis.com" reserved_peering_ranges = [google_compute_global_address.foobar.name] } @@ -2902,7 +2902,7 @@ resource "google_sql_database_instance" "instance" { tier = "db-f1-micro" ip_configuration { ipv4_enabled = "false" - private_network = data.google_compute_network.servicenet.self_link + private_network = google_compute_network.servicenet.self_link } backup_configuration { enabled = true @@ -2921,7 +2921,7 @@ resource "google_sql_database_instance" "replica1" { tier = "db-f1-micro" ip_configuration { ipv4_enabled = "false" - private_network = data.google_compute_network.servicenet.self_link + private_network = google_compute_network.servicenet.self_link allocated_ip_range = google_compute_global_address.foobar.name } } @@ -2942,7 +2942,7 @@ resource "google_sql_database_instance" "replica1" { func testAccSqlDatabaseInstance_withPrivateNetwork_withAllocatedIpRangeClone(databaseName, networkName, addressRangeName string) string { return fmt.Sprintf(` -data "google_compute_network" "servicenet" { +resource "google_compute_network" "servicenet" { name = "%s" } @@ -2951,11 +2951,11 @@ resource "google_compute_global_address" "foobar" { purpose = "VPC_PEERING" address_type = "INTERNAL" prefix_length = 16 - network = data.google_compute_network.servicenet.self_link + network = google_compute_network.servicenet.self_link } resource "google_service_networking_connection" "foobar" { - network = data.google_compute_network.servicenet.self_link + network = google_compute_network.servicenet.self_link service = "servicenetworking.googleapis.com" reserved_peering_ranges = [google_compute_global_address.foobar.name] } @@ -2970,7 +2970,7 @@ resource "google_sql_database_instance" "instance" { tier = "db-f1-micro" ip_configuration { ipv4_enabled = "false" - private_network = data.google_compute_network.servicenet.self_link + private_network = google_compute_network.servicenet.self_link } backup_configuration { enabled = true From bae7b3f28d9cf6610cdf57bcc8c9829a8e502e0b Mon Sep 17 00:00:00 2001 From: Zhenhua Li Date: Wed, 6 Sep 2023 08:16:41 -0700 Subject: [PATCH 3/4] Use resource google_compute_network for tests --- mmv1/products/alloydb/Backup.yaml | 4 ---- mmv1/products/alloydb/Instance.yaml | 2 -- .../databasemigrationservice/connectionprofile.yaml | 2 -- mmv1/products/looker/Instance.yaml | 1 - mmv1/products/memcache/Instance.yaml | 2 -- mmv1/products/redis/Instance.yaml | 2 -- .../services/alloydb/resource_alloydb_backup_test.go | 8 ++++---- .../services/alloydb/resource_alloydb_instance_test.go | 8 ++++---- .../services/cloudids/resource_cloudids_endpoint_test.go | 8 ++++---- .../services/memcache/resource_memcache_instance_test.go | 4 ++-- .../services/sql/resource_sql_database_instance_test.go | 8 ++++---- 11 files changed, 18 insertions(+), 31 deletions(-) diff --git a/mmv1/products/alloydb/Backup.yaml b/mmv1/products/alloydb/Backup.yaml index 3d4ac4cbf1c8..36a9f4339914 100644 --- a/mmv1/products/alloydb/Backup.yaml +++ b/mmv1/products/alloydb/Backup.yaml @@ -42,8 +42,6 @@ examples: alloydb_cluster_name: 'alloydb-cluster' alloydb_instance_name: 'alloydb-instance' network_name: 'alloydb-network' - test_vars_overrides: - network_name: 'acctest.BootstrapSharedTestNetwork(t, "alloydb-backup-basic")' ignore_read_extra: - 'reconciling' - 'update_time' @@ -55,8 +53,6 @@ examples: alloydb_cluster_name: 'alloydb-cluster' alloydb_instance_name: 'alloydb-instance' network_name: 'alloydb-network' - test_vars_overrides: - network_name: 'acctest.BootstrapSharedTestNetwork(t, "alloydb-backup-full")' ignore_read_extra: - 'reconciling' - 'update_time' diff --git a/mmv1/products/alloydb/Instance.yaml b/mmv1/products/alloydb/Instance.yaml index a8929b3965c7..5530c7434fa0 100644 --- a/mmv1/products/alloydb/Instance.yaml +++ b/mmv1/products/alloydb/Instance.yaml @@ -57,8 +57,6 @@ examples: alloydb_cluster_name: 'alloydb-cluster' alloydb_instance_name: 'alloydb-instance' network_name: 'alloydb-network' - test_vars_overrides: - network_name: 'acctest.BootstrapSharedTestNetwork(t, "alloydb-instance-basic")' ignore_read_extra: - 'reconciling' - 'update_time' diff --git a/mmv1/products/databasemigrationservice/connectionprofile.yaml b/mmv1/products/databasemigrationservice/connectionprofile.yaml index 3396127ae17b..62e6fc778024 100644 --- a/mmv1/products/databasemigrationservice/connectionprofile.yaml +++ b/mmv1/products/databasemigrationservice/connectionprofile.yaml @@ -87,8 +87,6 @@ examples: profile: 'my-profileid' global_address_name: 'private-ip-alloc' network_name: 'vpc-network' - test_vars_overrides: - network_name: 'acctest.BootstrapSharedTestNetwork(t, "profile-alloydb")' parameters: - !ruby/object:Api::Type::String name: 'connectionProfileId' diff --git a/mmv1/products/looker/Instance.yaml b/mmv1/products/looker/Instance.yaml index 7e645702f776..b830b54c7ac8 100644 --- a/mmv1/products/looker/Instance.yaml +++ b/mmv1/products/looker/Instance.yaml @@ -57,7 +57,6 @@ examples: client_id: 'my-client-id' client_secret: 'my-client-secret' test_vars_overrides: - network_name: 'acctest.BootstrapSharedTestNetwork(t, "looker-instance-enterprise")' kms_key_name: 'acctest.BootstrapKMSKeyInLocation(t, "us-central1").CryptoKey.Name' parameters: - !ruby/object:Api::Type::String diff --git a/mmv1/products/memcache/Instance.yaml b/mmv1/products/memcache/Instance.yaml index 11637e7d1cd4..a3dd514aa13f 100644 --- a/mmv1/products/memcache/Instance.yaml +++ b/mmv1/products/memcache/Instance.yaml @@ -37,8 +37,6 @@ examples: instance_name: 'test-instance' network_name: 'test-network' address_name: 'address' - test_vars_overrides: - network_name: 'acctest.BootstrapSharedTestNetwork(t, "memcache-instance-basic")' parameters: - !ruby/object:Api::Type::String name: 'region' diff --git a/mmv1/products/redis/Instance.yaml b/mmv1/products/redis/Instance.yaml index b232ae4e69bd..e49c6e3ee36c 100644 --- a/mmv1/products/redis/Instance.yaml +++ b/mmv1/products/redis/Instance.yaml @@ -67,8 +67,6 @@ examples: instance_name: 'private-cache' address_name: 'address' network_name: 'redis-test-network' - test_vars_overrides: - network_name: 'acctest.BootstrapSharedTestNetwork(t, "redis-private-service")' - !ruby/object:Provider::Terraform::Examples name: 'redis_instance_mrr' primary_resource_id: 'cache' 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 db2b9d690719..9ef5405ff1d1 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 @@ -61,7 +61,7 @@ resource "google_alloydb_backup" "default" { resource "google_alloydb_cluster" "default" { cluster_id = "tf-test-alloydb-cluster%{random_suffix}" location = "us-central1" - network = data.google_compute_network.default.id + network = google_compute_network.default.id } resource "google_alloydb_instance" "default" { @@ -77,16 +77,16 @@ resource "google_compute_global_address" "private_ip_alloc" { address_type = "INTERNAL" purpose = "VPC_PEERING" prefix_length = 16 - network = data.google_compute_network.default.id + network = google_compute_network.default.id } resource "google_service_networking_connection" "vpc_connection" { - network = data.google_compute_network.default.id + network = google_compute_network.default.id service = "servicenetworking.googleapis.com" reserved_peering_ranges = [google_compute_global_address.private_ip_alloc.name] } -data "google_compute_network" "default" { +resource "google_compute_network" "default" { name = "%{network_name}" } `, context) 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 754f3c64d865..11e81c33df77 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 @@ -382,12 +382,12 @@ resource "google_alloydb_instance" "primary" { resource "google_alloydb_cluster" "default" { cluster_id = "tf-test-alloydb-cluster%{random_suffix}" location = "us-central1" - network = data.google_compute_network.default.id + network = google_compute_network.default.id } data "google_project" "project" {} -data "google_compute_network" "default" { +resource "google_compute_network" "default" { name = "%{network_name}" } @@ -396,11 +396,11 @@ resource "google_compute_global_address" "private_ip_alloc" { address_type = "INTERNAL" purpose = "VPC_PEERING" prefix_length = 16 - network = data.google_compute_network.default.id + network = google_compute_network.default.id } resource "google_service_networking_connection" "vpc_connection" { - network = data.google_compute_network.default.id + network = google_compute_network.default.id service = "servicenetworking.googleapis.com" reserved_peering_ranges = [google_compute_global_address.private_ip_alloc.name] } 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 befd7e26a0f4..3e6f8a626c90 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 @@ -77,7 +77,7 @@ resource "google_cloud_ids_endpoint" "endpoint" { func testCloudIds_basicUpdate(context map[string]interface{}) string { return acctest.Nprintf(` -data "google_compute_network" "default" { +resource "google_compute_network" "default" { name = "%{network_name}" } resource "google_compute_global_address" "service_range" { @@ -85,10 +85,10 @@ resource "google_compute_global_address" "service_range" { purpose = "VPC_PEERING" address_type = "INTERNAL" prefix_length = 16 - network = data.google_compute_network.default.id + network = google_compute_network.default.id } resource "google_service_networking_connection" "private_service_connection" { - network = data.google_compute_network.default.id + network = google_compute_network.default.id service = "servicenetworking.googleapis.com" reserved_peering_ranges = [google_compute_global_address.service_range.name] } @@ -96,7 +96,7 @@ resource "google_service_networking_connection" "private_service_connection" { resource "google_cloud_ids_endpoint" "endpoint" { name = "cloud-ids-test-%{random_suffix}" location = "us-central1-f" - network = data.google_compute_network.default.id + network = google_compute_network.default.id severity = "INFORMATIONAL" threat_exceptions = ["33"] depends_on = [google_service_networking_connection.private_service_connection] 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 8aee02618aed..7c42f5632e91 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 @@ -88,11 +88,11 @@ resource "google_compute_global_address" "service_range" { purpose = "VPC_PEERING" address_type = "INTERNAL" prefix_length = 16 - network = data.google_compute_network.memcache_network.id + network = google_compute_network.memcache_network.id } resource "google_service_networking_connection" "private_service_connection" { - network = data.google_compute_network.memcache_network.id + network = google_compute_network.memcache_network.id service = "servicenetworking.googleapis.com" reserved_peering_ranges = [google_compute_global_address.service_range.name] } 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 4e6ae71c142c..fa295d443061 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 @@ -2997,7 +2997,7 @@ resource "google_sql_database_instance" "clone1" { func testAccSqlDatabaseInstance_withPrivateNetwork_withAllocatedIpRangeClone_withSettings(databaseName, networkName, addressRangeName string) string { return fmt.Sprintf(` -data "google_compute_network" "servicenet" { +resource "google_compute_network" "servicenet" { name = "%s" } @@ -3006,11 +3006,11 @@ resource "google_compute_global_address" "foobar" { purpose = "VPC_PEERING" address_type = "INTERNAL" prefix_length = 16 - network = data.google_compute_network.servicenet.self_link + network = google_compute_network.servicenet.self_link } resource "google_service_networking_connection" "foobar" { - network = data.google_compute_network.servicenet.self_link + network = google_compute_network.servicenet.self_link service = "servicenetworking.googleapis.com" reserved_peering_ranges = [google_compute_global_address.foobar.name] } @@ -3025,7 +3025,7 @@ resource "google_sql_database_instance" "instance" { tier = "db-f1-micro" ip_configuration { ipv4_enabled = "false" - private_network = data.google_compute_network.servicenet.self_link + private_network = google_compute_network.servicenet.self_link } backup_configuration { enabled = true From 27b07f9d31ce869a7ff2e53ec8f3f7689b131dbb Mon Sep 17 00:00:00 2001 From: Zhenhua Li Date: Wed, 6 Sep 2023 11:40:10 -0700 Subject: [PATCH 4/4] Fix tests --- .../alloydb/resource_alloydb_backup_test.go | 5 +- .../resource_alloydb_cluster_restore_test.go | 78 +++++++++---------- .../alloydb/resource_alloydb_instance_test.go | 13 ++-- 3 files changed, 49 insertions(+), 47 deletions(-) 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 9ef5405ff1d1..33091f142314 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 @@ -10,9 +10,10 @@ import ( func TestAccAlloydbBackup_update(t *testing.T) { t.Parallel() + random_suffix := acctest.RandString(t, 10) context := map[string]interface{}{ - "network_name": "tf-test-" + acctest.RandString(t, 10), - "random_suffix": acctest.RandString(t, 10), + "network_name": "tf-test-alloydb-network" + random_suffix, + "random_suffix": random_suffix, } acctest.VcrTest(t, resource.TestCase{ 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 c4aa8de30b95..9e3d209581e0 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 @@ -133,7 +133,7 @@ func testAccAlloydbClusterAndInstanceAndBackup_OnlyOneSourceAllowed(context map[ resource "google_alloydb_cluster" "source" { cluster_id = "tf-test-alloydb-cluster%{random_suffix}" location = "us-central1" - network = data.google_compute_network.default.id + network = google_compute_network.default.id } resource "google_alloydb_instance" "source" { @@ -155,7 +155,7 @@ resource "google_alloydb_backup" "default" { resource "google_alloydb_cluster" "restored" { cluster_id = "tf-test-alloydb-backup-restored-cluster-%{random_suffix}" location = "us-central1" - network = data.google_compute_network.default.id + network = google_compute_network.default.id restore_backup_source { backup_name = google_alloydb_backup.default.name } @@ -171,7 +171,7 @@ resource "google_alloydb_cluster" "restored" { data "google_project" "project" {} -data "google_compute_network" "default" { +resource "google_compute_network" "default" { name = "%{network_name}" } @@ -180,11 +180,11 @@ resource "google_compute_global_address" "private_ip_alloc" { address_type = "INTERNAL" purpose = "VPC_PEERING" prefix_length = 16 - network = data.google_compute_network.default.id + network = google_compute_network.default.id } resource "google_service_networking_connection" "vpc_connection" { - network = data.google_compute_network.default.id + network = google_compute_network.default.id service = "servicenetworking.googleapis.com" reserved_peering_ranges = [google_compute_global_address.private_ip_alloc.name] } @@ -197,7 +197,7 @@ func testAccAlloydbClusterAndInstanceAndBackup_SourceClusterAndPointInTimeRequir resource "google_alloydb_cluster" "source" { cluster_id = "tf-test-alloydb-cluster%{random_suffix}" location = "us-central1" - network = data.google_compute_network.default.id + network = google_compute_network.default.id } resource "google_alloydb_instance" "source" { @@ -219,7 +219,7 @@ resource "google_alloydb_backup" "default" { resource "google_alloydb_cluster" "restored" { cluster_id = "tf-test-alloydb-backup-restored-cluster-%{random_suffix}" location = "us-central1" - network = data.google_compute_network.default.id + network = google_compute_network.default.id restore_continuous_backup_source { cluster = google_alloydb_cluster.source.name @@ -232,7 +232,7 @@ resource "google_alloydb_cluster" "restored" { data "google_project" "project" {} -data "google_compute_network" "default" { +resource "google_compute_network" "default" { name = "%{network_name}" } @@ -241,11 +241,11 @@ resource "google_compute_global_address" "private_ip_alloc" { address_type = "INTERNAL" purpose = "VPC_PEERING" prefix_length = 16 - network = data.google_compute_network.default.id + network = google_compute_network.default.id } resource "google_service_networking_connection" "vpc_connection" { - network = data.google_compute_network.default.id + network = google_compute_network.default.id service = "servicenetworking.googleapis.com" reserved_peering_ranges = [google_compute_global_address.private_ip_alloc.name] } @@ -257,7 +257,7 @@ func testAccAlloydbClusterAndInstanceAndBackup_RestoredFromBackup(context map[st resource "google_alloydb_cluster" "source" { cluster_id = "tf-test-alloydb-cluster%{random_suffix}" location = "us-central1" - network = data.google_compute_network.default.id + network = google_compute_network.default.id } resource "google_alloydb_instance" "source" { @@ -279,7 +279,7 @@ resource "google_alloydb_backup" "default" { resource "google_alloydb_cluster" "restored_from_backup" { cluster_id = "tf-test-alloydb-backup-restored-cluster-%{random_suffix}" location = "us-central1" - network = data.google_compute_network.default.id + network = google_compute_network.default.id restore_backup_source { backup_name = google_alloydb_backup.default.name } @@ -291,7 +291,7 @@ resource "google_alloydb_cluster" "restored_from_backup" { data "google_project" "project" {} -data "google_compute_network" "default" { +resource "google_compute_network" "default" { name = "%{network_name}" } @@ -300,11 +300,11 @@ resource "google_compute_global_address" "private_ip_alloc" { address_type = "INTERNAL" purpose = "VPC_PEERING" prefix_length = 16 - network = data.google_compute_network.default.id + network = google_compute_network.default.id } resource "google_service_networking_connection" "vpc_connection" { - network = data.google_compute_network.default.id + network = google_compute_network.default.id service = "servicenetworking.googleapis.com" reserved_peering_ranges = [google_compute_global_address.private_ip_alloc.name] } @@ -318,7 +318,7 @@ func testAccAlloydbClusterAndInstanceAndBackup_RestoredFromBackupAndRestoredFrom resource "google_alloydb_cluster" "source" { cluster_id = "tf-test-alloydb-cluster%{random_suffix}" location = "us-central1" - network = data.google_compute_network.default.id + network = google_compute_network.default.id } resource "google_alloydb_instance" "source" { @@ -340,7 +340,7 @@ resource "google_alloydb_backup" "default" { resource "google_alloydb_cluster" "restored_from_backup" { cluster_id = "tf-test-alloydb-backup-restored-cluster-%{random_suffix}" location = "us-central1" - network = data.google_compute_network.default.id + network = google_compute_network.default.id restore_backup_source { backup_name = google_alloydb_backup.default.name } @@ -353,7 +353,7 @@ resource "google_alloydb_cluster" "restored_from_backup" { resource "google_alloydb_cluster" "restored_from_point_in_time" { cluster_id = "tf-test-alloydb-pitr-restored-cluster-%{random_suffix}" location = "us-central1" - network = data.google_compute_network.default.id + network = google_compute_network.default.id restore_continuous_backup_source { cluster = google_alloydb_cluster.source.name point_in_time = google_alloydb_backup.default.update_time @@ -366,7 +366,7 @@ resource "google_alloydb_cluster" "restored_from_point_in_time" { data "google_project" "project" {} -data "google_compute_network" "default" { +resource "google_compute_network" "default" { name = "%{network_name}" } @@ -375,11 +375,11 @@ resource "google_compute_global_address" "private_ip_alloc" { address_type = "INTERNAL" purpose = "VPC_PEERING" prefix_length = 16 - network = data.google_compute_network.default.id + network = google_compute_network.default.id } resource "google_service_networking_connection" "vpc_connection" { - network = data.google_compute_network.default.id + network = google_compute_network.default.id service = "servicenetworking.googleapis.com" reserved_peering_ranges = [google_compute_global_address.private_ip_alloc.name] } @@ -393,7 +393,7 @@ func testAccAlloydbClusterAndInstanceAndBackup_RestoredFromBackupAndRestoredFrom resource "google_alloydb_cluster" "source" { cluster_id = "tf-test-alloydb-cluster%{random_suffix}" location = "us-central1" - network = data.google_compute_network.default.id + network = google_compute_network.default.id } resource "google_alloydb_instance" "source" { @@ -415,7 +415,7 @@ resource "google_alloydb_backup" "default" { resource "google_alloydb_cluster" "restored_from_backup" { cluster_id = "tf-test-alloydb-backup-restored-cluster-%{random_suffix}" location = "us-central1" - network = data.google_compute_network.default.id + network = google_compute_network.default.id restore_backup_source { backup_name = google_alloydb_backup.default.name } @@ -433,7 +433,7 @@ resource "google_alloydb_cluster" "restored_from_backup" { resource "google_alloydb_cluster" "restored_from_point_in_time" { cluster_id = "tf-test-alloydb-pitr-restored-cluster-%{random_suffix}" location = "us-central1" - network = data.google_compute_network.default.id + network = google_compute_network.default.id restore_continuous_backup_source { cluster = google_alloydb_cluster.source.name point_in_time = google_alloydb_backup.default.update_time @@ -451,7 +451,7 @@ resource "google_alloydb_cluster" "restored_from_point_in_time" { data "google_project" "project" {} -data "google_compute_network" "default" { +resource "google_compute_network" "default" { name = "%{network_name}" } @@ -460,11 +460,11 @@ resource "google_compute_global_address" "private_ip_alloc" { address_type = "INTERNAL" purpose = "VPC_PEERING" prefix_length = 16 - network = data.google_compute_network.default.id + network = google_compute_network.default.id } resource "google_service_networking_connection" "vpc_connection" { - network = data.google_compute_network.default.id + network = google_compute_network.default.id service = "servicenetworking.googleapis.com" reserved_peering_ranges = [google_compute_global_address.private_ip_alloc.name] } @@ -478,7 +478,7 @@ func testAccAlloydbClusterAndInstanceAndBackup_RestoredFromBackupAndRestoredFrom resource "google_alloydb_cluster" "source" { cluster_id = "tf-test-alloydb-cluster%{random_suffix}" location = "us-central1" - network = data.google_compute_network.default.id + network = google_compute_network.default.id } resource "google_alloydb_instance" "source" { @@ -508,7 +508,7 @@ resource "google_alloydb_backup" "default2" { resource "google_alloydb_cluster" "restored_from_backup" { cluster_id = "tf-test-alloydb-backup-restored-cluster-%{random_suffix}" location = "us-central1" - network = data.google_compute_network.default.id + network = google_compute_network.default.id restore_backup_source { backup_name = google_alloydb_backup.default2.name } @@ -528,7 +528,7 @@ resource "google_alloydb_cluster" "restored_from_backup" { resource "google_alloydb_cluster" "restored_from_point_in_time" { cluster_id = "tf-test-alloydb-pitr-restored-cluster-%{random_suffix}" location = "us-central1" - network = data.google_compute_network.default.id + network = google_compute_network.default.id restore_continuous_backup_source { cluster = google_alloydb_cluster.restored_from_backup.name point_in_time = google_alloydb_backup.default.update_time @@ -546,7 +546,7 @@ resource "google_alloydb_cluster" "restored_from_point_in_time" { data "google_project" "project" {} -data "google_compute_network" "default" { +resource "google_compute_network" "default" { name = "%{network_name}" } @@ -555,11 +555,11 @@ resource "google_compute_global_address" "private_ip_alloc" { address_type = "INTERNAL" purpose = "VPC_PEERING" prefix_length = 16 - network = data.google_compute_network.default.id + network = google_compute_network.default.id } resource "google_service_networking_connection" "vpc_connection" { - network = data.google_compute_network.default.id + network = google_compute_network.default.id service = "servicenetworking.googleapis.com" reserved_peering_ranges = [google_compute_global_address.private_ip_alloc.name] } @@ -573,7 +573,7 @@ func testAccAlloydbClusterAndInstanceAndBackup_RestoredFromBackupAndRestoredFrom resource "google_alloydb_cluster" "source" { cluster_id = "tf-test-alloydb-cluster%{random_suffix}" location = "us-central1" - network = data.google_compute_network.default.id + network = google_compute_network.default.id } resource "google_alloydb_instance" "source" { @@ -595,7 +595,7 @@ resource "google_alloydb_backup" "default" { resource "google_alloydb_cluster" "restored_from_backup" { cluster_id = "tf-test-alloydb-backup-restored-cluster-%{random_suffix}" location = "us-central1" - network = data.google_compute_network.default.id + network = google_compute_network.default.id restore_backup_source { backup_name = google_alloydb_backup.default.name } @@ -604,7 +604,7 @@ resource "google_alloydb_cluster" "restored_from_backup" { resource "google_alloydb_cluster" "restored_from_point_in_time" { cluster_id = "tf-test-alloydb-pitr-restored-cluster-%{random_suffix}" location = "us-central1" - network = data.google_compute_network.default.id + network = google_compute_network.default.id restore_continuous_backup_source { cluster = google_alloydb_cluster.source.name point_in_time = google_alloydb_backup.default.update_time @@ -613,7 +613,7 @@ resource "google_alloydb_cluster" "restored_from_point_in_time" { data "google_project" "project" {} -data "google_compute_network" "default" { +resource "google_compute_network" "default" { name = "%{network_name}" } @@ -622,11 +622,11 @@ resource "google_compute_global_address" "private_ip_alloc" { address_type = "INTERNAL" purpose = "VPC_PEERING" prefix_length = 16 - network = data.google_compute_network.default.id + network = google_compute_network.default.id } resource "google_service_networking_connection" "vpc_connection" { - network = data.google_compute_network.default.id + network = google_compute_network.default.id service = "servicenetworking.googleapis.com" reserved_peering_ranges = [google_compute_global_address.private_ip_alloc.name] } 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 11e81c33df77..824bab8b12f0 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 @@ -10,9 +10,10 @@ import ( func TestAccAlloydbInstance_update(t *testing.T) { t.Parallel() + random_suffix := acctest.RandString(t, 10) context := map[string]interface{}{ - "random_suffix": acctest.RandString(t, 10), - "network_name": "tf-test-" + acctest.RandString(t, 10), + "random_suffix": random_suffix, + "network_name": "tf-test-alloydb-network" + random_suffix, } acctest.VcrTest(t, resource.TestCase{ @@ -63,7 +64,7 @@ resource "google_alloydb_instance" "default" { resource "google_alloydb_cluster" "default" { cluster_id = "tf-test-alloydb-cluster%{random_suffix}" location = "us-central1" - network = data.google_compute_network.default.id + network = google_compute_network.default.id initial_user { password = "tf-test-alloydb-cluster%{random_suffix}" @@ -73,7 +74,7 @@ resource "google_alloydb_cluster" "default" { data "google_project" "project" { } -data "google_compute_network" "default" { +resource "google_compute_network" "default" { name = "%{network_name}" } @@ -82,11 +83,11 @@ resource "google_compute_global_address" "private_ip_alloc" { address_type = "INTERNAL" purpose = "VPC_PEERING" prefix_length = 16 - network = data.google_compute_network.default.id + network = google_compute_network.default.id } resource "google_service_networking_connection" "vpc_connection" { - network = data.google_compute_network.default.id + network = google_compute_network.default.id service = "servicenetworking.googleapis.com" reserved_peering_ranges = [google_compute_global_address.private_ip_alloc.name] }