From b9e33704b4cd84b1cb29203737584a1e14748195 Mon Sep 17 00:00:00 2001 From: Michael Callahan Date: Tue, 9 Jan 2024 04:21:59 +0000 Subject: [PATCH] added test coverage --- ...urce_service_networking_connection_test.go | 88 +++++++++++++++++++ 1 file changed, 88 insertions(+) diff --git a/mmv1/third_party/terraform/services/servicenetworking/resource_service_networking_connection_test.go b/mmv1/third_party/terraform/services/servicenetworking/resource_service_networking_connection_test.go index dbbe7c7c32fe..597d36afd3c3 100644 --- a/mmv1/third_party/terraform/services/servicenetworking/resource_service_networking_connection_test.go +++ b/mmv1/third_party/terraform/services/servicenetworking/resource_service_networking_connection_test.go @@ -36,6 +36,32 @@ func TestAccServiceNetworkingConnection_create(t *testing.T) { }) } +func TestAccServiceNetworkingConnection_abandon(t *testing.T) { + t.Parallel() + + network := fmt.Sprintf("tf-test-service-networking-connection-abandon-%s", acctest.RandString(t, 10)) + addr := fmt.Sprintf("tf-test-%s", acctest.RandString(t, 10)) + service := "servicenetworking.googleapis.com" + org_id := envvar.GetTestOrgFromEnv(t) + billing_account := envvar.GetTestBillingAccountFromEnv(t) + + acctest.VcrTest(t, resource.TestCase{ + PreCheck: func() { acctest.AccTestPreCheck(t) }, + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t), + CheckDestroy: testServiceNetworkingConnectionDestroyAbandon(t, service, network), + Steps: []resource.TestStep{ + { + Config: testAccServiceNetworkingConnectionToBeAbandoned(network, addr, "servicenetworking.googleapis.com", org_id, billing_account), + }, + { + ResourceName: "google_service_networking_connection.foobar", + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + func TestAccServiceNetworkingConnection_update(t *testing.T) { t.Parallel() @@ -96,6 +122,30 @@ func testServiceNetworkingConnectionDestroy(t *testing.T, parent, network string } } +func testServiceNetworkingConnectionDestroyAbandon(t *testing.T, parent, network string) resource.TestCheckFunc { + return func(s *terraform.State) error { + config := acctest.GoogleProviderConfig(t) + parentService := "services/" + parent + networkName := fmt.Sprintf("projects/%s/global/networks/%s", envvar.GetTestProjectFromEnv(), network) + listCall := config.NewServiceNetworkingClient(config.UserAgent).Services.Connections.List(parentService).Network(networkName) + if config.UserProjectOverride { + listCall.Header().Add("X-Goog-User-Project", envvar.GetTestProjectFromEnv()) + } + response, err := listCall.Do() + if err != nil { + return err + } + + for _, c := range response.Connections { + if c.Network == networkName { + return nil + } + } + + return fmt.Errorf("Did not find %s which should still exist.", networkName) + } +} + func testAccServiceNetworkingConnection(networkName, addressRangeName, serviceName, org_id, billing_account string) string { return fmt.Sprintf(` resource "google_project" "project" { @@ -132,3 +182,41 @@ resource "google_service_networking_connection" "foobar" { } `, addressRangeName, addressRangeName, org_id, billing_account, networkName, addressRangeName, serviceName) } + +func testAccServiceNetworkingConnectionToBeAbandoned(networkName, addressRangeName, serviceName, org_id, billing_account string) string { + return fmt.Sprintf(` +resource "google_project" "project" { + project_id = "%s" + name = "%s" + org_id = "%s" + billing_account = "%s" +} + +resource "google_project_service" "servicenetworking" { + project = google_project.project.project_id + service = "servicenetworking.googleapis.com" +} + +resource "google_compute_network" "servicenet" { + name = "%s" + depends_on = [google_project_service.servicenetworking] +} + +resource "google_compute_global_address" "foobar" { + name = "%s" + purpose = "VPC_PEERING" + address_type = "INTERNAL" + prefix_length = 16 + network = google_compute_network.servicenet.self_link + depends_on = [google_project_service.servicenetworking] +} + +resource "google_service_networking_connection" "foobar" { + network = google_compute_network.servicenet.self_link + service = "%s" + reserved_peering_ranges = [google_compute_global_address.foobar.name] + depends_on = [google_project_service.servicenetworking] + deletion_policy = "ABANDON" +} +`, addressRangeName, addressRangeName, org_id, billing_account, networkName, addressRangeName, serviceName) +}