From 82d7e3f8e6385db7a1056bb56764870f920756e9 Mon Sep 17 00:00:00 2001 From: Dainius Date: Tue, 2 Jul 2024 14:21:25 +0300 Subject: [PATCH] Test fixes (#1288) --- .changes/v3.13.0/1253-improvements.md | 5 +- go.mod | 2 +- go.sum | 4 +- scripts/skip-upgrade-tests.txt | 8 ++ vcd/datasource_not_found_test.go | 29 +++++++ vcd/metadata_common_test.go | 13 +-- vcd/org_vdc_common_test.go | 2 +- ...esource_vcd_cse_kubernetes_cluster_test.go | 1 + ..._vcd_nsxt_alb_system_prerequisites_test.go | 30 ++++--- ...resource_vcd_solution_landing_zone_test.go | 1 + vcd/resource_vcd_vapp_vm_copy_test.go | 4 +- vcd/resource_vcd_vapp_vm_extraconfig_test.go | 79 ++++++++++--------- website/docs/r/vapp_vm.html.markdown | 2 +- 13 files changed, 116 insertions(+), 64 deletions(-) diff --git a/.changes/v3.13.0/1253-improvements.md b/.changes/v3.13.0/1253-improvements.md index c28089682..b59fad5c8 100644 --- a/.changes/v3.13.0/1253-improvements.md +++ b/.changes/v3.13.0/1253-improvements.md @@ -1,3 +1,2 @@ -* Resources `vcd_vapp_vm` and `vcd_vm` add property `set_extra_config` to add, modify, or remove VM extra configuration items [GH-1253] -* Resources and data sources `vcd_vapp_vm` and `vcd_vm` add property `extra_config` to read existing VM extra configuration [GH-1253] - +* Resources `vcd_vapp_vm` and `vcd_vm` add property `set_extra_config` to add, modify, or remove VM extra configuration items [GH-1253, GH-1288] +* Resources and data sources `vcd_vapp_vm` and `vcd_vm` add property `extra_config` to read existing VM extra configuration [GH-1253, GH-1288] diff --git a/go.mod b/go.mod index 6341976ca..577cacf71 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,7 @@ require ( github.com/hashicorp/go-version v1.6.0 github.com/hashicorp/terraform-plugin-sdk/v2 v2.34.0 github.com/kr/pretty v0.3.1 - github.com/vmware/go-vcloud-director/v2 v2.25.0-alpha.17 + github.com/vmware/go-vcloud-director/v2 v2.25.0-alpha.18 ) require ( diff --git a/go.sum b/go.sum index fda7c9842..e19aa1ca5 100644 --- a/go.sum +++ b/go.sum @@ -150,8 +150,8 @@ github.com/vmihailenco/msgpack/v5 v5.4.1 h1:cQriyiUvjTwOHg8QZaPihLWeRAAVoCpE00IU github.com/vmihailenco/msgpack/v5 v5.4.1/go.mod h1:GaZTsDaehaPpQVyxrf5mtQlH+pc21PIudVV/E3rRQok= github.com/vmihailenco/tagparser/v2 v2.0.0 h1:y09buUbR+b5aycVFQs/g70pqKVZNBmxwAhO7/IwNM9g= github.com/vmihailenco/tagparser/v2 v2.0.0/go.mod h1:Wri+At7QHww0WTrCBeu4J6bNtoV6mEfg5OIWRZA9qds= -github.com/vmware/go-vcloud-director/v2 v2.25.0-alpha.17 h1:3ar5VSWFQ/YUOnljbGdKh06pt1fwpgT0PJKN26HNuD8= -github.com/vmware/go-vcloud-director/v2 v2.25.0-alpha.17/go.mod h1:7Of1qJja+LLNKVegjZG7uuhhy6xgGg3q7Fkw2CEP+Tw= +github.com/vmware/go-vcloud-director/v2 v2.25.0-alpha.18 h1:qau0h1MwVjuRXoApnwlxhLOEkonJtu+HFgtF4uFOBgg= +github.com/vmware/go-vcloud-director/v2 v2.25.0-alpha.18/go.mod h1:7Of1qJja+LLNKVegjZG7uuhhy6xgGg3q7Fkw2CEP+Tw= github.com/xanzy/ssh-agent v0.3.3 h1:+/15pJfg/RsTxqYcX6fHqOXZwwMP+2VyYWJeWM2qQFM= github.com/xanzy/ssh-agent v0.3.3/go.mod h1:6dzNDKs0J9rVPHPhaGCukekBHKqfl+L3KghI1Bc68Uw= github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= diff --git a/scripts/skip-upgrade-tests.txt b/scripts/skip-upgrade-tests.txt index ed8bfa158..f77fdacc0 100644 --- a/scripts/skip-upgrade-tests.txt +++ b/scripts/skip-upgrade-tests.txt @@ -341,3 +341,11 @@ vcd.ResourceSchema-vcd_vm.tf v3.11.0 "New field 'consolidate_disks_on_create'" vcd.ResourceSchema-vcd_catalog_vapp_template.tf v3.11.0 "New 'capture_vapp' block" vcd.ResourceSchema-vcd_vapp_vm.tf v3.11.0 "added field 'vapp_id'" vcd.ResourceSchema-vcd_vm.tf v3.11.0 "added field 'vapp_id'" +vcd.ResourceSchema-vcd_catalog_media.tf v3.12.1 "added field 'catalog_item_id'" +vcd.ResourceSchema-vcd_cse_kubernetes_cluster.tf v3.12.1 "Added sensitive fields" +vcd.ResourceSchema-vcd_external_network_v2.tf v3.12.1 "Added fields 'nat_and_firewall_service_intention', 'route_advertisement_intention'" +vcd.ResourceSchema-vcd_nsxt_edgegateway.tf v3.12.1 "Added field 'ip_count_read_limit'" +vcd.ResourceSchema-vcd_nsxt_firewall.tf v3.12.1 "Added support for 'REJECT' and updated description" +vcd.ResourceSchema-vcd_vapp.tf v3.12.1 "Added fields 'vm_names', 'vapp_org_network_names', 'vapp_network_names'" +vcd.ResourceSchema-vcd_vapp_vm.tf v3.12.1 "Added field 'extra_config'" +vcd.ResourceSchema-vcd_vm.tf v3.12.1 "Added field 'extra_config'" diff --git a/vcd/datasource_not_found_test.go b/vcd/datasource_not_found_test.go index faffecd79..02ad7a4dd 100644 --- a/vcd/datasource_not_found_test.go +++ b/vcd/datasource_not_found_test.go @@ -108,6 +108,30 @@ func testSpecificDataSourceNotFound(dataSourceName string, vcdClient *VCDClient) skipVersionConstraint: "< 37.0", datasourceName: "vcd_service_account", }, + { + skipVersionConstraint: "< 37.1", + datasourceName: "vcd_solution_landing_zone", + }, + { + skipVersionConstraint: "< 37.1", + datasourceName: "vcd_solution_add_on", + }, + { + skipVersionConstraint: "< 37.1", + datasourceName: "vcd_solution_add_on_instance", + }, + { + skipVersionConstraint: "< 37.1", + datasourceName: "vcd_solution_add_on_instance_publish", + }, + { + skipVersionConstraint: "< 37.1", + datasourceName: "vcd_dse_registry_configuration", + }, + { + skipVersionConstraint: "< 37.1", + datasourceName: "vcd_ip_space_custom_quota", + }, } // urn:vcloud:ipSpace:2ec12e23-6911-4950-a33f-5602ae72ced2 @@ -149,6 +173,11 @@ func testSpecificDataSourceNotFound(dataSourceName string, vcdClient *VCDClient) "vcd_multisite_site_association", "vcd_multisite_site_data", "vcd_multisite_site", + "vcd_dse_registry_configuration", + "vcd_solution_landing_zone", + "vcd_solution_add_on", + "vcd_solution_add_on_instance", + "vcd_solution_add_on_instance_publish", } dataSourcesRequiringAlbConfig := []string{ "vcd_nsxt_alb_cloud", diff --git a/vcd/metadata_common_test.go b/vcd/metadata_common_test.go index 194b697a8..f95e78976 100644 --- a/vcd/metadata_common_test.go +++ b/vcd/metadata_common_test.go @@ -1,20 +1,21 @@ -//go:build catalog || disk || network || nsxt || vdc || org || vapp || vm || providerVdc || functional || ALL +//go:build catalog || disk || network || nsxt || vdc || org || vapp || vm || providerVdc || standaloneVm || functional || ALL package vcd import ( "context" "fmt" - "github.com/hashicorp/terraform-plugin-sdk/v2/diag" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" - "github.com/vmware/go-vcloud-director/v2/types/v56" "os" "regexp" "strconv" "strings" "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" + "github.com/vmware/go-vcloud-director/v2/types/v56" ) // testMetadataEntryCRUD executes a test that asserts CRUD operation behaviours of "metadata_entry" attribute in the given HCL diff --git a/vcd/org_vdc_common_test.go b/vcd/org_vdc_common_test.go index 8a13f9016..910a38f3a 100644 --- a/vcd/org_vdc_common_test.go +++ b/vcd/org_vdc_common_test.go @@ -1,4 +1,4 @@ -//go:build vdc || nsxt || ALL || functional +//go:build vdc || nsxt || standaloneVm || vm || vapp || ALL || functional package vcd diff --git a/vcd/resource_vcd_cse_kubernetes_cluster_test.go b/vcd/resource_vcd_cse_kubernetes_cluster_test.go index 78ae72044..1f535b5e8 100644 --- a/vcd/resource_vcd_cse_kubernetes_cluster_test.go +++ b/vcd/resource_vcd_cse_kubernetes_cluster_test.go @@ -786,6 +786,7 @@ func TestAccVcdCseKubernetesClusterFailure(t *testing.T) { "ServicesCidr": "5.6.7.8/24", // This will make the cluster to fail "AutoRepairOnErrors": false, // This must be false "NodeHealthCheck": false, + "Autoscaler": " ", "Timeout": 150, } testParamsNotEmpty(t, params) diff --git a/vcd/resource_vcd_nsxt_alb_system_prerequisites_test.go b/vcd/resource_vcd_nsxt_alb_system_prerequisites_test.go index 7a21b2d8a..c3998e6e2 100644 --- a/vcd/resource_vcd_nsxt_alb_system_prerequisites_test.go +++ b/vcd/resource_vcd_nsxt_alb_system_prerequisites_test.go @@ -50,7 +50,8 @@ func (a *albOrgUserPrerequisites) setupAlbPoolPrerequisites() { albController, err := vcdClient.CreateNsxtAlbController(newControllerDef) if err != nil { - t.Logf("error creating NSX-T ALB Controller: %s", err) + t.Errorf("error creating NSX-T ALB Controller: %s", err) + return } a.albController = albController // Store in struct for teardown fmt.Println("Done.") @@ -59,7 +60,8 @@ func (a *albOrgUserPrerequisites) setupAlbPoolPrerequisites() { fmt.Printf("# Creating NSX-T ALB Cloud. ") importableCloud, err := albController.GetAlbImportableCloudByName(testConfig.Nsxt.NsxtAlbImportableCloud) if err != nil { - t.Logf("error retrieving NSX-T ALB Importable Cloud: %s", err) + t.Errorf("error retrieving NSX-T ALB Importable Cloud: %s", err) + return } albCloudConfig := &types.NsxtAlbCloud{ @@ -77,7 +79,8 @@ func (a *albOrgUserPrerequisites) setupAlbPoolPrerequisites() { createdAlbCloud, err := vcdClient.CreateAlbCloud(albCloudConfig) if err != nil { - t.Logf("error creating NSX-T ALB Cloud: %s", err) + t.Errorf("error creating NSX-T ALB Cloud: %s", err) + return } a.albCloud = createdAlbCloud // Store in struct for teardown fmt.Println("Done.") @@ -86,7 +89,8 @@ func (a *albOrgUserPrerequisites) setupAlbPoolPrerequisites() { fmt.Printf("# Creating NSX-T ALB Service Engine Group. ") importableSeGroups, err := vcdClient.GetAllAlbImportableServiceEngineGroups(createdAlbCloud.NsxtAlbCloud.ID, nil) if err != nil || len(importableSeGroups) < 1 { - t.Logf("error retrieving NSX-T ALB Importable Service Engine Groups: %s", err) + t.Errorf("error retrieving NSX-T ALB Importable Service Engine Groups: %s", err) + return } albSeGroup := &types.NsxtAlbServiceEngineGroup{ @@ -106,7 +110,8 @@ func (a *albOrgUserPrerequisites) setupAlbPoolPrerequisites() { createdSeGroup, err := vcdClient.CreateNsxtAlbServiceEngineGroup(albSeGroup) if err != nil { - t.Logf("error creating NSX-T ALB Service Engine Group: %s", err) + t.Errorf("error creating NSX-T ALB Service Engine Group: %s", err) + return } a.albSeGroup = createdSeGroup // Store in struct for teardown fmt.Println("Done.") @@ -118,17 +123,20 @@ func (a *albOrgUserPrerequisites) setupAlbPoolPrerequisites() { fmt.Printf("# Enabling ALB on Edge Gateway. ") adminOrg, err := vcdClient.GetAdminOrgByName(testConfig.VCD.Org) if err != nil { - t.Logf("error getting AdminOrg '%s': %s", testConfig.VCD.Org, err) + t.Errorf("error getting AdminOrg '%s': %s", testConfig.VCD.Org, err) + return } vdc, err := adminOrg.GetVDCByName(testConfig.Nsxt.Vdc, false) if err != nil { - t.Logf("error getting NSX-T VDC '%s': %s", testConfig.Nsxt.Vdc, err) + t.Errorf("error getting NSX-T VDC '%s': %s", testConfig.Nsxt.Vdc, err) + return } nsxtEdge, err := vdc.GetNsxtEdgeGatewayByName(testConfig.Nsxt.EdgeGateway) if err != nil { - t.Logf("error retrieving NSX-T Edge Gateway '%s': %s", testConfig.Nsxt.Vdc, err) + t.Errorf("error retrieving NSX-T Edge Gateway '%s': %s", testConfig.Nsxt.Vdc, err) + return } // Update ALB General Settings @@ -142,7 +150,8 @@ func (a *albOrgUserPrerequisites) setupAlbPoolPrerequisites() { _, err = nsxtEdge.UpdateAlbSettings(albSettingsConfig) if err != nil { - t.Logf("error enabling ALB on NSX-T Edge Gateway: %s", err) + t.Errorf("error enabling ALB on NSX-T Edge Gateway: %s", err) + return } a.nsxtGw = nsxtEdge // Store in struct for teardown fmt.Println("Done.") @@ -157,7 +166,8 @@ func (a *albOrgUserPrerequisites) setupAlbPoolPrerequisites() { } serviceEngineGroupAssignment, err := vcdClient.CreateAlbServiceEngineGroupAssignment(serviceEngineGroupAssignmentConfig) if err != nil { - t.Logf("error assigning Service Engine Group '%s' to NSX-T Edge Gateway: %s", createdSeGroup.NsxtAlbServiceEngineGroup.Name, err) + t.Errorf("error assigning Service Engine Group '%s' to NSX-T Edge Gateway: %s", createdSeGroup.NsxtAlbServiceEngineGroup.Name, err) + return } a.nsxtGwSeGroupAssignment = serviceEngineGroupAssignment // Store in struct for teardown fmt.Println("Done.") diff --git a/vcd/resource_vcd_solution_landing_zone_test.go b/vcd/resource_vcd_solution_landing_zone_test.go index 6b3d0a509..9144c6286 100644 --- a/vcd/resource_vcd_solution_landing_zone_test.go +++ b/vcd/resource_vcd_solution_landing_zone_test.go @@ -12,6 +12,7 @@ import ( func TestAccVcdSolutionLandingZone(t *testing.T) { preTestChecks(t) + skipIfNotSysAdmin(t) if checkVersion(testConfig.Provider.ApiVersion, "< 37.1") { t.Skipf("Solution Landing Zones are supported in VCD 10.4.1+. Skipping") } diff --git a/vcd/resource_vcd_vapp_vm_copy_test.go b/vcd/resource_vcd_vapp_vm_copy_test.go index 9fdc2f25a..ead2c48d0 100644 --- a/vcd/resource_vcd_vapp_vm_copy_test.go +++ b/vcd/resource_vcd_vapp_vm_copy_test.go @@ -380,12 +380,12 @@ resource "vcd_org_vdc" "sizing-policy" { compute_capacity { cpu { allocated = "0" - limit = "24000" + limit = "4000" } memory { allocated = "0" - limit = "24000" + limit = "2048" } } diff --git a/vcd/resource_vcd_vapp_vm_extraconfig_test.go b/vcd/resource_vcd_vapp_vm_extraconfig_test.go index 7d56913b3..13578ce1a 100644 --- a/vcd/resource_vcd_vapp_vm_extraconfig_test.go +++ b/vcd/resource_vcd_vapp_vm_extraconfig_test.go @@ -4,15 +4,17 @@ package vcd import ( "fmt" + "testing" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" "github.com/vmware/go-vcloud-director/v2/types/v56" - "testing" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" ) func TestAccVcdVAppVm_extraconfig(t *testing.T) { preTestChecks(t) + skipIfNotSysAdmin(t) initialValue := "value" updatedValue := "another value" @@ -173,45 +175,46 @@ func TestAccVcdVAppVm_extraconfig(t *testing.T) { resource.TestCheckResourceAttr("vcd_vm.empty-vm", "status_text", "POWERED_OFF"), testAccCheckVcdVMPowerState(testConfig.VCD.Org, testConfig.Nsxt.Vdc, "", t.Name()+"-empty-standalone-vm", "POWERED_OFF"), - // Check initial extra configuration items - resource.TestCheckTypeSetElemNestedAttrs("vcd_vapp_vm.template-vm", "extra_config.*", map[string]string{ - "key": "template-vapp-vm-1", - "value": initialValue + "1", - }), - resource.TestCheckTypeSetElemNestedAttrs("vcd_vapp_vm.template-vm", "extra_config.*", map[string]string{ - "key": "template-vapp-vm-2", - "value": initialValue + "2", - }), - resource.TestCheckTypeSetElemNestedAttrs("vcd_vm.template-vm", "extra_config.*", map[string]string{ - "key": "template-vm-1", - "value": initialValue + "1", - }), - resource.TestCheckTypeSetElemNestedAttrs("vcd_vm.template-vm", "extra_config.*", map[string]string{ - "key": "template-vm-2", - "value": initialValue + "2", - }), - resource.TestCheckTypeSetElemNestedAttrs("vcd_vapp_vm.empty-vm", "extra_config.*", map[string]string{ - "key": "empty-vapp-vm-1", - "value": initialValue + "1", - }), - resource.TestCheckTypeSetElemNestedAttrs("vcd_vapp_vm.empty-vm", "extra_config.*", map[string]string{ - "key": "empty-vapp-vm-2", - "value": initialValue + "2", - }), - resource.TestCheckTypeSetElemNestedAttrs("vcd_vm.empty-vm", "extra_config.*", map[string]string{ - "key": "empty-vm-1", - "value": initialValue + "1", - }), - resource.TestCheckTypeSetElemNestedAttrs("vcd_vm.empty-vm", "extra_config.*", map[string]string{ - "key": "empty-vm-2", - "value": initialValue + "2", - }), + testConditionalCheck(checkVersion(testConfig.Provider.ApiVersion, "> 37.0"), resource.ComposeTestCheckFunc( + resource.TestCheckTypeSetElemNestedAttrs("vcd_vapp_vm.template-vm", "extra_config.*", map[string]string{ + "key": "template-vapp-vm-1", + "value": initialValue + "1", + }), + resource.TestCheckTypeSetElemNestedAttrs("vcd_vapp_vm.template-vm", "extra_config.*", map[string]string{ + "key": "template-vapp-vm-2", + "value": initialValue + "2", + }), + resource.TestCheckTypeSetElemNestedAttrs("vcd_vm.template-vm", "extra_config.*", map[string]string{ + "key": "template-vm-1", + "value": initialValue + "1", + }), + resource.TestCheckTypeSetElemNestedAttrs("vcd_vm.template-vm", "extra_config.*", map[string]string{ + "key": "template-vm-2", + "value": initialValue + "2", + }), + resource.TestCheckTypeSetElemNestedAttrs("vcd_vapp_vm.empty-vm", "extra_config.*", map[string]string{ + "key": "empty-vapp-vm-1", + "value": initialValue + "1", + }), + resource.TestCheckTypeSetElemNestedAttrs("vcd_vapp_vm.empty-vm", "extra_config.*", map[string]string{ + "key": "empty-vapp-vm-2", + "value": initialValue + "2", + }), + resource.TestCheckTypeSetElemNestedAttrs("vcd_vm.empty-vm", "extra_config.*", map[string]string{ + "key": "empty-vm-1", + "value": initialValue + "1", + }), + resource.TestCheckTypeSetElemNestedAttrs("vcd_vm.empty-vm", "extra_config.*", map[string]string{ + "key": "empty-vm-2", + "value": initialValue + "2", + }), + )), ), }, // Update extra configuration items { Config: configTextStep2, - Check: resource.ComposeAggregateTestCheckFunc( + Check: testConditionalCheck(checkVersion(testConfig.Provider.ApiVersion, "> 37.0"), resource.ComposeTestCheckFunc( resource.TestCheckTypeSetElemNestedAttrs("vcd_vapp_vm.template-vm", "extra_config.*", map[string]string{ "key": "template-vapp-vm-1", "value": updatedValue + "1", @@ -244,12 +247,12 @@ func TestAccVcdVAppVm_extraconfig(t *testing.T) { "key": "empty-vm-2", "value": updatedValue + "2", }), - ), + )), }, // Remove extra configuration items { Config: configTextStep3, - Check: resource.ComposeAggregateTestCheckFunc( + Check: testConditionalCheck(checkVersion(testConfig.Provider.ApiVersion, "> 37.0"), resource.ComposeTestCheckFunc( checkExtraConfigExists(testConfig.Nsxt.Vdc, t.Name()+"-template-vapp-vm", map[string]string{"template-vapp-vm1": ""}, false), checkExtraConfigExists(testConfig.Nsxt.Vdc, t.Name()+"-template-standalone-vm", map[string]string{"template-vm1": ""}, false), checkExtraConfigExists(testConfig.Nsxt.Vdc, t.Name()+"-empty-vapp-vm", map[string]string{"empty-vapp-vm1": ""}, false), @@ -258,7 +261,7 @@ func TestAccVcdVAppVm_extraconfig(t *testing.T) { checkExtraConfigExists(testConfig.Nsxt.Vdc, t.Name()+"-template-standalone-vm", map[string]string{"template-vm2": ""}, false), checkExtraConfigExists(testConfig.Nsxt.Vdc, t.Name()+"-empty-vapp-vm", map[string]string{"empty-vapp-vm2": ""}, false), checkExtraConfigExists(testConfig.Nsxt.Vdc, t.Name()+"-empty-standalone-vm", map[string]string{"empty-vm2": ""}, false), - ), + )), }, }, }) diff --git a/website/docs/r/vapp_vm.html.markdown b/website/docs/r/vapp_vm.html.markdown index 04c969d29..a29fefc27 100644 --- a/website/docs/r/vapp_vm.html.markdown +++ b/website/docs/r/vapp_vm.html.markdown @@ -569,7 +569,7 @@ example for usage details. * `status_text` - (*v3.8+*) The vApp status as text. * `inherited_metadata` - (*v3.11+*; *VCD 10.5.1+*) A map that contains read-only metadata that is automatically added by VCD (10.5.1+) and provides details on the origin of the VM (e.g. `vm.origin.id`, `vm.origin.name`, `vm.origin.type`). -* `extra_config` - (*v3.13.+*) The VM extra configuration. See [Extra Configuration](#extra-configuration) for more detail. +* `extra_config` - (*v3.13.+*) The VM extra configuration. See [Extra Configuration](#extra-configuration) for more detail. *Not populated on VCD 10.4.0*. * `imported` - (*v3.13.+*) A true/false value telling whether the resource was imported.