blob: c4cb65bdab9bb6547602b0b3dbdac0c044d9c371 [file] [log] [blame] [edit]
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
// ----------------------------------------------------------------------------
//
// *** AUTO GENERATED CODE *** Type: MMv1 ***
//
// ----------------------------------------------------------------------------
//
// This file is automatically generated by Magic Modules and manual
// changes will be clobbered when the file is regenerated.
//
// Please read more about how to change this file in
// .github/CONTRIBUTING.md.
//
// ----------------------------------------------------------------------------
package datastream_test
import (
"fmt"
"strings"
"testing"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
"github.com/hashicorp/terraform-provider-google-beta/google-beta/acctest"
"github.com/hashicorp/terraform-provider-google-beta/google-beta/tpgresource"
transport_tpg "github.com/hashicorp/terraform-provider-google-beta/google-beta/transport"
)
func TestAccDatastreamPrivateConnection_datastreamPrivateConnectionFullExample(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: testAccCheckDatastreamPrivateConnectionDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccDatastreamPrivateConnection_datastreamPrivateConnectionFullExample(context),
},
{
ResourceName: "google_datastream_private_connection.default",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"private_connection_id", "location", "labels", "terraform_labels"},
},
},
})
}
func testAccDatastreamPrivateConnection_datastreamPrivateConnectionFullExample(context map[string]interface{}) string {
return acctest.Nprintf(`
resource "google_datastream_private_connection" "default" {
display_name = "Connection profile"
location = "us-central1"
private_connection_id = "tf-test-my-connection%{random_suffix}"
labels = {
key = "value"
}
vpc_peering_config {
vpc = google_compute_network.default.id
subnet = "10.0.0.0/29"
}
}
resource "google_compute_network" "default" {
name = "tf-test-my-network%{random_suffix}"
}
`, context)
}
func testAccCheckDatastreamPrivateConnectionDestroyProducer(t *testing.T) func(s *terraform.State) error {
return func(s *terraform.State) error {
for name, rs := range s.RootModule().Resources {
if rs.Type != "google_datastream_private_connection" {
continue
}
if strings.HasPrefix(name, "data.") {
continue
}
config := acctest.GoogleProviderConfig(t)
url, err := tpgresource.ReplaceVarsForTest(config, rs, "{{DatastreamBasePath}}projects/{{project}}/locations/{{location}}/privateConnections/{{private_connection_id}}")
if err != nil {
return err
}
billingProject := ""
if config.BillingProject != "" {
billingProject = config.BillingProject
}
_, err = transport_tpg.SendRequest(transport_tpg.SendRequestOptions{
Config: config,
Method: "GET",
Project: billingProject,
RawURL: url,
UserAgent: config.UserAgent,
})
if err == nil {
return fmt.Errorf("DatastreamPrivateConnection still exists at %s", url)
}
}
return nil
}
}