| // 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 vmwareengine_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/envvar" |
| "github.com/hashicorp/terraform-provider-google-beta/google-beta/tpgresource" |
| transport_tpg "github.com/hashicorp/terraform-provider-google-beta/google-beta/transport" |
| ) |
| |
| func TestAccVmwareengineNetworkPolicy_vmwareEngineNetworkPolicyBasicExample(t *testing.T) { |
| t.Parallel() |
| |
| context := map[string]interface{}{ |
| "region": envvar.GetTestRegionFromEnv(), |
| "random_suffix": acctest.RandString(t, 10), |
| } |
| |
| acctest.VcrTest(t, resource.TestCase{ |
| PreCheck: func() { acctest.AccTestPreCheck(t) }, |
| ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t), |
| CheckDestroy: testAccCheckVmwareengineNetworkPolicyDestroyProducer(t), |
| Steps: []resource.TestStep{ |
| { |
| Config: testAccVmwareengineNetworkPolicy_vmwareEngineNetworkPolicyBasicExample(context), |
| }, |
| { |
| ResourceName: "google_vmwareengine_network_policy.vmw-engine-network-policy", |
| ImportState: true, |
| ImportStateVerify: true, |
| ImportStateVerifyIgnore: []string{"location", "name"}, |
| }, |
| }, |
| }) |
| } |
| |
| func testAccVmwareengineNetworkPolicy_vmwareEngineNetworkPolicyBasicExample(context map[string]interface{}) string { |
| return acctest.Nprintf(` |
| resource "google_vmwareengine_network" "network-policy-nw" { |
| name = "standard-nw" |
| location = "global" |
| type = "STANDARD" |
| description = "VMwareEngine standard network sample" |
| } |
| |
| resource "google_vmwareengine_network_policy" "vmw-engine-network-policy" { |
| location = "%{region}" |
| name = "tf-test-sample-network-policy%{random_suffix}" |
| edge_services_cidr = "192.168.30.0/26" |
| vmware_engine_network = google_vmwareengine_network.network-policy-nw.id |
| } |
| `, context) |
| } |
| |
| func TestAccVmwareengineNetworkPolicy_vmwareEngineNetworkPolicyFullExample(t *testing.T) { |
| t.Parallel() |
| |
| context := map[string]interface{}{ |
| "region": envvar.GetTestRegionFromEnv(), |
| "random_suffix": acctest.RandString(t, 10), |
| } |
| |
| acctest.VcrTest(t, resource.TestCase{ |
| PreCheck: func() { acctest.AccTestPreCheck(t) }, |
| ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t), |
| CheckDestroy: testAccCheckVmwareengineNetworkPolicyDestroyProducer(t), |
| Steps: []resource.TestStep{ |
| { |
| Config: testAccVmwareengineNetworkPolicy_vmwareEngineNetworkPolicyFullExample(context), |
| }, |
| { |
| ResourceName: "google_vmwareengine_network_policy.vmw-engine-network-policy", |
| ImportState: true, |
| ImportStateVerify: true, |
| ImportStateVerifyIgnore: []string{"location", "name"}, |
| }, |
| }, |
| }) |
| } |
| |
| func testAccVmwareengineNetworkPolicy_vmwareEngineNetworkPolicyFullExample(context map[string]interface{}) string { |
| return acctest.Nprintf(` |
| resource "google_vmwareengine_network" "network-policy-nw" { |
| name = "standard-full-nw" |
| location = "global" |
| type = "STANDARD" |
| description = "VMwareEngine standard network sample" |
| } |
| |
| resource "google_vmwareengine_network_policy" "vmw-engine-network-policy" { |
| location = "%{region}" |
| name = "tf-test-sample-network-policy-full%{random_suffix}" |
| edge_services_cidr = "192.168.30.0/26" |
| vmware_engine_network = google_vmwareengine_network.network-policy-nw.id |
| description = "Sample Network Policy" |
| internet_access { |
| enabled = true |
| } |
| external_ip { |
| enabled = true |
| } |
| } |
| `, context) |
| } |
| |
| func testAccCheckVmwareengineNetworkPolicyDestroyProducer(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_vmwareengine_network_policy" { |
| continue |
| } |
| if strings.HasPrefix(name, "data.") { |
| continue |
| } |
| |
| config := acctest.GoogleProviderConfig(t) |
| |
| url, err := tpgresource.ReplaceVarsForTest(config, rs, "{{VmwareengineBasePath}}projects/{{project}}/locations/{{location}}/networkPolicies/{{name}}") |
| 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("VmwareengineNetworkPolicy still exists at %s", url) |
| } |
| } |
| |
| return nil |
| } |
| } |