Skip to content

Commit

Permalink
Update Vmware Engine acceptance tests to provision resources in a new…
Browse files Browse the repository at this point in the history
… project (#9835) (#6912)

* Update `TestAccDataSourceVmwareEngineNetwork_basic` to provision resources in a new project

* Add depends_on to try and improve delete order

* Add explicit vmware engine permissions in project, remove redundant depends_on

* Add some sleeps to check IAM permission propagation

* Add missing `ExternalProviders` config on acc test

* Remove redundant IAM binding, re-organise dependencies

* Remove unused context entry `terraform_service_account`

* Update `TestAccDataSourceVmwareengineNetworkPeering_basic` to provision resources in a new project

* Simplify dependencies in acceptance tests

* Update `TestAccDataSourceVmwareengineNetworkPolicy_basic` to provision resources in a new project

* Update `TestAccVmwareengineCluster_vmwareEngineClusterUpdate` to provision resources in a new project

* Update `TestAccVmwareengineExternalAddress_vmwareEngineExternalAddressUpdate` to provision resources in a new project

* Make whitespace consistent in affected acceptance tests

* Add missing comma

* Update remaining VMware Engine acceptance tests to use temporary projects

* Remove duplicate ExternalProviders

* Fix problem when referencing `google_project` resource

* Fix problem when referencing `google_project` resource

* Add missing `project` argument in `TestAccVmwareengineNetworkPolicy_update`

* Add missing `project` argument in `TestAccVmwareengineNetworkPeering_update`

* Add missing `project` argument in acceptance test resources

* Add missing `project` argument in acceptance test resources

* Add missing `project` argument in acceptance test resources

* Update second config of test to use external project

* Revert changes to TestAccVmwareengineSubnet_vmwareEngineUserDefinedSubnetUpdate

* Revert changes to TestAccVmwareengineExternalAccessRule_vmwareEngineExternalAccessRuleUpdate

[upstream:be616c72db6f3b6fa45762be6b25d6b473ef1333]

Signed-off-by: Modular Magician <[email protected]>
  • Loading branch information
modular-magician authored Jan 30, 2024
1 parent 276e291 commit 464a96e
Show file tree
Hide file tree
Showing 11 changed files with 355 additions and 96 deletions.
3 changes: 3 additions & 0 deletions .changelog/9835.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:none

```
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,25 @@ import (

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

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

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

acctest.VcrTest(t, resource.TestCase{
PreCheck: func() { acctest.AccTestPreCheck(t) },
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
CheckDestroy: testAccCheckVmwareengineNetworkPeeringDestroyProducer(t),
ExternalProviders: map[string]resource.ExternalProvider{
"time": {},
},
CheckDestroy: testAccCheckVmwareengineNetworkPeeringDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccVmwareengineNetworkPeering_ds(context),
Expand All @@ -33,31 +39,63 @@ func TestAccDataSourceVmwareengineNetworkPeering_basic(t *testing.T) {

func testAccVmwareengineNetworkPeering_ds(context map[string]interface{}) string {
return acctest.Nprintf(`
resource "google_project" "project" {
project_id = "tf-test%{random_suffix}"
name = "tf-test%{random_suffix}"
org_id = "%{org_id}"
billing_account = "%{billing_account}"
}
resource "google_project_service" "vmwareengine" {
project = google_project.project.project_id
service = "vmwareengine.googleapis.com"
}
resource "time_sleep" "sleep" {
create_duration = "1m"
depends_on = [
google_project_service.vmwareengine,
]
}
resource "google_vmwareengine_network" "network-peering-nw" {
name = "tf-test-sample-nw%{random_suffix}"
location = "global"
type = "STANDARD"
project = google_project.project.project_id
name = "tf-test-sample-nw%{random_suffix}"
location = "global"
type = "STANDARD"
depends_on = [
time_sleep.sleep # Sleep allows permissions in the new project to propagate
]
}
resource "google_vmwareengine_network" "network-peering-peer-nw" {
name = "tf-test-peer-nw%{random_suffix}"
location = "global"
type = "STANDARD"
project = google_project.project.project_id
name = "tf-test-peer-nw%{random_suffix}"
location = "global"
type = "STANDARD"
depends_on = [
time_sleep.sleep # Sleep allows permissions in the new project to propagate
]
}
resource "google_vmwareengine_network_peering" "vmw-engine-network-peering" {
name = "tf-test-sample-network-peering%{random_suffix}"
description = "Sample description"
vmware_engine_network = google_vmwareengine_network.network-peering-nw.id
peer_network = google_vmwareengine_network.network-peering-peer-nw.id
peer_network_type = "VMWARE_ENGINE_NETWORK"
project = google_project.project.project_id
name = "tf-test-sample-network-peering%{random_suffix}"
description = "Sample description"
vmware_engine_network = google_vmwareengine_network.network-peering-nw.id
peer_network = google_vmwareengine_network.network-peering-peer-nw.id
peer_network_type = "VMWARE_ENGINE_NETWORK"
depends_on = [
time_sleep.sleep # Sleep allows permissions in the new project to propagate
]
}
data "google_vmwareengine_network_peering" "ds" {
name = google_vmwareengine_network_peering.vmw-engine-network-peering.name
depends_on = [
google_vmwareengine_network_peering.vmw-engine-network-peering,
]
project = google_project.project.project_id
name = google_vmwareengine_network_peering.vmw-engine-network-peering.name
}
`, context)
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,19 @@ func TestAccDataSourceVmwareengineNetworkPolicy_basic(t *testing.T) {
t.Parallel()

context := map[string]interface{}{
"region": envvar.GetTestRegionFromEnv(),
"random_suffix": acctest.RandString(t, 10),
"region": envvar.GetTestRegionFromEnv(),
"random_suffix": acctest.RandString(t, 10),
"org_id": envvar.GetTestOrgFromEnv(t),
"billing_account": envvar.GetTestBillingAccountFromEnv(t),
}

acctest.VcrTest(t, resource.TestCase{
PreCheck: func() { acctest.AccTestPreCheck(t) },
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
CheckDestroy: testAccCheckVmwareengineNetworkPolicyDestroyProducer(t),
ExternalProviders: map[string]resource.ExternalProvider{
"time": {},
},
CheckDestroy: testAccCheckVmwareengineNetworkPolicyDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccVmwareengineNetworkPolicy_ds(context),
Expand All @@ -35,27 +40,57 @@ func TestAccDataSourceVmwareengineNetworkPolicy_basic(t *testing.T) {

func testAccVmwareengineNetworkPolicy_ds(context map[string]interface{}) string {
return acctest.Nprintf(`
resource "google_project" "project" {
project_id = "tf-test%{random_suffix}"
name = "tf-test%{random_suffix}"
org_id = "%{org_id}"
billing_account = "%{billing_account}"
}
resource "google_project_service" "vmwareengine" {
project = google_project.project.project_id
service = "vmwareengine.googleapis.com"
}
resource "time_sleep" "sleep" {
create_duration = "1m"
depends_on = [
google_project_service.vmwareengine,
]
}
resource "google_vmwareengine_network" "network-policy-ds-nw" {
name = "tf-test-sample-nw%{random_suffix}"
location = "global"
type = "STANDARD"
description = "VMwareEngine standard network sample"
project = google_project.project.project_id
name = "tf-test-sample-nw%{random_suffix}"
location = "global"
type = "STANDARD"
description = "VMwareEngine standard network sample"
depends_on = [
time_sleep.sleep # Sleep allows permissions in the new project to propagate
]
}
resource "google_vmwareengine_network_policy" "vmw-engine-network-policy" {
location = "%{region}"
name = "tf-test-sample-network-policy%{random_suffix}"
internet_access {
enabled = true
}
external_ip {
enabled = true
}
edge_services_cidr = "192.168.30.0/26"
vmware_engine_network = google_vmwareengine_network.network-policy-ds-nw.id
project = google_project.project.project_id
location = "%{region}"
name = "tf-test-sample-network-policy%{random_suffix}"
internet_access {
enabled = true
}
external_ip {
enabled = true
}
edge_services_cidr = "192.168.30.0/26"
vmware_engine_network = google_vmwareengine_network.network-policy-ds-nw.id
depends_on = [
time_sleep.sleep # Sleep allows permissions in the new project to propagate
]
}
data "google_vmwareengine_network_policy" "ds" {
project = google_project.project.project_id
name = google_vmwareengine_network_policy.vmw-engine-network-policy.name
location = "%{region}"
depends_on = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,25 @@ import (

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

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

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

acctest.VcrTest(t, resource.TestCase{
PreCheck: func() { acctest.AccTestPreCheck(t) },
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
CheckDestroy: testAccCheckVmwareengineNetworkDestroyProducer(t),
ExternalProviders: map[string]resource.ExternalProvider{
"time": {},
},
CheckDestroy: testAccCheckVmwareengineNetworkDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccDataSourceVmwareEngineNetworkConfig(context),
Expand All @@ -33,19 +39,42 @@ func TestAccDataSourceVmwareEngineNetwork_basic(t *testing.T) {

func testAccDataSourceVmwareEngineNetworkConfig(context map[string]interface{}) string {
return acctest.Nprintf(`
resource "google_project" "project" {
project_id = "tf-test%{random_suffix}"
name = "tf-test%{random_suffix}"
org_id = "%{org_id}"
billing_account = "%{billing_account}"
}
resource "google_project_service" "vmwareengine" {
project = google_project.project.project_id
service = "vmwareengine.googleapis.com"
}
resource "time_sleep" "sleep" {
create_duration = "1m"
depends_on = [
google_project_service.vmwareengine,
]
}
resource "google_vmwareengine_network" "nw" {
name = "tf-test-sample-network%{random_suffix}"
location = "global" # Standard network needs to be global
type = "STANDARD"
description = "VMwareEngine standard network sample"
project = google_project.project.project_id
name = "tf-test-sample-network%{random_suffix}"
location = "global" # Standard network needs to be global
type = "STANDARD"
description = "VMwareEngine standard network sample"
depends_on = [
time_sleep.sleep # Sleep allows permissions in the new project to propagate
]
}
data "google_vmwareengine_network" "ds" {
name = google_vmwareengine_network.nw.name
project = google_project.project.project_id
location = "global"
depends_on = [
google_vmwareengine_network.nw,
]
}
`, context)
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,18 @@ func TestAccVmwareengineCluster_vmwareEngineClusterUpdate(t *testing.T) {

context := map[string]interface{}{
"region": "southamerica-west1", // using region with low node utilization.
"random_suffix": acctest.RandString(t, 10),
"org_id": envvar.GetTestOrgFromEnv(t),
"billing_account": envvar.GetTestBillingAccountFromEnv(t),
"random_suffix": acctest.RandString(t, 10),
}

acctest.VcrTest(t, resource.TestCase{
PreCheck: func() { acctest.AccTestPreCheck(t) },
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
CheckDestroy: testAccCheckVmwareengineClusterDestroyProducer(t),
ExternalProviders: map[string]resource.ExternalProvider{
"time": {},
},
CheckDestroy: testAccCheckVmwareengineClusterDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testVmwareEngineClusterConfig(context, 3),
Expand Down Expand Up @@ -69,15 +72,39 @@ func TestAccVmwareengineCluster_vmwareEngineClusterUpdate(t *testing.T) {
func testVmwareEngineClusterConfig(context map[string]interface{}, nodeCount int) string {
context["node_count"] = nodeCount
return acctest.Nprintf(`
resource "google_project" "project" {
project_id = "tf-test%{random_suffix}"
name = "tf-test%{random_suffix}"
org_id = "%{org_id}"
billing_account = "%{billing_account}"
}
resource "google_project_service" "vmwareengine" {
project = google_project.project.project_id
service = "vmwareengine.googleapis.com"
}
resource "time_sleep" "sleep" {
create_duration = "1m"
depends_on = [
google_project_service.vmwareengine,
]
}
resource "google_vmwareengine_network" "cluster-nw" {
project = google_project.project.project_id
name = "tf-test-cluster-nw%{random_suffix}"
location = "global"
type = "STANDARD"
description = "PC network description."
depends_on = [
time_sleep.sleep # Sleep allows permissions in the new project to propagate
]
}
resource "google_vmwareengine_private_cloud" "cluster-pc" {
project = google_project.project.project_id
location = "%{region}-a"
name = "tf-test-cluster-pc%{random_suffix}"
description = "Sample test PC."
Expand All @@ -101,16 +128,13 @@ resource "google_vmwareengine_cluster" "vmw-engine-ext-cluster" {
node_type_configs {
node_type_id = "standard-72"
node_count = %{node_count}
custom_core_count = 32
custom_core_count = 32
}
}
data "google_vmwareengine_cluster" ds {
name = "tf-test-ext-cluster%{random_suffix}"
data "google_vmwareengine_cluster" "ds" {
name = google_vmwareengine_cluster.vmw-engine-ext-cluster.name
parent = google_vmwareengine_private_cloud.cluster-pc.id
depends_on = [
google_vmwareengine_cluster.vmw-engine-ext-cluster,
]
}
`, context)
}
Expand Down
Loading

0 comments on commit 464a96e

Please sign in to comment.