Skip to content

Commit

Permalink
Test fixes (vmware#1288)
Browse files Browse the repository at this point in the history
  • Loading branch information
Didainius authored Jul 2, 2024
1 parent 399d5b0 commit 82d7e3f
Show file tree
Hide file tree
Showing 13 changed files with 116 additions and 64 deletions.
5 changes: 2 additions & 3 deletions .changes/v3.13.0/1253-improvements.md
Original file line number Diff line number Diff line change
@@ -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]
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
8 changes: 8 additions & 0 deletions scripts/skip-upgrade-tests.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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'"
29 changes: 29 additions & 0 deletions vcd/datasource_not_found_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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",
Expand Down
13 changes: 7 additions & 6 deletions vcd/metadata_common_test.go
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion vcd/org_vdc_common_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//go:build vdc || nsxt || ALL || functional
//go:build vdc || nsxt || standaloneVm || vm || vapp || ALL || functional

package vcd

Expand Down
1 change: 1 addition & 0 deletions vcd/resource_vcd_cse_kubernetes_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
30 changes: 20 additions & 10 deletions vcd/resource_vcd_nsxt_alb_system_prerequisites_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
Expand All @@ -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{
Expand All @@ -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.")
Expand All @@ -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{
Expand All @@ -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.")
Expand All @@ -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
Expand All @@ -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.")
Expand All @@ -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.")
Expand Down
1 change: 1 addition & 0 deletions vcd/resource_vcd_solution_landing_zone_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down
4 changes: 2 additions & 2 deletions vcd/resource_vcd_vapp_vm_copy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
Expand Down
79 changes: 41 additions & 38 deletions vcd/resource_vcd_vapp_vm_extraconfig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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),
Expand All @@ -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),
),
)),
},
},
})
Expand Down
2 changes: 1 addition & 1 deletion website/docs/r/vapp_vm.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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.

<a id="disk"></a>
Expand Down

0 comments on commit 82d7e3f

Please sign in to comment.