|
| 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 parallelstore_test |
| 19 | + |
| 20 | +import ( |
| 21 | + "fmt" |
| 22 | + "strings" |
| 23 | + "testing" |
| 24 | + |
| 25 | + "github.com/hashicorp/terraform-plugin-testing/helper/resource" |
| 26 | + "github.com/hashicorp/terraform-plugin-testing/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 TestAccParallelstoreInstance_parallelstoreInstanceBasicExample(t *testing.T) { |
| 34 | + t.Parallel() |
| 35 | + |
| 36 | + context := map[string]interface{}{ |
| 37 | + "random_suffix": acctest.RandString(t, 10), |
| 38 | + } |
| 39 | + |
| 40 | + acctest.VcrTest(t, resource.TestCase{ |
| 41 | + PreCheck: func() { acctest.AccTestPreCheck(t) }, |
| 42 | + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t), |
| 43 | + CheckDestroy: testAccCheckParallelstoreInstanceDestroyProducer(t), |
| 44 | + Steps: []resource.TestStep{ |
| 45 | + { |
| 46 | + Config: testAccParallelstoreInstance_parallelstoreInstanceBasicExample(context), |
| 47 | + }, |
| 48 | + { |
| 49 | + ResourceName: "google_parallelstore_instance.instance", |
| 50 | + ImportState: true, |
| 51 | + ImportStateVerify: true, |
| 52 | + ImportStateVerifyIgnore: []string{"instance_id", "labels", "location", "terraform_labels"}, |
| 53 | + }, |
| 54 | + }, |
| 55 | + }) |
| 56 | +} |
| 57 | + |
| 58 | +func testAccParallelstoreInstance_parallelstoreInstanceBasicExample(context map[string]interface{}) string { |
| 59 | + return acctest.Nprintf(` |
| 60 | +resource "google_parallelstore_instance" "instance" { |
| 61 | + instance_id = "instance%{random_suffix}" |
| 62 | + location = "us-central1-a" |
| 63 | + description = "test instance" |
| 64 | + capacity_gib = 12000 |
| 65 | + network = google_compute_network.network.name |
| 66 | + file_stripe_level = "FILE_STRIPE_LEVEL_MIN" |
| 67 | + directory_stripe_level = "DIRECTORY_STRIPE_LEVEL_MIN" |
| 68 | + labels = { |
| 69 | + test = "value" |
| 70 | + } |
| 71 | + depends_on = [google_service_networking_connection.default] |
| 72 | +} |
| 73 | +
|
| 74 | +resource "google_compute_network" "network" { |
| 75 | + name = "network%{random_suffix}" |
| 76 | + auto_create_subnetworks = true |
| 77 | + mtu = 8896 |
| 78 | +} |
| 79 | +
|
| 80 | +# Create an IP address |
| 81 | +resource "google_compute_global_address" "private_ip_alloc" { |
| 82 | + name = "address%{random_suffix}" |
| 83 | + purpose = "VPC_PEERING" |
| 84 | + address_type = "INTERNAL" |
| 85 | + prefix_length = 24 |
| 86 | + network = google_compute_network.network.id |
| 87 | +} |
| 88 | +
|
| 89 | +# Create a private connection |
| 90 | +resource "google_service_networking_connection" "default" { |
| 91 | + network = google_compute_network.network.id |
| 92 | + service = "servicenetworking.googleapis.com" |
| 93 | + reserved_peering_ranges = [google_compute_global_address.private_ip_alloc.name] |
| 94 | +} |
| 95 | +`, context) |
| 96 | +} |
| 97 | + |
| 98 | +func testAccCheckParallelstoreInstanceDestroyProducer(t *testing.T) func(s *terraform.State) error { |
| 99 | + return func(s *terraform.State) error { |
| 100 | + for name, rs := range s.RootModule().Resources { |
| 101 | + if rs.Type != "google_parallelstore_instance" { |
| 102 | + continue |
| 103 | + } |
| 104 | + if strings.HasPrefix(name, "data.") { |
| 105 | + continue |
| 106 | + } |
| 107 | + |
| 108 | + config := acctest.GoogleProviderConfig(t) |
| 109 | + |
| 110 | + url, err := tpgresource.ReplaceVarsForTest(config, rs, "{{ParallelstoreBasePath}}projects/{{project}}/locations/{{location}}/instances/{{instance_id}}") |
| 111 | + if err != nil { |
| 112 | + return err |
| 113 | + } |
| 114 | + |
| 115 | + billingProject := "" |
| 116 | + |
| 117 | + if config.BillingProject != "" { |
| 118 | + billingProject = config.BillingProject |
| 119 | + } |
| 120 | + |
| 121 | + _, err = transport_tpg.SendRequest(transport_tpg.SendRequestOptions{ |
| 122 | + Config: config, |
| 123 | + Method: "GET", |
| 124 | + Project: billingProject, |
| 125 | + RawURL: url, |
| 126 | + UserAgent: config.UserAgent, |
| 127 | + }) |
| 128 | + if err == nil { |
| 129 | + return fmt.Errorf("ParallelstoreInstance still exists at %s", url) |
| 130 | + } |
| 131 | + } |
| 132 | + |
| 133 | + return nil |
| 134 | + } |
| 135 | +} |
0 commit comments