|
| 1 | +// Copyright (c) HashiCorp, Inc. |
| 2 | +// SPDX-License-Identifier: MPL-2.0 |
| 3 | + |
| 4 | +// ---------------------------------------------------------------------------- |
| 5 | +// |
| 6 | +// *** AUTO GENERATED CODE *** Type: MMv1 *** |
| 7 | +// |
| 8 | +// ---------------------------------------------------------------------------- |
| 9 | +// |
| 10 | +// This file is automatically generated by Magic Modules and manual |
| 11 | +// changes will be clobbered when the file is regenerated. |
| 12 | +// |
| 13 | +// Please read more about how to change this file in |
| 14 | +// .github/CONTRIBUTING.md. |
| 15 | +// |
| 16 | +// ---------------------------------------------------------------------------- |
| 17 | + |
| 18 | +package google |
| 19 | + |
| 20 | +import ( |
| 21 | + "fmt" |
| 22 | + "strings" |
| 23 | + "testing" |
| 24 | + |
| 25 | + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" |
| 26 | + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" |
| 27 | + |
| 28 | + "github.com/hashicorp/terraform-provider-google/google/acctest" |
| 29 | + "github.com/hashicorp/terraform-provider-google/google/tpgresource" |
| 30 | + transport_tpg "github.com/hashicorp/terraform-provider-google/google/transport" |
| 31 | +) |
| 32 | + |
| 33 | +func TestAccNetworkConnectivityServiceConnectionPolicy_networkConnectivityPolicyBasicExample(t *testing.T) { |
| 34 | + t.Parallel() |
| 35 | + |
| 36 | + context := map[string]interface{}{ |
| 37 | + "service_class_name": "gcp-memorystore-redis", |
| 38 | + "random_suffix": acctest.RandString(t, 10), |
| 39 | + } |
| 40 | + |
| 41 | + acctest.VcrTest(t, resource.TestCase{ |
| 42 | + PreCheck: func() { acctest.AccTestPreCheck(t) }, |
| 43 | + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t), |
| 44 | + CheckDestroy: testAccCheckNetworkConnectivityServiceConnectionPolicyDestroyProducer(t), |
| 45 | + Steps: []resource.TestStep{ |
| 46 | + { |
| 47 | + Config: testAccNetworkConnectivityServiceConnectionPolicy_networkConnectivityPolicyBasicExample(context), |
| 48 | + }, |
| 49 | + { |
| 50 | + ResourceName: "google_network_connectivity_service_connection_policy.default", |
| 51 | + ImportState: true, |
| 52 | + ImportStateVerify: true, |
| 53 | + ImportStateVerifyIgnore: []string{"name", "location"}, |
| 54 | + }, |
| 55 | + }, |
| 56 | + }) |
| 57 | +} |
| 58 | + |
| 59 | +func testAccNetworkConnectivityServiceConnectionPolicy_networkConnectivityPolicyBasicExample(context map[string]interface{}) string { |
| 60 | + return acctest.Nprintf(` |
| 61 | +resource "google_compute_network" "producer_net" { |
| 62 | + name = "tf-test-producer-net%{random_suffix}" |
| 63 | + auto_create_subnetworks = false |
| 64 | +} |
| 65 | +
|
| 66 | +resource "google_compute_subnetwork" "producer_subnet" { |
| 67 | + name = "tf-test-producer-subnet%{random_suffix}" |
| 68 | + ip_cidr_range = "10.0.0.0/16" |
| 69 | + region = "us-central1" |
| 70 | + network = google_compute_network.producer_net.id |
| 71 | +} |
| 72 | +
|
| 73 | +resource "google_network_connectivity_service_connection_policy" "default" { |
| 74 | + name = "tf-test-my-network-connectivity-policy%{random_suffix}" |
| 75 | + location = "us-central1" |
| 76 | + service_class = "%{service_class_name}" |
| 77 | + description = "my basic service connection policy" |
| 78 | + network = google_compute_network.producer_net.id |
| 79 | + psc_config { |
| 80 | + subnetworks = [google_compute_subnetwork.producer_subnet.id] |
| 81 | + limit = 2 |
| 82 | + } |
| 83 | +} |
| 84 | +`, context) |
| 85 | +} |
| 86 | + |
| 87 | +func testAccCheckNetworkConnectivityServiceConnectionPolicyDestroyProducer(t *testing.T) func(s *terraform.State) error { |
| 88 | + return func(s *terraform.State) error { |
| 89 | + for name, rs := range s.RootModule().Resources { |
| 90 | + if rs.Type != "google_network_connectivity_service_connection_policy" { |
| 91 | + continue |
| 92 | + } |
| 93 | + if strings.HasPrefix(name, "data.") { |
| 94 | + continue |
| 95 | + } |
| 96 | + |
| 97 | + config := acctest.GoogleProviderConfig(t) |
| 98 | + |
| 99 | + url, err := tpgresource.ReplaceVarsForTest(config, rs, "{{NetworkConnectivityBasePath}}projects/{{project}}/locations/{{location}}/serviceConnectionPolicies/{{name}}") |
| 100 | + if err != nil { |
| 101 | + return err |
| 102 | + } |
| 103 | + |
| 104 | + billingProject := "" |
| 105 | + |
| 106 | + if config.BillingProject != "" { |
| 107 | + billingProject = config.BillingProject |
| 108 | + } |
| 109 | + |
| 110 | + _, err = transport_tpg.SendRequest(transport_tpg.SendRequestOptions{ |
| 111 | + Config: config, |
| 112 | + Method: "GET", |
| 113 | + Project: billingProject, |
| 114 | + RawURL: url, |
| 115 | + UserAgent: config.UserAgent, |
| 116 | + }) |
| 117 | + if err == nil { |
| 118 | + return fmt.Errorf("NetworkConnectivityServiceConnectionPolicy still exists at %s", url) |
| 119 | + } |
| 120 | + } |
| 121 | + |
| 122 | + return nil |
| 123 | + } |
| 124 | +} |
0 commit comments