|
| 1 | +// ---------------------------------------------------------------------------- |
| 2 | +// |
| 3 | +// *** AUTO GENERATED CODE *** Type: MMv1 *** |
| 4 | +// |
| 5 | +// ---------------------------------------------------------------------------- |
| 6 | +// |
| 7 | +// This file is automatically generated by Magic Modules and manual |
| 8 | +// changes will be clobbered when the file is regenerated. |
| 9 | +// |
| 10 | +// Please read more about how to change this file in |
| 11 | +// .github/CONTRIBUTING.md. |
| 12 | +// |
| 13 | +// ---------------------------------------------------------------------------- |
| 14 | + |
| 15 | +package google |
| 16 | + |
| 17 | +import ( |
| 18 | + "fmt" |
| 19 | + "strings" |
| 20 | + "testing" |
| 21 | + |
| 22 | + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" |
| 23 | + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" |
| 24 | +) |
| 25 | + |
| 26 | +func TestAccVertexAIEndpoint_vertexAiEndpointNetwork(t *testing.T) { |
| 27 | + t.Parallel() |
| 28 | + |
| 29 | + context := map[string]interface{}{ |
| 30 | + "endpoint_name": fmt.Sprint(randInt(t) % 9999999999), |
| 31 | + "kms_key_name": BootstrapKMSKeyInLocation(t, "us-central1").CryptoKey.Name, |
| 32 | + "network_name": BootstrapSharedTestNetwork(t, "vertex"), |
| 33 | + "random_suffix": randString(t, 10), |
| 34 | + } |
| 35 | + |
| 36 | + vcrTest(t, resource.TestCase{ |
| 37 | + PreCheck: func() { testAccPreCheck(t) }, |
| 38 | + Providers: testAccProviders, |
| 39 | + CheckDestroy: testAccCheckVertexAIEndpointDestroyProducer(t), |
| 40 | + Steps: []resource.TestStep{ |
| 41 | + { |
| 42 | + Config: testAccVertexAIEndpoint_vertexAiEndpointNetwork(context), |
| 43 | + }, |
| 44 | + { |
| 45 | + ResourceName: "google_vertex_ai_endpoint.endpoint", |
| 46 | + ImportState: true, |
| 47 | + ImportStateVerify: true, |
| 48 | + ImportStateVerifyIgnore: []string{"etag", "location"}, |
| 49 | + }, |
| 50 | + { |
| 51 | + Config: testAccVertexAIEndpoint_vertexAiEndpointNetworkUpdate(context), |
| 52 | + }, |
| 53 | + { |
| 54 | + ResourceName: "google_vertex_ai_endpoint.endpoint", |
| 55 | + ImportState: true, |
| 56 | + ImportStateVerify: true, |
| 57 | + ImportStateVerifyIgnore: []string{"etag", "location"}, |
| 58 | + }, |
| 59 | + }, |
| 60 | + }) |
| 61 | +} |
| 62 | + |
| 63 | +func testAccVertexAIEndpoint_vertexAiEndpointNetwork(context map[string]interface{}) string { |
| 64 | + return Nprintf(` |
| 65 | +resource "google_vertex_ai_endpoint" "endpoint" { |
| 66 | + name = "%{endpoint_name}" |
| 67 | + display_name = "sample-endpoint" |
| 68 | + description = "A sample vertex endpoint" |
| 69 | + location = "us-central1" |
| 70 | + labels = { |
| 71 | + label-one = "value-one" |
| 72 | + } |
| 73 | + network = "projects/${data.google_project.project.number}/global/networks/${data.google_compute_network.vertex_network.name}" |
| 74 | + encryption_spec { |
| 75 | + kms_key_name = "%{kms_key_name}" |
| 76 | + } |
| 77 | + depends_on = [ |
| 78 | + google_service_networking_connection.vertex_vpc_connection |
| 79 | + ] |
| 80 | +} |
| 81 | +
|
| 82 | +resource "google_service_networking_connection" "vertex_vpc_connection" { |
| 83 | + network = data.google_compute_network.vertex_network.id |
| 84 | + service = "servicenetworking.googleapis.com" |
| 85 | + reserved_peering_ranges = [google_compute_global_address.vertex_range.name] |
| 86 | +} |
| 87 | +
|
| 88 | +resource "google_compute_global_address" "vertex_range" { |
| 89 | + name = "tf-test-address-name%{random_suffix}" |
| 90 | + purpose = "VPC_PEERING" |
| 91 | + address_type = "INTERNAL" |
| 92 | + prefix_length = 24 |
| 93 | + network = data.google_compute_network.vertex_network.id |
| 94 | +} |
| 95 | +
|
| 96 | +data "google_compute_network" "vertex_network" { |
| 97 | + name = "%{network_name}" |
| 98 | +} |
| 99 | +
|
| 100 | +resource "google_kms_crypto_key_iam_member" "crypto_key" { |
| 101 | + crypto_key_id = "%{kms_key_name}" |
| 102 | + role = "roles/cloudkms.cryptoKeyEncrypterDecrypter" |
| 103 | + member = "serviceAccount:service-${data.google_project.project.number}@gcp-sa-aiplatform.iam.gserviceaccount.com" |
| 104 | +} |
| 105 | +
|
| 106 | +data "google_project" "project" {} |
| 107 | +`, context) |
| 108 | +} |
| 109 | + |
| 110 | +func testAccVertexAIEndpoint_vertexAiEndpointNetworkUpdate(context map[string]interface{}) string { |
| 111 | + return Nprintf(` |
| 112 | +resource "google_vertex_ai_endpoint" "endpoint" { |
| 113 | + name = "%{endpoint_name}" |
| 114 | + display_name = "new-sample-endpoint" |
| 115 | + description = "An updated sample vertex endpoint" |
| 116 | + location = "us-central1" |
| 117 | + labels = { |
| 118 | + label-two = "value-two" |
| 119 | + } |
| 120 | + network = "projects/${data.google_project.project.number}/global/networks/${data.google_compute_network.vertex_network.name}" |
| 121 | + encryption_spec { |
| 122 | + kms_key_name = "%{kms_key_name}" |
| 123 | + } |
| 124 | + depends_on = [ |
| 125 | + google_service_networking_connection.vertex_vpc_connection |
| 126 | + ] |
| 127 | +} |
| 128 | +
|
| 129 | +resource "google_service_networking_connection" "vertex_vpc_connection" { |
| 130 | + network = data.google_compute_network.vertex_network.id |
| 131 | + service = "servicenetworking.googleapis.com" |
| 132 | + reserved_peering_ranges = [google_compute_global_address.vertex_range.name] |
| 133 | +} |
| 134 | +
|
| 135 | +resource "google_compute_global_address" "vertex_range" { |
| 136 | + name = "tf-test-address-name%{random_suffix}" |
| 137 | + purpose = "VPC_PEERING" |
| 138 | + address_type = "INTERNAL" |
| 139 | + prefix_length = 24 |
| 140 | + network = data.google_compute_network.vertex_network.id |
| 141 | +} |
| 142 | +
|
| 143 | +data "google_compute_network" "vertex_network" { |
| 144 | + name = "%{network_name}" |
| 145 | +} |
| 146 | +
|
| 147 | +resource "google_kms_crypto_key_iam_member" "crypto_key" { |
| 148 | + crypto_key_id = "%{kms_key_name}" |
| 149 | + role = "roles/cloudkms.cryptoKeyEncrypterDecrypter" |
| 150 | + member = "serviceAccount:service-${data.google_project.project.number}@gcp-sa-aiplatform.iam.gserviceaccount.com" |
| 151 | +} |
| 152 | +
|
| 153 | +data "google_project" "project" {} |
| 154 | +`, context) |
| 155 | +} |
| 156 | + |
| 157 | +func testAccCheckVertexAIEndpointDestroyProducer(t *testing.T) func(s *terraform.State) error { |
| 158 | + return func(s *terraform.State) error { |
| 159 | + for name, rs := range s.RootModule().Resources { |
| 160 | + if rs.Type != "google_vertex_ai_endpoint" { |
| 161 | + continue |
| 162 | + } |
| 163 | + if strings.HasPrefix(name, "data.") { |
| 164 | + continue |
| 165 | + } |
| 166 | + |
| 167 | + config := googleProviderConfig(t) |
| 168 | + |
| 169 | + url, err := replaceVarsForTest(config, rs, "{{VertexAIBasePath}}projects/{{project}}/locations/{{location}}/endpoints/{{name}}") |
| 170 | + if err != nil { |
| 171 | + return err |
| 172 | + } |
| 173 | + |
| 174 | + billingProject := "" |
| 175 | + |
| 176 | + if config.BillingProject != "" { |
| 177 | + billingProject = config.BillingProject |
| 178 | + } |
| 179 | + |
| 180 | + _, err = sendRequest(config, "GET", billingProject, url, config.userAgent, nil) |
| 181 | + if err == nil { |
| 182 | + return fmt.Errorf("VertexAIEndpoint still exists at %s", url) |
| 183 | + } |
| 184 | + } |
| 185 | + |
| 186 | + return nil |
| 187 | + } |
| 188 | +} |
0 commit comments