Skip to content

Commit

Permalink
Retain vmware network legacy tests
Browse files Browse the repository at this point in the history
  • Loading branch information
swamitagupta committed Nov 21, 2023
1 parent 8e50f19 commit 82745ba
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 7 deletions.
11 changes: 11 additions & 0 deletions mmv1/products/vmwareengine/Network.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,17 @@ examples:
- !ruby/object:Provider::Terraform::Examples
name: "vmware_engine_network_standard"
primary_resource_id: "vmw-engine-network"
- !ruby/object:Provider::Terraform::Examples
name: "vmware_engine_network_legacy"
pull_external: true
primary_resource_id: "vmw-engine-network"
skip_test: true # update tests will take care of create and update. Legacy network needs to be created on an isolated project.
vars:
proj_id: "vmw-proj"
test_env_vars:
location: :REGION
org_id: :ORG_ID
billing_account: :BILLING_ACCT
parameters:
- !ruby/object:Api::Type::String
name: "location"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
resource "google_vmwareengine_network" "<%= ctx[:primary_resource_id] %>" {
provider = google-beta
project = google_project_service.acceptance.project
name = "<%= ctx[:test_env_vars]['location'] %>-default" #Legacy network IDs are in the format: {region-id}-default
location = "<%= ctx[:test_env_vars]['location'] %>"
type = "LEGACY"
description = "VMwareEngine legacy network sample"
}

resource "google_project_service" "acceptance" {
project = google_project.acceptance.project_id
provider = google-beta
service = "vmwareengine.googleapis.com"

# Needed for CI tests for permissions to propagate, should not be needed for actual usage
depends_on = [time_sleep.wait_60_seconds]
}

# there can be only 1 Legacy network per region for a given project,
# so creating new project for isolation in CI.
resource "google_project" "acceptance" {
name = "<%= ctx[:vars]['proj_id'] %>"
provider = google-beta
project_id = "<%= ctx[:vars]['proj_id'] %>"
org_id = "<%= ctx[:test_env_vars]['org_id'] %>"
billing_account = "<%= ctx[:test_env_vars]['billing_account'] %>"
}

resource "time_sleep" "wait_60_seconds" {
depends_on = [google_project.acceptance]

create_duration = "60s"
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
package vmwareengine

import (
"fmt"

Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
package vmwareengine_test

import (
"github.com/hashicorp/terraform-provider-google/google/acctest"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-provider-google/google/acctest"
)

func TestAccDataSourceVmwareEngineNetwork_basic(t *testing.T) {
t.Parallel()

context := map[string]interface{}{
"random_suffix": acctest.RandString(t, 10),
"random_suffix": acctest.RandString(t, 10),
}

acctest.VcrTest(t, resource.TestCase{
Expand Down Expand Up @@ -46,4 +46,4 @@ data "google_vmwareengine_network" "ds" {
]
}
`, context)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,18 @@ import (
"fmt"
"testing"

"github.com/hashicorp/terraform-provider-google/google/acctest"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-provider-google/google/acctest"
"github.com/hashicorp/terraform-provider-google/google/envvar"
)

func TestAccVmwareengineNetwork_vmwareEngineNetworkUpdate(t *testing.T) {
t.Parallel()
context := map[string]interface{}{
"region": envvar.GetTestRegionFromEnv(),
"random_suffix": acctest.RandString(t, 10),
"organization": envvar.GetTestOrgFromEnv(t),
"billing_account": envvar.GetTestBillingAccountFromEnv(t),
}

configTemplate := vmwareEngineNetworkConfigTemplate(context)
Expand All @@ -21,6 +25,7 @@ func TestAccVmwareengineNetwork_vmwareEngineNetworkUpdate(t *testing.T) {
CheckDestroy: testAccCheckVmwareengineNetworkDestroyProducer(t),
ExternalProviders: map[string]resource.ExternalProvider{
"random": {},
"time": {},
},
Steps: []resource.TestStep{
{
Expand Down Expand Up @@ -48,10 +53,35 @@ func TestAccVmwareengineNetwork_vmwareEngineNetworkUpdate(t *testing.T) {
func vmwareEngineNetworkConfigTemplate(context map[string]interface{}) string {
return acctest.Nprintf(`
resource "google_vmwareengine_network" "default-nw" {
name = "tf-test-network-%{random_suffix}"
location = "global"
type = "STANDARD"
project = google_project_service.acceptance.project
name = "%{region}-default"
location = "%{region}"
type = "LEGACY"
description = "%s"
}
# there can be only 1 Legacy network per region for a given project, so creating new project to isolate tests.
resource "google_project" "acceptance" {
name = "tf-test-%{random_suffix}"
provider = google-beta
project_id = "tf-test-%{random_suffix}"
org_id = "%{organization}"
billing_account = "%{billing_account}"
}
resource "google_project_service" "acceptance" {
project = google_project.acceptance.project_id
provider = google-beta
service = "vmwareengine.googleapis.com"
# Needed for CI tests for permissions to propagate, should not be needed for actual usage
depends_on = [time_sleep.wait_60_seconds]
}
resource "time_sleep" "wait_60_seconds" {
depends_on = [google_project.acceptance]
create_duration = "60s"
}
`, context)
}

0 comments on commit 82745ba

Please sign in to comment.