From bbbec3e596f5927aedcc9a906ab30f0741923b82 Mon Sep 17 00:00:00 2001 From: Modular Magician Date: Thu, 21 Sep 2023 18:13:14 +0000 Subject: [PATCH] Fix failed tests related to google_service_networking_connection (#8904) * Bootstrap service networking connection * Revert tests * Rename network names * Modify tests * Fix tests * Catch the error when deleteConnection fails * Fix test TestAccVertexAIIndexEndpoint_updated * Fix test TestAccAlloydbInstance_createInstanceWithNetworkConfigAndAllocatedIPRange * Fix test Signed-off-by: Modular Magician --- .changelog/8904.txt | 3 + google-beta/acctest/bootstrap_test_utils.go | 131 ++++++++++++ .../alloydb/resource_alloydb_backup_test.go | 108 ++++------ .../resource_alloydb_cluster_restore_test.go | 184 +++------------- .../alloydb/resource_alloydb_instance_test.go | 193 ++++++----------- ..._bitbucket_server_config_generated_test.go | 13 +- .../resource_cloudbuild_worker_pool_test.go | 21 +- .../resource_cloudids_endpoint_test.go | 36 +--- ...rvice_connection_profile_generated_test.go | 86 -------- ...gration_service_connection_profile_test.go | 67 ++++++ .../resource_memcache_instance_test.go | 42 +--- .../resource_service_networking_connection.go | 37 ++-- ...urce_service_networking_connection_test.go | 10 +- .../resource_sql_database_instance_test.go | 197 ++++++------------ .../tpu/resource_tpu_node_generated_test.go | 8 +- .../resource_vertex_ai_endpoint_test.go | 36 +--- ...vertex_ai_index_endpoint_generated_test.go | 11 +- .../resource_vertex_ai_index_endpoint_test.go | 31 +-- ...uild_bitbucket_server_config.html.markdown | 10 +- ...n_service_connection_profile.html.markdown | 5 - website/docs/r/tpu_node.html.markdown | 8 +- .../docs/r/vertex_ai_endpoint.html.markdown | 8 +- .../r/vertex_ai_index_endpoint.html.markdown | 8 +- 23 files changed, 466 insertions(+), 787 deletions(-) create mode 100644 .changelog/8904.txt diff --git a/.changelog/8904.txt b/.changelog/8904.txt new file mode 100644 index 0000000000..ea7b859c12 --- /dev/null +++ b/.changelog/8904.txt @@ -0,0 +1,3 @@ +```release-note:breaking-change +servicenetworking: used the `deleteConnection` method to delete the resource `google_service_networking_connection` +``` diff --git a/google-beta/acctest/bootstrap_test_utils.go b/google-beta/acctest/bootstrap_test_utils.go index 72a083d960..80ac34485f 100644 --- a/google-beta/acctest/bootstrap_test_utils.go +++ b/google-beta/acctest/bootstrap_test_utils.go @@ -15,6 +15,7 @@ import ( tpgcompute "github.com/hashicorp/terraform-provider-google-beta/google-beta/services/compute" "github.com/hashicorp/terraform-provider-google-beta/google-beta/services/privateca" "github.com/hashicorp/terraform-provider-google-beta/google-beta/services/resourcemanager" + tpgservicenetworking "github.com/hashicorp/terraform-provider-google-beta/google-beta/services/servicenetworking" "github.com/hashicorp/terraform-provider-google-beta/google-beta/services/sql" "github.com/hashicorp/terraform-provider-google-beta/google-beta/tpgiamresource" "github.com/hashicorp/terraform-provider-google-beta/google-beta/tpgresource" @@ -25,6 +26,7 @@ import ( cloudresourcemanager "google.golang.org/api/cloudresourcemanager/v1" iam "google.golang.org/api/iam/v1" "google.golang.org/api/iamcredentials/v1" + "google.golang.org/api/servicenetworking/v1" "google.golang.org/api/serviceusage/v1" sqladmin "google.golang.org/api/sqladmin/v1beta4" ) @@ -356,6 +358,135 @@ func BootstrapSharedTestNetwork(t *testing.T, testId string) string { return network.Name } +const SharedTestGlobalAddressPrefix = "tf-bootstrap-addr-" + +func BootstrapSharedTestGlobalAddress(t *testing.T, testId, networkId string) string { + project := envvar.GetTestProjectFromEnv() + addressName := SharedTestGlobalAddressPrefix + testId + + config := BootstrapConfig(t) + if config == nil { + return "" + } + + log.Printf("[DEBUG] Getting shared test global address %q", addressName) + _, err := config.NewComputeClient(config.UserAgent).GlobalAddresses.Get(project, addressName).Do() + if err != nil && transport_tpg.IsGoogleApiErrorWithCode(err, 404) { + log.Printf("[DEBUG] Global address %q not found, bootstrapping", addressName) + url := fmt.Sprintf("%sprojects/%s/global/addresses", config.ComputeBasePath, project) + netObj := map[string]interface{}{ + "name": addressName, + "address_type": "INTERNAL", + "purpose": "VPC_PEERING", + "prefix_length": 16, + "network": networkId, + } + + res, err := transport_tpg.SendRequest(transport_tpg.SendRequestOptions{ + Config: config, + Method: "POST", + Project: project, + RawURL: url, + UserAgent: config.UserAgent, + Body: netObj, + Timeout: 4 * time.Minute, + }) + if err != nil { + t.Fatalf("Error bootstrapping shared test global address %q: %s", addressName, err) + } + + log.Printf("[DEBUG] Waiting for global address creation to finish") + err = tpgcompute.ComputeOperationWaitTime(config, res, project, "Error bootstrapping shared test global address", config.UserAgent, 4*time.Minute) + if err != nil { + t.Fatalf("Error bootstrapping shared test global address %q: %s", addressName, err) + } + } + + address, err := config.NewComputeClient(config.UserAgent).GlobalAddresses.Get(project, addressName).Do() + if err != nil { + t.Errorf("Error getting shared test global address %q: %s", addressName, err) + } + if address == nil { + t.Fatalf("Error getting shared test global address %q: is nil", addressName) + } + 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 { + return "" + } + + networkName := BootstrapSharedTestNetwork(t, testId) + 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) + if config.UserProjectOverride { + readCall.Header().Add("X-Goog-User-Project", project) + } + response, err := readCall.Do() + if err != nil { + t.Errorf("Error getting shared test service networking connection: %s", err) + } + + var connection *servicenetworking.Connection + for _, c := range response.Connections { + if c.Network == networkId { + connection = c + break + } + } + + if connection == nil { + log.Printf("[DEBUG] Service networking connection not found, bootstrapping") + + connection := &servicenetworking.Connection{ + Network: networkId, + ReservedPeeringRanges: []string{globalAddressName}, + } + + createCall := config.NewServiceNetworkingClient(config.UserAgent).Services.Connections.Create(parentService, connection) + if config.UserProjectOverride { + createCall.Header().Add("X-Goog-User-Project", project) + } + op, err := createCall.Do() + if err != nil { + t.Fatalf("Error bootstrapping shared test service networking connection: %s", err) + } + + log.Printf("[DEBUG] Waiting for service networking connection creation to finish") + if err := tpgservicenetworking.ServiceNetworkingOperationWaitTime(config, op, "Create Service Networking Connection", config.UserAgent, project, 4*time.Minute); err != nil { + t.Fatalf("Error bootstrapping shared test service networking connection: %s", err) + } + } + + log.Printf("[DEBUG] Getting shared test service networking connection") + + return networkName +} + var SharedServicePerimeterProjectPrefix = "tf-bootstrap-sp-" func BootstrapServicePerimeterProjects(t *testing.T, desiredProjects int) []*cloudresourcemanager.Project { diff --git a/google-beta/services/alloydb/resource_alloydb_backup_test.go b/google-beta/services/alloydb/resource_alloydb_backup_test.go index cbd2e3b1cb..923ff3dcc7 100644 --- a/google-beta/services/alloydb/resource_alloydb_backup_test.go +++ b/google-beta/services/alloydb/resource_alloydb_backup_test.go @@ -14,7 +14,7 @@ func TestAccAlloydbBackup_update(t *testing.T) { random_suffix := acctest.RandString(t, 10) context := map[string]interface{}{ - "network_name": "tf-test-alloydb-network" + random_suffix, + "network_name": acctest.BootstrapSharedServiceNetworkingConnection(t, "alloydb-backup-update-1"), "random_suffix": random_suffix, } @@ -24,7 +24,7 @@ func TestAccAlloydbBackup_update(t *testing.T) { CheckDestroy: testAccCheckAlloydbBackupDestroyProducer(t), Steps: []resource.TestStep{ { - Config: testAccAlloydbBackup_alloydbBackupFullExample(context), + Config: testAccAlloydbBackup_alloydbBackupBasic(context), }, { ResourceName: "google_alloydb_backup.default", @@ -45,8 +45,7 @@ func TestAccAlloydbBackup_update(t *testing.T) { }) } -// Updates "label" field from testAccAlloydbBackup_alloydbBackupFullExample -func testAccAlloydbBackup_update(context map[string]interface{}) string { +func testAccAlloydbBackup_alloydbBackupBasic(context map[string]interface{}) string { return acctest.Nprintf(` resource "google_alloydb_backup" "default" { location = "us-central1" @@ -55,8 +54,7 @@ resource "google_alloydb_backup" "default" { description = "example description" labels = { - "label" = "updated_key" - "label2" = "updated_key2" + "label" = "key" } depends_on = [google_alloydb_instance.default] } @@ -64,32 +62,50 @@ resource "google_alloydb_backup" "default" { resource "google_alloydb_cluster" "default" { cluster_id = "tf-test-alloydb-cluster%{random_suffix}" location = "us-central1" - network = google_compute_network.default.id + network = data.google_compute_network.default.id } resource "google_alloydb_instance" "default" { cluster = google_alloydb_cluster.default.name instance_id = "tf-test-alloydb-instance%{random_suffix}" instance_type = "PRIMARY" +} + +data "google_compute_network" "default" { + name = "%{network_name}" +} +`, context) +} + +// Updates "label" field +func testAccAlloydbBackup_update(context map[string]interface{}) string { + return acctest.Nprintf(` +resource "google_alloydb_backup" "default" { + location = "us-central1" + backup_id = "tf-test-alloydb-backup%{random_suffix}" + cluster_name = google_alloydb_cluster.default.name - depends_on = [google_service_networking_connection.vpc_connection] + description = "example description" + labels = { + "label" = "updated_key" + "label2" = "updated_key2" + } + depends_on = [google_alloydb_instance.default] } -resource "google_compute_global_address" "private_ip_alloc" { - name = "tf-test-alloydb-cluster%{random_suffix}" - address_type = "INTERNAL" - purpose = "VPC_PEERING" - prefix_length = 16 - network = google_compute_network.default.id +resource "google_alloydb_cluster" "default" { + cluster_id = "tf-test-alloydb-cluster%{random_suffix}" + location = "us-central1" + network = data.google_compute_network.default.id } -resource "google_service_networking_connection" "vpc_connection" { - network = google_compute_network.default.id - service = "servicenetworking.googleapis.com" - reserved_peering_ranges = [google_compute_global_address.private_ip_alloc.name] +resource "google_alloydb_instance" "default" { + cluster = google_alloydb_cluster.default.name + instance_id = "tf-test-alloydb-instance%{random_suffix}" + instance_type = "PRIMARY" } -resource "google_compute_network" "default" { +data "google_compute_network" "default" { name = "%{network_name}" } `, context) @@ -101,7 +117,7 @@ func TestAccAlloydbBackup_createBackupWithMandatoryFields(t *testing.T) { context := map[string]interface{}{ "random_suffix": acctest.RandString(t, 10), - "network_name": "tf-test-" + acctest.RandString(t, 10), + "network_name": acctest.BootstrapSharedServiceNetworkingConnection(t, "alloydb-backup-mandatory-1"), } acctest.VcrTest(t, resource.TestCase{ @@ -128,12 +144,12 @@ resource "google_alloydb_backup" "default" { resource "google_alloydb_cluster" "default" { location = "us-central1" cluster_id = "tf-test-alloydb-cluster%{random_suffix}" - network = google_compute_network.default.id + network = data.google_compute_network.default.id } data "google_project" "project" { } -resource "google_compute_network" "default" { +data "google_compute_network" "default" { name = "%{network_name}" } @@ -141,32 +157,6 @@ resource "google_alloydb_instance" "default" { cluster = google_alloydb_cluster.default.name instance_id = "tf-test-alloydb-instance%{random_suffix}" instance_type = "PRIMARY" - - depends_on = [google_service_networking_connection.vpc_connection] -} - -resource "google_compute_global_address" "private_ip_alloc" { - name = "tf-test-alloydb-cluster%{random_suffix}" - address_type = "INTERNAL" - purpose = "VPC_PEERING" - prefix_length = 16 - network = google_compute_network.default.id - lifecycle { - ignore_changes = [ - address, - creation_timestamp, - id, - network, - project, - self_link - ] - } -} - -resource "google_service_networking_connection" "vpc_connection" { - network = google_compute_network.default.id - service = "servicenetworking.googleapis.com" - reserved_peering_ranges = [google_compute_global_address.private_ip_alloc.name] } `, context) } @@ -175,7 +165,7 @@ func TestAccAlloydbBackup_usingCMEK(t *testing.T) { t.Parallel() context := map[string]interface{}{ - "network_name": "tf-test-" + acctest.RandString(t, 10), + "network_name": acctest.BootstrapSharedServiceNetworkingConnection(t, "alloydb-backup-cmek-1"), "random_suffix": acctest.RandString(t, 10), "key_name": "tf-test-key-" + acctest.RandString(t, 10), } @@ -218,32 +208,16 @@ resource "google_alloydb_backup" "default" { resource "google_alloydb_cluster" "default" { cluster_id = "tf-test-alloydb-cluster%{random_suffix}" location = "us-central1" - network = google_compute_network.default.id + network = data.google_compute_network.default.id } resource "google_alloydb_instance" "default" { cluster = google_alloydb_cluster.default.name instance_id = "tf-test-alloydb-instance%{random_suffix}" instance_type = "PRIMARY" - - depends_on = [google_service_networking_connection.vpc_connection] -} - -resource "google_compute_global_address" "private_ip_alloc" { - name = "tf-test-alloydb-cluster%{random_suffix}" - address_type = "INTERNAL" - purpose = "VPC_PEERING" - prefix_length = 16 - network = google_compute_network.default.id -} - -resource "google_service_networking_connection" "vpc_connection" { - network = google_compute_network.default.id - service = "servicenetworking.googleapis.com" - reserved_peering_ranges = [google_compute_global_address.private_ip_alloc.name] } -resource "google_compute_network" "default" { +data "google_compute_network" "default" { name = "%{network_name}" } data "google_project" "project" {} diff --git a/google-beta/services/alloydb/resource_alloydb_cluster_restore_test.go b/google-beta/services/alloydb/resource_alloydb_cluster_restore_test.go index b5249746d1..3fa25fc32f 100644 --- a/google-beta/services/alloydb/resource_alloydb_cluster_restore_test.go +++ b/google-beta/services/alloydb/resource_alloydb_cluster_restore_test.go @@ -21,7 +21,7 @@ func TestAccAlloydbCluster_restore(t *testing.T) { context := map[string]interface{}{ "random_suffix": acctest.RandString(t, 10), - "network_name": "tf-test-" + acctest.RandString(t, 10), + "network_name": acctest.BootstrapSharedServiceNetworkingConnection(t, "alloydb-instance-restore-1"), } acctest.VcrTest(t, resource.TestCase{ @@ -88,15 +88,13 @@ func testAccAlloydbClusterAndInstanceAndBackup(context map[string]interface{}) s resource "google_alloydb_cluster" "source" { cluster_id = "tf-test-alloydb-cluster%{random_suffix}" location = "us-central1" - network = google_compute_network.default.id + network = data.google_compute_network.default.id } resource "google_alloydb_instance" "source" { cluster = google_alloydb_cluster.source.name instance_id = "tf-test-alloydb-instance%{random_suffix}" instance_type = "PRIMARY" - - depends_on = [google_service_networking_connection.vpc_connection] } resource "google_alloydb_backup" "default" { @@ -109,23 +107,9 @@ resource "google_alloydb_backup" "default" { data "google_project" "project" {} -resource "google_compute_network" "default" { +data "google_compute_network" "default" { name = "%{network_name}" } - -resource "google_compute_global_address" "private_ip_alloc" { - name = "tf-test-alloydb-cluster%{random_suffix}" - address_type = "INTERNAL" - purpose = "VPC_PEERING" - prefix_length = 16 - network = google_compute_network.default.id -} - -resource "google_service_networking_connection" "vpc_connection" { - network = google_compute_network.default.id - service = "servicenetworking.googleapis.com" - reserved_peering_ranges = [google_compute_global_address.private_ip_alloc.name] -} `, context) } @@ -135,15 +119,13 @@ func testAccAlloydbClusterAndInstanceAndBackup_OnlyOneSourceAllowed(context map[ resource "google_alloydb_cluster" "source" { cluster_id = "tf-test-alloydb-cluster%{random_suffix}" location = "us-central1" - network = google_compute_network.default.id + network = data.google_compute_network.default.id } resource "google_alloydb_instance" "source" { cluster = google_alloydb_cluster.source.name instance_id = "tf-test-alloydb-instance%{random_suffix}" instance_type = "PRIMARY" - - depends_on = [google_service_networking_connection.vpc_connection] } resource "google_alloydb_backup" "default" { @@ -157,7 +139,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 = google_compute_network.default.id + network = data.google_compute_network.default.id restore_backup_source { backup_name = google_alloydb_backup.default.name } @@ -173,23 +155,9 @@ resource "google_alloydb_cluster" "restored" { data "google_project" "project" {} -resource "google_compute_network" "default" { +data "google_compute_network" "default" { name = "%{network_name}" } - -resource "google_compute_global_address" "private_ip_alloc" { - name = "tf-test-alloydb-cluster%{random_suffix}" - address_type = "INTERNAL" - purpose = "VPC_PEERING" - prefix_length = 16 - network = google_compute_network.default.id -} - -resource "google_service_networking_connection" "vpc_connection" { - network = google_compute_network.default.id - service = "servicenetworking.googleapis.com" - reserved_peering_ranges = [google_compute_global_address.private_ip_alloc.name] -} `, context) } @@ -199,15 +167,13 @@ func testAccAlloydbClusterAndInstanceAndBackup_SourceClusterAndPointInTimeRequir resource "google_alloydb_cluster" "source" { cluster_id = "tf-test-alloydb-cluster%{random_suffix}" location = "us-central1" - network = google_compute_network.default.id + network = data.google_compute_network.default.id } resource "google_alloydb_instance" "source" { cluster = google_alloydb_cluster.source.name instance_id = "tf-test-alloydb-instance%{random_suffix}" instance_type = "PRIMARY" - - depends_on = [google_service_networking_connection.vpc_connection] } resource "google_alloydb_backup" "default" { @@ -221,7 +187,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 = google_compute_network.default.id + network = data.google_compute_network.default.id restore_continuous_backup_source { cluster = google_alloydb_cluster.source.name @@ -234,23 +200,9 @@ resource "google_alloydb_cluster" "restored" { data "google_project" "project" {} -resource "google_compute_network" "default" { +data "google_compute_network" "default" { name = "%{network_name}" } - -resource "google_compute_global_address" "private_ip_alloc" { - name = "tf-test-alloydb-cluster%{random_suffix}" - address_type = "INTERNAL" - purpose = "VPC_PEERING" - prefix_length = 16 - network = google_compute_network.default.id -} - -resource "google_service_networking_connection" "vpc_connection" { - network = google_compute_network.default.id - service = "servicenetworking.googleapis.com" - reserved_peering_ranges = [google_compute_global_address.private_ip_alloc.name] -} `, context) } @@ -259,15 +211,13 @@ func testAccAlloydbClusterAndInstanceAndBackup_RestoredFromBackup(context map[st resource "google_alloydb_cluster" "source" { cluster_id = "tf-test-alloydb-cluster%{random_suffix}" location = "us-central1" - network = google_compute_network.default.id + network = data.google_compute_network.default.id } resource "google_alloydb_instance" "source" { cluster = google_alloydb_cluster.source.name instance_id = "tf-test-alloydb-instance%{random_suffix}" instance_type = "PRIMARY" - - depends_on = [google_service_networking_connection.vpc_connection] } resource "google_alloydb_backup" "default" { @@ -281,7 +231,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 = google_compute_network.default.id + network = data.google_compute_network.default.id restore_backup_source { backup_name = google_alloydb_backup.default.name } @@ -293,23 +243,9 @@ resource "google_alloydb_cluster" "restored_from_backup" { data "google_project" "project" {} -resource "google_compute_network" "default" { +data "google_compute_network" "default" { name = "%{network_name}" } - -resource "google_compute_global_address" "private_ip_alloc" { - name = "tf-test-alloydb-cluster%{random_suffix}" - address_type = "INTERNAL" - purpose = "VPC_PEERING" - prefix_length = 16 - network = google_compute_network.default.id -} - -resource "google_service_networking_connection" "vpc_connection" { - network = google_compute_network.default.id - service = "servicenetworking.googleapis.com" - reserved_peering_ranges = [google_compute_global_address.private_ip_alloc.name] -} `, context) } @@ -320,15 +256,13 @@ func testAccAlloydbClusterAndInstanceAndBackup_RestoredFromBackupAndRestoredFrom resource "google_alloydb_cluster" "source" { cluster_id = "tf-test-alloydb-cluster%{random_suffix}" location = "us-central1" - network = google_compute_network.default.id + network = data.google_compute_network.default.id } resource "google_alloydb_instance" "source" { cluster = google_alloydb_cluster.source.name instance_id = "tf-test-alloydb-instance%{random_suffix}" instance_type = "PRIMARY" - - depends_on = [google_service_networking_connection.vpc_connection] } resource "google_alloydb_backup" "default" { @@ -342,7 +276,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 = google_compute_network.default.id + network = data.google_compute_network.default.id restore_backup_source { backup_name = google_alloydb_backup.default.name } @@ -355,7 +289,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 = google_compute_network.default.id + network = data.google_compute_network.default.id restore_continuous_backup_source { cluster = google_alloydb_cluster.source.name point_in_time = google_alloydb_backup.default.update_time @@ -368,23 +302,9 @@ resource "google_alloydb_cluster" "restored_from_point_in_time" { data "google_project" "project" {} -resource "google_compute_network" "default" { +data "google_compute_network" "default" { name = "%{network_name}" } - -resource "google_compute_global_address" "private_ip_alloc" { - name = "tf-test-alloydb-cluster%{random_suffix}" - address_type = "INTERNAL" - purpose = "VPC_PEERING" - prefix_length = 16 - network = google_compute_network.default.id -} - -resource "google_service_networking_connection" "vpc_connection" { - network = google_compute_network.default.id - service = "servicenetworking.googleapis.com" - reserved_peering_ranges = [google_compute_global_address.private_ip_alloc.name] -} `, context) } @@ -395,15 +315,13 @@ func testAccAlloydbClusterAndInstanceAndBackup_RestoredFromBackupAndRestoredFrom resource "google_alloydb_cluster" "source" { cluster_id = "tf-test-alloydb-cluster%{random_suffix}" location = "us-central1" - network = google_compute_network.default.id + network = data.google_compute_network.default.id } resource "google_alloydb_instance" "source" { cluster = google_alloydb_cluster.source.name instance_id = "tf-test-alloydb-instance%{random_suffix}" instance_type = "PRIMARY" - - depends_on = [google_service_networking_connection.vpc_connection] } resource "google_alloydb_backup" "default" { @@ -417,7 +335,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 = google_compute_network.default.id + network = data.google_compute_network.default.id restore_backup_source { backup_name = google_alloydb_backup.default.name } @@ -435,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 = google_compute_network.default.id + network = data.google_compute_network.default.id restore_continuous_backup_source { cluster = google_alloydb_cluster.source.name point_in_time = google_alloydb_backup.default.update_time @@ -453,23 +371,9 @@ resource "google_alloydb_cluster" "restored_from_point_in_time" { data "google_project" "project" {} -resource "google_compute_network" "default" { +data "google_compute_network" "default" { name = "%{network_name}" } - -resource "google_compute_global_address" "private_ip_alloc" { - name = "tf-test-alloydb-cluster%{random_suffix}" - address_type = "INTERNAL" - purpose = "VPC_PEERING" - prefix_length = 16 - network = google_compute_network.default.id -} - -resource "google_service_networking_connection" "vpc_connection" { - network = google_compute_network.default.id - service = "servicenetworking.googleapis.com" - reserved_peering_ranges = [google_compute_global_address.private_ip_alloc.name] -} `, context) } @@ -480,15 +384,13 @@ func testAccAlloydbClusterAndInstanceAndBackup_RestoredFromBackupAndRestoredFrom resource "google_alloydb_cluster" "source" { cluster_id = "tf-test-alloydb-cluster%{random_suffix}" location = "us-central1" - network = google_compute_network.default.id + network = data.google_compute_network.default.id } resource "google_alloydb_instance" "source" { cluster = google_alloydb_cluster.source.name instance_id = "tf-test-alloydb-instance%{random_suffix}" instance_type = "PRIMARY" - - depends_on = [google_service_networking_connection.vpc_connection] } resource "google_alloydb_backup" "default" { @@ -510,7 +412,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 = google_compute_network.default.id + network = data.google_compute_network.default.id restore_backup_source { backup_name = google_alloydb_backup.default2.name } @@ -530,7 +432,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 = google_compute_network.default.id + network = data.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 @@ -548,23 +450,9 @@ resource "google_alloydb_cluster" "restored_from_point_in_time" { data "google_project" "project" {} -resource "google_compute_network" "default" { +data "google_compute_network" "default" { name = "%{network_name}" } - -resource "google_compute_global_address" "private_ip_alloc" { - name = "tf-test-alloydb-cluster%{random_suffix}" - address_type = "INTERNAL" - purpose = "VPC_PEERING" - prefix_length = 16 - network = google_compute_network.default.id -} - -resource "google_service_networking_connection" "vpc_connection" { - network = google_compute_network.default.id - service = "servicenetworking.googleapis.com" - reserved_peering_ranges = [google_compute_global_address.private_ip_alloc.name] -} `, context) } @@ -575,15 +463,13 @@ func testAccAlloydbClusterAndInstanceAndBackup_RestoredFromBackupAndRestoredFrom resource "google_alloydb_cluster" "source" { cluster_id = "tf-test-alloydb-cluster%{random_suffix}" location = "us-central1" - network = google_compute_network.default.id + network = data.google_compute_network.default.id } resource "google_alloydb_instance" "source" { cluster = google_alloydb_cluster.source.name instance_id = "tf-test-alloydb-instance%{random_suffix}" instance_type = "PRIMARY" - - depends_on = [google_service_networking_connection.vpc_connection] } resource "google_alloydb_backup" "default" { @@ -597,7 +483,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 = google_compute_network.default.id + network = data.google_compute_network.default.id restore_backup_source { backup_name = google_alloydb_backup.default.name } @@ -606,7 +492,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 = google_compute_network.default.id + network = data.google_compute_network.default.id restore_continuous_backup_source { cluster = google_alloydb_cluster.source.name point_in_time = google_alloydb_backup.default.update_time @@ -615,22 +501,8 @@ resource "google_alloydb_cluster" "restored_from_point_in_time" { data "google_project" "project" {} -resource "google_compute_network" "default" { +data "google_compute_network" "default" { name = "%{network_name}" } - -resource "google_compute_global_address" "private_ip_alloc" { - name = "tf-test-alloydb-cluster%{random_suffix}" - address_type = "INTERNAL" - purpose = "VPC_PEERING" - prefix_length = 16 - network = google_compute_network.default.id -} - -resource "google_service_networking_connection" "vpc_connection" { - network = google_compute_network.default.id - service = "servicenetworking.googleapis.com" - reserved_peering_ranges = [google_compute_global_address.private_ip_alloc.name] -} `, context) } diff --git a/google-beta/services/alloydb/resource_alloydb_instance_test.go b/google-beta/services/alloydb/resource_alloydb_instance_test.go index 7818e5dfb7..07ba4bd67a 100644 --- a/google-beta/services/alloydb/resource_alloydb_instance_test.go +++ b/google-beta/services/alloydb/resource_alloydb_instance_test.go @@ -3,10 +3,12 @@ package alloydb_test import ( + "fmt" "testing" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" "github.com/hashicorp/terraform-provider-google-beta/google-beta/acctest" + "github.com/hashicorp/terraform-provider-google-beta/google-beta/envvar" ) func TestAccAlloydbInstance_update(t *testing.T) { @@ -14,8 +16,8 @@ func TestAccAlloydbInstance_update(t *testing.T) { random_suffix := acctest.RandString(t, 10) context := map[string]interface{}{ + "network_name": acctest.BootstrapSharedServiceNetworkingConnection(t, "alloydb-instance-update-1"), "random_suffix": random_suffix, - "network_name": "tf-test-alloydb-network" + random_suffix, } acctest.VcrTest(t, resource.TestCase{ @@ -24,7 +26,7 @@ func TestAccAlloydbInstance_update(t *testing.T) { CheckDestroy: testAccCheckAlloydbInstanceDestroyProducer(t), Steps: []resource.TestStep{ { - Config: testAccAlloydbInstance_alloydbInstanceBasicExample(context), + Config: testAccAlloydbInstance_alloydbInstanceBasic(context), }, { ResourceName: "google_alloydb_instance.default", @@ -45,6 +47,34 @@ func TestAccAlloydbInstance_update(t *testing.T) { }) } +func testAccAlloydbInstance_alloydbInstanceBasic(context map[string]interface{}) string { + return acctest.Nprintf(` +resource "google_alloydb_instance" "default" { + cluster = google_alloydb_cluster.default.name + instance_id = "tf-test-alloydb-instance%{random_suffix}" + instance_type = "PRIMARY" + + machine_config { + cpu_count = 2 + } +} + +resource "google_alloydb_cluster" "default" { + cluster_id = "tf-test-alloydb-cluster%{random_suffix}" + location = "us-central1" + network = data.google_compute_network.default.id + + initial_user { + password = "tf-test-alloydb-cluster%{random_suffix}" + } +} + +data "google_compute_network" "default" { + name = "%{network_name}" +} +`, context) +} + func testAccAlloydbInstance_update(context map[string]interface{}) string { return acctest.Nprintf(` resource "google_alloydb_instance" "default" { @@ -59,40 +89,21 @@ resource "google_alloydb_instance" "default" { labels = { test = "tf-test-alloydb-instance%{random_suffix}" } - - depends_on = [google_service_networking_connection.vpc_connection] } resource "google_alloydb_cluster" "default" { cluster_id = "tf-test-alloydb-cluster%{random_suffix}" location = "us-central1" - network = google_compute_network.default.id + network = data.google_compute_network.default.id initial_user { password = "tf-test-alloydb-cluster%{random_suffix}" } } -data "google_project" "project" { -} - -resource "google_compute_network" "default" { +data "google_compute_network" "default" { name = "%{network_name}" } - -resource "google_compute_global_address" "private_ip_alloc" { - name = "tf-test-alloydb-cluster%{random_suffix}" - address_type = "INTERNAL" - purpose = "VPC_PEERING" - prefix_length = 16 - network = google_compute_network.default.id -} - -resource "google_service_networking_connection" "vpc_connection" { - network = google_compute_network.default.id - service = "servicenetworking.googleapis.com" - reserved_peering_ranges = [google_compute_global_address.private_ip_alloc.name] -} `, context) } @@ -102,7 +113,7 @@ func TestAccAlloydbInstance_createInstanceWithMandatoryFields(t *testing.T) { context := map[string]interface{}{ "random_suffix": acctest.RandString(t, 10), - "network_name": "tf-test-" + acctest.RandString(t, 10), + "network_name": acctest.BootstrapSharedServiceNetworkingConnection(t, "alloydb-instance-mandatory-1"), } acctest.VcrTest(t, resource.TestCase{ @@ -123,35 +134,19 @@ resource "google_alloydb_instance" "default" { cluster = google_alloydb_cluster.default.name instance_id = "tf-test-alloydb-instance%{random_suffix}" instance_type = "PRIMARY" - - depends_on = [google_service_networking_connection.vpc_connection] } resource "google_alloydb_cluster" "default" { cluster_id = "tf-test-alloydb-cluster%{random_suffix}" location = "us-central1" - network = google_compute_network.default.id + network = data.google_compute_network.default.id } data "google_project" "project" {} -resource "google_compute_network" "default" { +data "google_compute_network" "default" { name = "%{network_name}" } - -resource "google_compute_global_address" "private_ip_alloc" { - name = "tf-test-alloydb-cluster%{random_suffix}" - address_type = "INTERNAL" - purpose = "VPC_PEERING" - prefix_length = 16 - network = google_compute_network.default.id -} - -resource "google_service_networking_connection" "vpc_connection" { - network = google_compute_network.default.id - service = "servicenetworking.googleapis.com" - reserved_peering_ranges = [google_compute_global_address.private_ip_alloc.name] -} `, context) } @@ -161,7 +156,7 @@ func TestAccAlloydbInstance_createInstanceWithMaximumFields(t *testing.T) { context := map[string]interface{}{ "random_suffix": acctest.RandString(t, 10), - "network_name": "tf-test-" + acctest.RandString(t, 10), + "network_name": acctest.BootstrapSharedServiceNetworkingConnection(t, "alloydb-instance-maximum-1"), } acctest.VcrTest(t, resource.TestCase{ @@ -196,7 +191,6 @@ resource "google_alloydb_instance" "default" { machine_config { cpu_count = 4 } - depends_on = [google_service_networking_connection.vpc_connection] lifecycle { ignore_changes = [ gce_zone, @@ -208,28 +202,14 @@ resource "google_alloydb_instance" "default" { resource "google_alloydb_cluster" "default" { cluster_id = "tf-test-alloydb-cluster%{random_suffix}" location = "us-central1" - network = google_compute_network.default.id + network = data.google_compute_network.default.id } data "google_project" "project" {} -resource "google_compute_network" "default" { +data "google_compute_network" "default" { name = "%{network_name}" } - -resource "google_compute_global_address" "private_ip_alloc" { - name = "tf-test-alloydb-cluster%{random_suffix}" - address_type = "INTERNAL" - purpose = "VPC_PEERING" - prefix_length = 16 - network = google_compute_network.default.id -} - -resource "google_service_networking_connection" "vpc_connection" { - network = google_compute_network.default.id - service = "servicenetworking.googleapis.com" - reserved_peering_ranges = [google_compute_global_address.private_ip_alloc.name] -} `, context) } @@ -239,7 +219,7 @@ func TestAccAlloydbInstance_createPrimaryAndReadPoolInstance(t *testing.T) { context := map[string]interface{}{ "random_suffix": acctest.RandString(t, 10), - "network_name": "tf-test-" + acctest.RandString(t, 10), + "network_name": acctest.BootstrapSharedServiceNetworkingConnection(t, "alloydb-instance-readpool-1"), } acctest.VcrTest(t, resource.TestCase{ @@ -260,7 +240,6 @@ resource "google_alloydb_instance" "primary" { cluster = google_alloydb_cluster.default.name instance_id = "tf-test-alloydb-instance%{random_suffix}" instance_type = "PRIMARY" - depends_on = [google_service_networking_connection.vpc_connection] } resource "google_alloydb_instance" "read_pool" { @@ -270,34 +249,20 @@ resource "google_alloydb_instance" "read_pool" { read_pool_config { node_count = 4 } - depends_on = [google_service_networking_connection.vpc_connection, google_alloydb_instance.primary] + depends_on = [google_alloydb_instance.primary] } resource "google_alloydb_cluster" "default" { cluster_id = "tf-test-alloydb-cluster%{random_suffix}" location = "us-central1" - network = google_compute_network.default.id + network = data.google_compute_network.default.id } data "google_project" "project" {} -resource "google_compute_network" "default" { +data "google_compute_network" "default" { name = "%{network_name}" } - -resource "google_compute_global_address" "private_ip_alloc" { - name = "tf-test-alloydb-cluster%{random_suffix}" - address_type = "INTERNAL" - purpose = "VPC_PEERING" - prefix_length = 16 - network = google_compute_network.default.id -} - -resource "google_service_networking_connection" "vpc_connection" { - network = google_compute_network.default.id - service = "servicenetworking.googleapis.com" - reserved_peering_ranges = [google_compute_global_address.private_ip_alloc.name] -} `, context) } @@ -307,7 +272,7 @@ func TestAccAlloydbInstance_updateDatabaseFlagInPrimaryInstance(t *testing.T) { context := map[string]interface{}{ "random_suffix": acctest.RandString(t, 10), - "network_name": "tf-test-" + acctest.RandString(t, 10), + "network_name": acctest.BootstrapSharedServiceNetworkingConnection(t, "alloydb-instance-updatedb-1"), } acctest.VcrTest(t, resource.TestCase{ @@ -339,34 +304,19 @@ resource "google_alloydb_instance" "primary" { database_flags = { "alloydb.enable_auto_explain" = "true" } - depends_on = [google_service_networking_connection.vpc_connection] } resource "google_alloydb_cluster" "default" { cluster_id = "tf-test-alloydb-cluster%{random_suffix}" location = "us-central1" - network = google_compute_network.default.id + network = data.google_compute_network.default.id } data "google_project" "project" {} -resource "google_compute_network" "default" { +data "google_compute_network" "default" { name = "%{network_name}" } - -resource "google_compute_global_address" "private_ip_alloc" { - name = "tf-test-alloydb-cluster%{random_suffix}" - address_type = "INTERNAL" - purpose = "VPC_PEERING" - prefix_length = 16 - network = google_compute_network.default.id -} - -resource "google_service_networking_connection" "vpc_connection" { - network = google_compute_network.default.id - service = "servicenetworking.googleapis.com" - reserved_peering_ranges = [google_compute_global_address.private_ip_alloc.name] -} `, context) } @@ -379,34 +329,19 @@ resource "google_alloydb_instance" "primary" { database_flags = { "alloydb.enable_auto_explain" = "false" } - depends_on = [google_service_networking_connection.vpc_connection] } resource "google_alloydb_cluster" "default" { cluster_id = "tf-test-alloydb-cluster%{random_suffix}" location = "us-central1" - network = google_compute_network.default.id + network = data.google_compute_network.default.id } data "google_project" "project" {} -resource "google_compute_network" "default" { +data "google_compute_network" "default" { name = "%{network_name}" } - -resource "google_compute_global_address" "private_ip_alloc" { - name = "tf-test-alloydb-cluster%{random_suffix}" - address_type = "INTERNAL" - purpose = "VPC_PEERING" - prefix_length = 16 - network = google_compute_network.default.id -} - -resource "google_service_networking_connection" "vpc_connection" { - network = google_compute_network.default.id - service = "servicenetworking.googleapis.com" - reserved_peering_ranges = [google_compute_global_address.private_ip_alloc.name] -} `, context) } @@ -414,9 +349,17 @@ resource "google_service_networking_connection" "vpc_connection" { func TestAccAlloydbInstance_createInstanceWithNetworkConfigAndAllocatedIPRange(t *testing.T) { t.Parallel() + projectNumber := envvar.GetTestProjectNumberFromEnv() + testId := "alloydbinstance-network-config-1" + networkName := acctest.BootstrapSharedTestNetwork(t, testId) + networkId := fmt.Sprintf("projects/%v/global/networks/%v", projectNumber, networkName) + addressName := acctest.BootstrapSharedTestGlobalAddress(t, testId, networkId) + acctest.BootstrapSharedServiceNetworkingConnection(t, testId) + context := map[string]interface{}{ "random_suffix": acctest.RandString(t, 10), - "network_name": acctest.BootstrapSharedTestNetwork(t, "alloydbinstance-network-config"), + "network_name": networkName, + "address_name": addressName, } acctest.VcrTest(t, resource.TestCase{ @@ -437,7 +380,6 @@ resource "google_alloydb_instance" "default" { cluster = google_alloydb_cluster.default.name instance_id = "tf-test-alloydb-instance%{random_suffix}" instance_type = "PRIMARY" - depends_on = [google_service_networking_connection.vpc_connection] } resource "google_alloydb_cluster" "default" { @@ -445,29 +387,16 @@ resource "google_alloydb_cluster" "default" { location = "us-central1" network_config { network = data.google_compute_network.default.id - allocated_ip_range = google_compute_global_address.private_ip_alloc.name + allocated_ip_range = data.google_compute_global_address.private_ip_alloc.name } - } -data "google_project" "project" {} - data "google_compute_network" "default" { name = "%{network_name}" } -resource "google_compute_global_address" "private_ip_alloc" { - name = "tf-test-alloydb-cluster%{random_suffix}" - address_type = "INTERNAL" - purpose = "VPC_PEERING" - prefix_length = 16 - network = data.google_compute_network.default.id -} - -resource "google_service_networking_connection" "vpc_connection" { - network = data.google_compute_network.default.id - service = "servicenetworking.googleapis.com" - reserved_peering_ranges = [google_compute_global_address.private_ip_alloc.name] +data "google_compute_global_address" "private_ip_alloc" { + name = "%{address_name}" } `, context) } diff --git a/google-beta/services/cloudbuild/resource_cloudbuild_bitbucket_server_config_generated_test.go b/google-beta/services/cloudbuild/resource_cloudbuild_bitbucket_server_config_generated_test.go index 22847ea6be..87aa7a997f 100644 --- a/google-beta/services/cloudbuild/resource_cloudbuild_bitbucket_server_config_generated_test.go +++ b/google-beta/services/cloudbuild/resource_cloudbuild_bitbucket_server_config_generated_test.go @@ -76,7 +76,6 @@ func TestAccCloudBuildBitbucketServerConfig_cloudbuildBitbucketServerConfigPeere t.Parallel() context := map[string]interface{}{ - "network_name": acctest.BootstrapSharedTestNetwork(t, "peered-network"), "random_suffix": acctest.RandString(t, 10), } @@ -106,9 +105,9 @@ resource "google_project_service" "servicenetworking" { service = "servicenetworking.googleapis.com" disable_on_destroy = false } - -data "google_compute_network" "vpc_network" { - name = "%{network_name}" + +resource "google_compute_network" "vpc_network" { + name = "tf-test-vpc-network%{random_suffix}" depends_on = [google_project_service.servicenetworking] } @@ -117,11 +116,11 @@ resource "google_compute_global_address" "private_ip_alloc" { purpose = "VPC_PEERING" address_type = "INTERNAL" prefix_length = 16 - network = data.google_compute_network.vpc_network.id + network = google_compute_network.vpc_network.id } resource "google_service_networking_connection" "default" { - network = data.google_compute_network.vpc_network.id + network = google_compute_network.vpc_network.id service = "servicenetworking.googleapis.com" reserved_peering_ranges = [google_compute_global_address.private_ip_alloc.name] depends_on = [google_project_service.servicenetworking] @@ -138,7 +137,7 @@ resource "google_cloudbuild_bitbucket_server_config" "bbs-config-with-peered-net } username = "test" api_key = "" - peered_network = replace(data.google_compute_network.vpc_network.id, data.google_project.project.name, data.google_project.project.number) + peered_network = replace(google_compute_network.vpc_network.id, data.google_project.project.name, data.google_project.project.number) ssl_ca = "-----BEGIN CERTIFICATE-----\n-----END CERTIFICATE-----\n-----BEGIN CERTIFICATE-----\n-----END CERTIFICATE-----\n" depends_on = [google_service_networking_connection.default] } diff --git a/google-beta/services/cloudbuild/resource_cloudbuild_worker_pool_test.go b/google-beta/services/cloudbuild/resource_cloudbuild_worker_pool_test.go index 6204f297b5..aa33262b92 100644 --- a/google-beta/services/cloudbuild/resource_cloudbuild_worker_pool_test.go +++ b/google-beta/services/cloudbuild/resource_cloudbuild_worker_pool_test.go @@ -105,7 +105,7 @@ func TestAccCloudbuildWorkerPool_withNetwork(t *testing.T) { context := map[string]interface{}{ "random_suffix": acctest.RandString(t, 10), "project": envvar.GetTestProjectFromEnv(), - "network_name": "tf-test-" + acctest.RandString(t, 10), + "network_name": acctest.BootstrapSharedServiceNetworkingConnection(t, "cloudbuild-workerpool-1"), } acctest.VcrTest(t, resource.TestCase{ @@ -128,24 +128,10 @@ func TestAccCloudbuildWorkerPool_withNetwork(t *testing.T) { func testAccCloudbuildWorkerPool_withNetwork(context map[string]interface{}) string { return acctest.Nprintf(` -resource "google_compute_network" "network" { +data "google_compute_network" "network" { name = "%{network_name}" } -resource "google_compute_global_address" "worker_range" { - name = "tf-test-worker-pool-range%{random_suffix}" - purpose = "VPC_PEERING" - address_type = "INTERNAL" - prefix_length = 16 - network = google_compute_network.network.id -} - -resource "google_service_networking_connection" "worker_pool_conn" { - network = google_compute_network.network.id - service = "servicenetworking.googleapis.com" - reserved_peering_ranges = [google_compute_global_address.worker_range.name] -} - resource "google_cloudbuild_worker_pool" "pool" { name = "pool%{random_suffix}" location = "europe-west1" @@ -155,10 +141,9 @@ resource "google_cloudbuild_worker_pool" "pool" { no_external_ip = false } network_config { - peered_network = google_compute_network.network.id + peered_network = data.google_compute_network.network.id peered_network_ip_range = "/29" } - depends_on = [google_service_networking_connection.worker_pool_conn] } `, context) } diff --git a/google-beta/services/cloudids/resource_cloudids_endpoint_test.go b/google-beta/services/cloudids/resource_cloudids_endpoint_test.go index c7eeeec664..f5e1090911 100644 --- a/google-beta/services/cloudids/resource_cloudids_endpoint_test.go +++ b/google-beta/services/cloudids/resource_cloudids_endpoint_test.go @@ -20,7 +20,7 @@ func TestAccCloudIdsEndpoint_basic(t *testing.T) { context := map[string]interface{}{ "random_suffix": acctest.RandString(t, 10), - "network_name": "tf-test-key-" + acctest.RandString(t, 10), + "network_name": acctest.BootstrapSharedServiceNetworkingConnection(t, "cloud-ids-endpoint-1"), } acctest.VcrTest(t, resource.TestCase{ @@ -50,58 +50,32 @@ func TestAccCloudIdsEndpoint_basic(t *testing.T) { func testCloudIds_basic(context map[string]interface{}) string { return acctest.Nprintf(` -resource "google_compute_network" "default" { +data "google_compute_network" "default" { name = "%{network_name}" } -resource "google_compute_global_address" "service_range" { - name = "tf-test-address%{random_suffix}" - purpose = "VPC_PEERING" - address_type = "INTERNAL" - prefix_length = 16 - network = google_compute_network.default.id -} -resource "google_service_networking_connection" "private_service_connection" { - network = google_compute_network.default.id - service = "servicenetworking.googleapis.com" - reserved_peering_ranges = [google_compute_global_address.service_range.name] -} resource "google_cloud_ids_endpoint" "endpoint" { name = "cloud-ids-test-%{random_suffix}" location = "us-central1-f" - network = google_compute_network.default.id + network = data.google_compute_network.default.id severity = "INFORMATIONAL" threat_exceptions = ["12", "67"] - depends_on = [google_service_networking_connection.private_service_connection] } `, context) } func testCloudIds_basicUpdate(context map[string]interface{}) string { return acctest.Nprintf(` -resource "google_compute_network" "default" { +data "google_compute_network" "default" { name = "%{network_name}" } -resource "google_compute_global_address" "service_range" { - name = "tf-test-address%{random_suffix}" - purpose = "VPC_PEERING" - address_type = "INTERNAL" - prefix_length = 16 - network = google_compute_network.default.id -} -resource "google_service_networking_connection" "private_service_connection" { - network = google_compute_network.default.id - service = "servicenetworking.googleapis.com" - reserved_peering_ranges = [google_compute_global_address.service_range.name] -} resource "google_cloud_ids_endpoint" "endpoint" { name = "cloud-ids-test-%{random_suffix}" location = "us-central1-f" - network = google_compute_network.default.id + network = data.google_compute_network.default.id severity = "INFORMATIONAL" threat_exceptions = ["33"] - depends_on = [google_service_networking_connection.private_service_connection] } `, context) } diff --git a/google-beta/services/databasemigrationservice/resource_database_migration_service_connection_profile_generated_test.go b/google-beta/services/databasemigrationservice/resource_database_migration_service_connection_profile_generated_test.go index 7dbea45568..cd8e197e0a 100644 --- a/google-beta/services/databasemigrationservice/resource_database_migration_service_connection_profile_generated_test.go +++ b/google-beta/services/databasemigrationservice/resource_database_migration_service_connection_profile_generated_test.go @@ -221,92 +221,6 @@ resource "google_database_migration_service_connection_profile" "postgresprofile `, context) } -func TestAccDatabaseMigrationServiceConnectionProfile_databaseMigrationServiceConnectionProfileAlloydbExample(t *testing.T) { - t.Parallel() - - context := map[string]interface{}{ - "random_suffix": acctest.RandString(t, 10), - } - - acctest.VcrTest(t, resource.TestCase{ - PreCheck: func() { acctest.AccTestPreCheck(t) }, - ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t), - CheckDestroy: testAccCheckDatabaseMigrationServiceConnectionProfileDestroyProducer(t), - Steps: []resource.TestStep{ - { - Config: testAccDatabaseMigrationServiceConnectionProfile_databaseMigrationServiceConnectionProfileAlloydbExample(context), - }, - { - ResourceName: "google_database_migration_service_connection_profile.alloydbprofile", - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"connection_profile_id", "location", "alloydb.0.settings.0.initial_user.0.password", "labels", "terraform_labels"}, - }, - }, - }) -} - -func testAccDatabaseMigrationServiceConnectionProfile_databaseMigrationServiceConnectionProfileAlloydbExample(context map[string]interface{}) string { - return acctest.Nprintf(` -data "google_project" "project" { -} - -resource "google_compute_network" "default" { - name = "tf-test-vpc-network%{random_suffix}" -} - -resource "google_compute_global_address" "private_ip_alloc" { - name = "tf-test-private-ip-alloc%{random_suffix}" - address_type = "INTERNAL" - purpose = "VPC_PEERING" - prefix_length = 16 - network = google_compute_network.default.id -} - -resource "google_service_networking_connection" "vpc_connection" { - network = google_compute_network.default.id - service = "servicenetworking.googleapis.com" - reserved_peering_ranges = [google_compute_global_address.private_ip_alloc.name] -} - - -resource "google_database_migration_service_connection_profile" "alloydbprofile" { - location = "us-central1" - connection_profile_id = "tf-test-my-profileid%{random_suffix}" - display_name = "tf-test-my-profileid%{random_suffix}_display" - labels = { - foo = "bar" - } - alloydb { - cluster_id = "tf-test-dbmsalloycluster%{random_suffix}" - settings { - initial_user { - user = "alloyuser%{random_suffix}" - password = "alloypass%{random_suffix}" - } - vpc_network = google_compute_network.default.id - labels = { - alloyfoo = "alloybar" - } - primary_instance_settings { - id = "priminstid" - machine_config { - cpu_count = 2 - } - database_flags = { - } - labels = { - alloysinstfoo = "allowinstbar" - } - } - } - } - - depends_on = [google_service_networking_connection.vpc_connection] -} -`, context) -} - func testAccCheckDatabaseMigrationServiceConnectionProfileDestroyProducer(t *testing.T) func(s *terraform.State) error { return func(s *terraform.State) error { for name, rs := range s.RootModule().Resources { diff --git a/google-beta/services/databasemigrationservice/resource_database_migration_service_connection_profile_test.go b/google-beta/services/databasemigrationservice/resource_database_migration_service_connection_profile_test.go index fd79c9f9fc..fb642b8f02 100644 --- a/google-beta/services/databasemigrationservice/resource_database_migration_service_connection_profile_test.go +++ b/google-beta/services/databasemigrationservice/resource_database_migration_service_connection_profile_test.go @@ -79,3 +79,70 @@ resource "google_database_migration_service_connection_profile" "default" { } `, context) } + +func TestAccDatabaseMigrationServiceConnectionProfile_databaseMigrationServiceConnectionProfileAlloydb(t *testing.T) { + t.Parallel() + + context := map[string]interface{}{ + "random_suffix": acctest.RandString(t, 10), + "network_name": acctest.BootstrapSharedServiceNetworkingConnection(t, "vpc-network-1"), + } + + acctest.VcrTest(t, resource.TestCase{ + PreCheck: func() { acctest.AccTestPreCheck(t) }, + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t), + CheckDestroy: testAccCheckDatabaseMigrationServiceConnectionProfileDestroyProducer(t), + Steps: []resource.TestStep{ + { + Config: testAccDatabaseMigrationServiceConnectionProfile_databaseMigrationServiceConnectionProfileAlloydb(context), + }, + { + ResourceName: "google_database_migration_service_connection_profile.alloydbprofile", + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"connection_profile_id", "location", "alloydb.0.settings.0.initial_user.0.password", "labels", "terraform_labels"}, + }, + }, + }) +} + +func testAccDatabaseMigrationServiceConnectionProfile_databaseMigrationServiceConnectionProfileAlloydb(context map[string]interface{}) string { + return acctest.Nprintf(` +data "google_compute_network" "default" { + name = "%{network_name}" +} + +resource "google_database_migration_service_connection_profile" "alloydbprofile" { + location = "us-central1" + connection_profile_id = "tf-test-my-profileid%{random_suffix}" + display_name = "tf-test-my-profileid%{random_suffix}_display" + labels = { + foo = "bar" + } + alloydb { + cluster_id = "tf-test-dbmsalloycluster%{random_suffix}" + settings { + initial_user { + user = "alloyuser%{random_suffix}" + password = "alloypass%{random_suffix}" + } + vpc_network = data.google_compute_network.default.id + labels = { + alloyfoo = "alloybar" + } + primary_instance_settings { + id = "priminstid" + machine_config { + cpu_count = 2 + } + database_flags = { + } + labels = { + alloysinstfoo = "allowinstbar" + } + } + } + } +} +`, context) +} diff --git a/google-beta/services/memcache/resource_memcache_instance_test.go b/google-beta/services/memcache/resource_memcache_instance_test.go index 1c237ae772..956084a9be 100644 --- a/google-beta/services/memcache/resource_memcache_instance_test.go +++ b/google-beta/services/memcache/resource_memcache_instance_test.go @@ -15,7 +15,7 @@ func TestAccMemcacheInstance_update(t *testing.T) { prefix := fmt.Sprintf("%d", acctest.RandInt(t)) name := fmt.Sprintf("tf-test-%s", prefix) - network := "tf-test-" + acctest.RandString(t, 10) + network := acctest.BootstrapSharedServiceNetworkingConnection(t, "memcache-instance-update-1") acctest.VcrTest(t, resource.TestCase{ PreCheck: func() { acctest.AccTestPreCheck(t) }, @@ -44,24 +44,10 @@ func TestAccMemcacheInstance_update(t *testing.T) { func testAccMemcacheInstance_update(prefix, name, network string) string { return fmt.Sprintf(` -resource "google_compute_global_address" "service_range" { - name = "tf-test%s" - purpose = "VPC_PEERING" - address_type = "INTERNAL" - prefix_length = 16 - network = google_compute_network.memcache_network.id -} - -resource "google_service_networking_connection" "private_service_connection" { - network = google_compute_network.memcache_network.id - service = "servicenetworking.googleapis.com" - reserved_peering_ranges = [google_compute_global_address.service_range.name] -} - resource "google_memcache_instance" "test" { name = "%s" region = "us-central1" - authorized_network = google_service_networking_connection.private_service_connection.network + authorized_network = data.google_compute_network.memcache_network.id node_config { cpu_count = 1 @@ -77,32 +63,18 @@ resource "google_memcache_instance" "test" { } } -resource "google_compute_network" "memcache_network" { +data "google_compute_network" "memcache_network" { name = "%s" } -`, prefix, name, network) +`, name, network) } func testAccMemcacheInstance_update2(prefix, name, network string) string { return fmt.Sprintf(` -resource "google_compute_global_address" "service_range" { - name = "tf-test%s" - purpose = "VPC_PEERING" - address_type = "INTERNAL" - prefix_length = 16 - network = google_compute_network.memcache_network.id -} - -resource "google_service_networking_connection" "private_service_connection" { - network = google_compute_network.memcache_network.id - service = "servicenetworking.googleapis.com" - reserved_peering_ranges = [google_compute_global_address.service_range.name] -} - resource "google_memcache_instance" "test" { name = "%s" region = "us-central1" - authorized_network = google_service_networking_connection.private_service_connection.network + authorized_network = data.google_compute_network.memcache_network.id node_config { cpu_count = 1 @@ -118,8 +90,8 @@ resource "google_memcache_instance" "test" { } } -resource "google_compute_network" "memcache_network" { +data "google_compute_network" "memcache_network" { name = "%s" } -`, prefix, name, network) +`, name, network) } diff --git a/google-beta/services/servicenetworking/resource_service_networking_connection.go b/google-beta/services/servicenetworking/resource_service_networking_connection.go index 4fd143b388..1014381d9d 100644 --- a/google-beta/services/servicenetworking/resource_service_networking_connection.go +++ b/google-beta/services/servicenetworking/resource_service_networking_connection.go @@ -10,13 +10,11 @@ import ( "strings" "time" - tpgcompute "github.com/hashicorp/terraform-provider-google-beta/google-beta/services/compute" "github.com/hashicorp/terraform-provider-google-beta/google-beta/tpgresource" transport_tpg "github.com/hashicorp/terraform-provider-google-beta/google-beta/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" ) @@ -263,42 +261,35 @@ func resourceServiceNetworkingConnectionDelete(d *schema.ResourceData, meta inte 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), - }) + connectionId, err := parseConnectionId(d.Id()) if err != nil { - return transport_tpg.HandleNotFoundError(err, d, fmt.Sprintf("ServiceNetworkingConnection %q", d.Id())) + return errwrap.Wrapf("Unable to parse Service Networking Connection id, err: {{err}}", err) } + parentService := formatParentService(connectionId.Service) - op := &compute.Operation{} - err = tpgresource.Convert(res, op) - if err != nil { - return err + deleteConnectionRequest := &servicenetworking.DeleteConnectionRequest{ + ConsumerNetwork: serviceNetworkingNetworkName, } - err = tpgcompute.ComputeOperationWaitTime( - config, op, project, "Updating Network", userAgent, d.Timeout(schema.TimeoutDelete)) + deleteCall := config.NewServiceNetworkingClient(userAgent).Services.Connections.DeleteConnection(parentService+"/connections/servicenetworking-googleapis-com", deleteConnectionRequest) + if config.UserProjectOverride { + deleteCall.Header().Add("X-Goog-User-Project", project) + } + op, err := deleteCall.Do() if err != nil { return err } + if err := ServiceNetworkingOperationWaitTime(config, op, "Delete Service Networking Connection", userAgent, project, d.Timeout(schema.TimeoutCreate)); err != nil { + return errwrap.Wrapf("Unable to remove Service Networking Connection, err: {{err}}", err) + } + d.SetId("") log.Printf("[INFO] Service network connection removed.") diff --git a/google-beta/services/servicenetworking/resource_service_networking_connection_test.go b/google-beta/services/servicenetworking/resource_service_networking_connection_test.go index 7550e9ef84..c2f327f614 100644 --- a/google-beta/services/servicenetworking/resource_service_networking_connection_test.go +++ b/google-beta/services/servicenetworking/resource_service_networking_connection_test.go @@ -15,7 +15,7 @@ import ( func TestAccServiceNetworkingConnection_create(t *testing.T) { t.Parallel() - network := acctest.BootstrapSharedTestNetwork(t, "service-networking-connection-create") + network := fmt.Sprintf("tf-test-service-networking-connection-create-%s", acctest.RandString(t, 10)) addr := fmt.Sprintf("tf-test-%s", acctest.RandString(t, 10)) service := "servicenetworking.googleapis.com" @@ -39,7 +39,7 @@ func TestAccServiceNetworkingConnection_create(t *testing.T) { func TestAccServiceNetworkingConnection_update(t *testing.T) { t.Parallel() - network := acctest.BootstrapSharedTestNetwork(t, "service-networking-connection-update") + network := fmt.Sprintf("tf-test-service-networking-connection-update-%s", acctest.RandString(t, 10)) addr1 := fmt.Sprintf("tf-test-%s", acctest.RandString(t, 10)) addr2 := fmt.Sprintf("tf-test-%s", acctest.RandString(t, 10)) service := "servicenetworking.googleapis.com" @@ -96,7 +96,7 @@ func testServiceNetworkingConnectionDestroy(t *testing.T, parent, network string func testAccServiceNetworkingConnection(networkName, addressRangeName, serviceName string) string { return fmt.Sprintf(` -data "google_compute_network" "servicenet" { +resource "google_compute_network" "servicenet" { name = "%s" } @@ -105,11 +105,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 = "%s" reserved_peering_ranges = [google_compute_global_address.foobar.name] } diff --git a/google-beta/services/sql/resource_sql_database_instance_test.go b/google-beta/services/sql/resource_sql_database_instance_test.go index 36a0432a0d..0f3643fd4b 100644 --- a/google-beta/services/sql/resource_sql_database_instance_test.go +++ b/google-beta/services/sql/resource_sql_database_instance_test.go @@ -180,8 +180,12 @@ func TestAccSqlDatabaseInstance_deleteDefaultUserBeforeSubsequentApiCalls(t *tes t.Parallel() databaseName := "tf-test-" + acctest.RandString(t, 10) - addressName := "tf-test-" + acctest.RandString(t, 10) - networkName := "tf-test-" + acctest.RandString(t, 10) + 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. @@ -193,7 +197,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() { @@ -738,8 +742,7 @@ func TestAccSqlDatabaseInstance_withPrivateNetwork_withoutAllocatedIpRange(t *te t.Parallel() databaseName := "tf-test-" + acctest.RandString(t, 10) - addressName := "tf-test-" + acctest.RandString(t, 10) - networkName := "tf-test-" + acctest.RandString(t, 10) + networkName := acctest.BootstrapSharedServiceNetworkingConnection(t, "sql-instance-1") acctest.VcrTest(t, resource.TestCase{ PreCheck: func() { acctest.AccTestPreCheck(t) }, @@ -747,7 +750,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", @@ -756,7 +759,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", @@ -765,7 +768,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", @@ -774,7 +777,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", @@ -977,10 +980,19 @@ func TestAccSqlDatabaseInstance_withPrivateNetwork_withAllocatedIpRange(t *testi t.Parallel() databaseName := "tf-test-" + acctest.RandString(t, 10) - addressName := "tf-test-" + acctest.RandString(t, 10) - networkName := "tf-test-" + acctest.RandString(t, 10) - addressName_update := "tf-test-" + acctest.RandString(t, 10) + "update" - networkName_update := "tf-test-" + acctest.RandString(t, 10) + "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) }, @@ -1014,8 +1026,13 @@ func TestAccSqlDatabaseInstance_withPrivateNetwork_withAllocatedIpRangeReplica(t t.Parallel() databaseName := "tf-test-" + acctest.RandString(t, 10) - addressName := "tf-test-" + acctest.RandString(t, 10) - networkName := "tf-test-" + acctest.RandString(t, 10) + + 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) }, @@ -1046,8 +1063,12 @@ func TestAccSqlDatabaseInstance_withPrivateNetwork_withAllocatedIpRangeClone(t * t.Parallel() databaseName := "tf-test-" + acctest.RandString(t, 10) - addressName := "tf-test-" + acctest.RandString(t, 10) - networkName := "tf-test-" + acctest.RandString(t, 10) + 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) }, @@ -1447,8 +1468,7 @@ func TestAccSqlDatabaseInstance_ActiveDirectory(t *testing.T) { t.Parallel() databaseName := "tf-test-" + acctest.RandString(t, 10) - networkName := acctest.BootstrapSharedTestNetwork(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) @@ -1458,7 +1478,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", @@ -2176,28 +2196,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" @@ -2214,7 +2219,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 { @@ -2805,33 +2810,18 @@ 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) } 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" @@ -2840,36 +2830,21 @@ 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 %s } } } -`, 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" @@ -2878,36 +2853,21 @@ 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 { 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" @@ -2916,7 +2876,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 } backup_configuration { enabled = true @@ -2926,7 +2886,6 @@ resource "google_sql_database_instance" "instance" { } } resource "google_sql_database_instance" "replica1" { - depends_on = [google_service_networking_connection.foobar] name = "%s-replica1" region = "us-central1" database_version = "MYSQL_5_7" @@ -2935,8 +2894,8 @@ resource "google_sql_database_instance" "replica1" { 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" } } @@ -2951,31 +2910,16 @@ 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 { 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" @@ -2984,7 +2928,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 } backup_configuration { enabled = true @@ -3002,35 +2946,20 @@ 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 { 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" @@ -3039,7 +2968,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 } backup_configuration { enabled = true @@ -3057,7 +2986,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 { @@ -3067,7 +2996,7 @@ resource "google_sql_database_instance" "clone1" { } } } -`, networkName, addressRangeName, databaseName, databaseName) +`, networkName, databaseName, databaseName, addressRangeName) } var testGoogleSqlDatabaseInstance_settings = ` diff --git a/google-beta/services/tpu/resource_tpu_node_generated_test.go b/google-beta/services/tpu/resource_tpu_node_generated_test.go index ccffcaf4d8..18c182063e 100644 --- a/google-beta/services/tpu/resource_tpu_node_generated_test.go +++ b/google-beta/services/tpu/resource_tpu_node_generated_test.go @@ -124,8 +124,8 @@ resource "google_tpu_node" "tpu" { } } -data "google_compute_network" "network" { - name = "default" +resource "google_compute_network" "network" { + name = "tf-test-tpu-node-network%{random_suffix}" } resource "google_compute_global_address" "service_range" { @@ -133,11 +133,11 @@ resource "google_compute_global_address" "service_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" "private_service_connection" { - network = data.google_compute_network.network.id + network = google_compute_network.network.id service = "servicenetworking.googleapis.com" reserved_peering_ranges = [google_compute_global_address.service_range.name] } diff --git a/google-beta/services/vertexai/resource_vertex_ai_endpoint_test.go b/google-beta/services/vertexai/resource_vertex_ai_endpoint_test.go index 69300325dd..e220ece555 100644 --- a/google-beta/services/vertexai/resource_vertex_ai_endpoint_test.go +++ b/google-beta/services/vertexai/resource_vertex_ai_endpoint_test.go @@ -20,7 +20,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.BootstrapSharedTestNetwork(t, "vertex-ai-endpoint-update"), + "network_name": acctest.BootstrapSharedServiceNetworkingConnection(t, "vertex-ai-endpoint-update-1"), "random_suffix": acctest.RandString(t, 10), } @@ -66,23 +66,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" { @@ -114,23 +97,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/google-beta/services/vertexai/resource_vertex_ai_index_endpoint_generated_test.go b/google-beta/services/vertexai/resource_vertex_ai_index_endpoint_generated_test.go index 70c7c2363f..3baa865c34 100644 --- a/google-beta/services/vertexai/resource_vertex_ai_index_endpoint_generated_test.go +++ b/google-beta/services/vertexai/resource_vertex_ai_index_endpoint_generated_test.go @@ -34,7 +34,6 @@ func TestAccVertexAIIndexEndpoint_vertexAiIndexEndpointExample(t *testing.T) { t.Parallel() context := map[string]interface{}{ - "network_name": acctest.BootstrapSharedTestNetwork(t, "vertex-ai-index-endpoint"), "random_suffix": acctest.RandString(t, 10), } @@ -65,14 +64,14 @@ resource "google_vertex_ai_index_endpoint" "index_endpoint" { labels = { label-one = "value-one" } - network = "projects/${data.google_project.project.number}/global/networks/${data.google_compute_network.vertex_network.name}" + network = "projects/${data.google_project.project.number}/global/networks/${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 + network = google_compute_network.vertex_network.id service = "servicenetworking.googleapis.com" reserved_peering_ranges = [google_compute_global_address.vertex_range.name] } @@ -82,11 +81,11 @@ resource "google_compute_global_address" "vertex_range" { purpose = "VPC_PEERING" address_type = "INTERNAL" prefix_length = 24 - network = data.google_compute_network.vertex_network.id + network = google_compute_network.vertex_network.id } -data "google_compute_network" "vertex_network" { - name = "%{network_name}" +resource "google_compute_network" "vertex_network" { + name = "tf-test-network-name%{random_suffix}" } data "google_project" "project" {} diff --git a/google-beta/services/vertexai/resource_vertex_ai_index_endpoint_test.go b/google-beta/services/vertexai/resource_vertex_ai_index_endpoint_test.go index 3e1679c1d4..aec076b893 100644 --- a/google-beta/services/vertexai/resource_vertex_ai_index_endpoint_test.go +++ b/google-beta/services/vertexai/resource_vertex_ai_index_endpoint_test.go @@ -14,7 +14,7 @@ func TestAccVertexAIIndexEndpoint_updated(t *testing.T) { t.Parallel() context := map[string]interface{}{ - "network_name": acctest.BootstrapSharedTestNetwork(t, "vertex-ai-index-endpoint-update"), + "network_name": acctest.BootstrapSharedServiceNetworkingConnection(t, "vertex-ai-index-endpoint-update-1"), "random_suffix": acctest.RandString(t, 10), } @@ -30,7 +30,7 @@ func TestAccVertexAIIndexEndpoint_updated(t *testing.T) { ResourceName: "google_vertex_ai_index_endpoint.index_endpoint", ImportState: true, ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"etag", "region"}, + ImportStateVerifyIgnore: []string{"etag", "region", "labels", "terraform_labels"}, }, { Config: testAccVertexAIIndexEndpoint_updated(context), @@ -39,7 +39,7 @@ func TestAccVertexAIIndexEndpoint_updated(t *testing.T) { ResourceName: "google_vertex_ai_index_endpoint.index_endpoint", ImportState: true, ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"etag", "region"}, + ImportStateVerifyIgnore: []string{"etag", "region", "labels", "terraform_labels"}, }, }, }) @@ -55,15 +55,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" @@ -89,22 +82,8 @@ resource "google_vertex_ai_index_endpoint" "index_endpoint" { label-two = "value-two" } 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" - address_type = "INTERNAL" - prefix_length = 24 - network = data.google_compute_network.vertex_network.id } + data "google_compute_network" "vertex_network" { name = "%{network_name}" } diff --git a/website/docs/r/cloudbuild_bitbucket_server_config.html.markdown b/website/docs/r/cloudbuild_bitbucket_server_config.html.markdown index 45b1e9b685..94cfc1fed8 100644 --- a/website/docs/r/cloudbuild_bitbucket_server_config.html.markdown +++ b/website/docs/r/cloudbuild_bitbucket_server_config.html.markdown @@ -91,8 +91,8 @@ resource "google_project_service" "servicenetworking" { service = "servicenetworking.googleapis.com" disable_on_destroy = false } - -data "google_compute_network" "vpc_network" { + +resource "google_compute_network" "vpc_network" { name = "vpc-network" depends_on = [google_project_service.servicenetworking] } @@ -102,11 +102,11 @@ resource "google_compute_global_address" "private_ip_alloc" { purpose = "VPC_PEERING" address_type = "INTERNAL" prefix_length = 16 - network = data.google_compute_network.vpc_network.id + network = google_compute_network.vpc_network.id } resource "google_service_networking_connection" "default" { - network = data.google_compute_network.vpc_network.id + network = google_compute_network.vpc_network.id service = "servicenetworking.googleapis.com" reserved_peering_ranges = [google_compute_global_address.private_ip_alloc.name] depends_on = [google_project_service.servicenetworking] @@ -123,7 +123,7 @@ resource "google_cloudbuild_bitbucket_server_config" "bbs-config-with-peered-net } username = "test" api_key = "" - peered_network = replace(data.google_compute_network.vpc_network.id, data.google_project.project.name, data.google_project.project.number) + peered_network = replace(google_compute_network.vpc_network.id, data.google_project.project.name, data.google_project.project.number) ssl_ca = "-----BEGIN CERTIFICATE-----\n-----END CERTIFICATE-----\n-----BEGIN CERTIFICATE-----\n-----END CERTIFICATE-----\n" depends_on = [google_service_networking_connection.default] } diff --git a/website/docs/r/database_migration_service_connection_profile.html.markdown b/website/docs/r/database_migration_service_connection_profile.html.markdown index 0454352d75..6a36b49c91 100644 --- a/website/docs/r/database_migration_service_connection_profile.html.markdown +++ b/website/docs/r/database_migration_service_connection_profile.html.markdown @@ -183,11 +183,6 @@ resource "google_database_migration_service_connection_profile" "postgresprofile depends_on = [google_sql_user.sqldb_user] } ``` - ## Example Usage - Database Migration Service Connection Profile Alloydb diff --git a/website/docs/r/tpu_node.html.markdown b/website/docs/r/tpu_node.html.markdown index 54ba70a917..803c324bed 100644 --- a/website/docs/r/tpu_node.html.markdown +++ b/website/docs/r/tpu_node.html.markdown @@ -84,8 +84,8 @@ resource "google_tpu_node" "tpu" { } } -data "google_compute_network" "network" { - name = "default" +resource "google_compute_network" "network" { + name = "tpu-node-network" } resource "google_compute_global_address" "service_range" { @@ -93,11 +93,11 @@ resource "google_compute_global_address" "service_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" "private_service_connection" { - network = data.google_compute_network.network.id + network = google_compute_network.network.id service = "servicenetworking.googleapis.com" reserved_peering_ranges = [google_compute_global_address.service_range.name] } diff --git a/website/docs/r/vertex_ai_endpoint.html.markdown b/website/docs/r/vertex_ai_endpoint.html.markdown index c3d1e42c96..568caf1929 100644 --- a/website/docs/r/vertex_ai_endpoint.html.markdown +++ b/website/docs/r/vertex_ai_endpoint.html.markdown @@ -41,7 +41,7 @@ resource "google_vertex_ai_endpoint" "endpoint" { labels = { label-one = "value-one" } - network = "projects/${data.google_project.project.number}/global/networks/${data.google_compute_network.vertex_network.name}" + network = "projects/${data.google_project.project.number}/global/networks/${google_compute_network.vertex_network.name}" encryption_spec { kms_key_name = "kms-name" } @@ -51,7 +51,7 @@ resource "google_vertex_ai_endpoint" "endpoint" { } resource "google_service_networking_connection" "vertex_vpc_connection" { - network = data.google_compute_network.vertex_network.id + network = google_compute_network.vertex_network.id service = "servicenetworking.googleapis.com" reserved_peering_ranges = [google_compute_global_address.vertex_range.name] } @@ -61,10 +61,10 @@ resource "google_compute_global_address" "vertex_range" { purpose = "VPC_PEERING" address_type = "INTERNAL" prefix_length = 24 - network = data.google_compute_network.vertex_network.id + network = google_compute_network.vertex_network.id } -data "google_compute_network" "vertex_network" { +resource "google_compute_network" "vertex_network" { name = "network-name" } diff --git a/website/docs/r/vertex_ai_index_endpoint.html.markdown b/website/docs/r/vertex_ai_index_endpoint.html.markdown index cdb0165f05..e7b82b05bc 100644 --- a/website/docs/r/vertex_ai_index_endpoint.html.markdown +++ b/website/docs/r/vertex_ai_index_endpoint.html.markdown @@ -42,14 +42,14 @@ resource "google_vertex_ai_index_endpoint" "index_endpoint" { labels = { label-one = "value-one" } - network = "projects/${data.google_project.project.number}/global/networks/${data.google_compute_network.vertex_network.name}" + network = "projects/${data.google_project.project.number}/global/networks/${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 + network = google_compute_network.vertex_network.id service = "servicenetworking.googleapis.com" reserved_peering_ranges = [google_compute_global_address.vertex_range.name] } @@ -59,10 +59,10 @@ resource "google_compute_global_address" "vertex_range" { purpose = "VPC_PEERING" address_type = "INTERNAL" prefix_length = 24 - network = data.google_compute_network.vertex_network.id + network = google_compute_network.vertex_network.id } -data "google_compute_network" "vertex_network" { +resource "google_compute_network" "vertex_network" { name = "network-name" }