From 0a84a41ad1e042f2861ba3816ccea926cc7a21c6 Mon Sep 17 00:00:00 2001 From: Dainius Serplis Date: Thu, 28 Apr 2022 15:39:43 +0300 Subject: [PATCH 1/3] Skip NVMe related binary tests in VCD < 10.2.2 Signed-off-by: Dainius Serplis --- vcd/resource_vcd_independent_disk_test.go | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/vcd/resource_vcd_independent_disk_test.go b/vcd/resource_vcd_independent_disk_test.go index 16f2f9faf..3d7f46e6c 100644 --- a/vcd/resource_vcd_independent_disk_test.go +++ b/vcd/resource_vcd_independent_disk_test.go @@ -80,10 +80,17 @@ func TestAccVcdIndependentDiskBasic(t *testing.T) { configTextWithoutOptionals := templateFill(testAccCheckVcdIndependentDiskWithoutOptionals, params) params["FuncName"] = t.Name() + "-Update" configTextForUpdate := templateFill(testAccCheckVcdIndependentDiskForUpdate, params) - params["FuncName"] = t.Name() + "-Nvme" - configTextNvme := templateFill(testAccCheckVcdIndependentDiskNvmeType, params) - params["FuncName"] = t.Name() + "-NvmeUpdate" - configTextNvmeUpdate := templateFill(testAccCheckVcdIndependentDiskNvmeTypeUpdate, params) + + var configTextNvme string + var configTextNvmeUpdate string + if nvmeUnsupported, _ := vcdVersionIsLowerThan1022(); !nvmeUnsupported { + params["FuncName"] = t.Name() + "-Nvme" + configTextNvme = templateFill(testAccCheckVcdIndependentDiskNvmeType, params) + params["FuncName"] = t.Name() + "-NvmeUpdate" + configTextNvmeUpdate = templateFill(testAccCheckVcdIndependentDiskNvmeTypeUpdate, params) + + } + params["FuncName"] = t.Name() + "-attachedToVm" configTextAttachedToVm := templateFill(testAccCheckVcdIndependentDiskAttachedToVm, params) params["FuncName"] = t.Name() + "-attachedToVmUpdate" From d99eeb6cbfd5f89afd80ba1d26ecc6e98483bb2e Mon Sep 17 00:00:00 2001 From: Dainius Serplis Date: Thu, 28 Apr 2022 15:46:04 +0300 Subject: [PATCH 2/3] Add fixes for datasources Signed-off-by: Dainius Serplis --- vcd/datasource_vcd_independent_disk.go | 5 +++-- vcd/resource_vcd_independent_disk.go | 2 ++ vcd/resource_vcd_vapp_network.go | 2 +- vcd/resource_vcd_vapp_org_network.go | 8 +++++--- 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/vcd/datasource_vcd_independent_disk.go b/vcd/datasource_vcd_independent_disk.go index 5d24c43a8..c9902e400 100644 --- a/vcd/datasource_vcd_independent_disk.go +++ b/vcd/datasource_vcd_independent_disk.go @@ -2,9 +2,10 @@ package vcd import ( "context" - "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "log" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/vmware/go-vcloud-director/v2/govcd" "github.com/vmware/go-vcloud-director/v2/types/v56" @@ -110,7 +111,7 @@ func datasourceVcIndependentDisk() *schema.Resource { func dataSourceVcdIndependentDiskRead(_ context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { vcdClient := meta.(*VCDClient) - _, vdc, err := vcdClient.GetOrgAndVdc("", d.Get("vdc").(string)) + _, vdc, err := vcdClient.GetOrgAndVdcFromResource(d) if err != nil { return diag.Errorf(errorRetrievingOrgAndVdc, err) } diff --git a/vcd/resource_vcd_independent_disk.go b/vcd/resource_vcd_independent_disk.go index d6fc3055f..9f3380f81 100644 --- a/vcd/resource_vcd_independent_disk.go +++ b/vcd/resource_vcd_independent_disk.go @@ -636,6 +636,8 @@ func getDiskForImport(d *schema.ResourceData, meta interface{}, orgName, vdcName } d.SetId(disk.Disk.Id) + dSet(d, "org", orgName) + dSet(d, "vdc", vdcName) dSet(d, "name", disk.Disk.Name) return []*schema.ResourceData{d}, nil } diff --git a/vcd/resource_vcd_vapp_network.go b/vcd/resource_vcd_vapp_network.go index 3a931f458..81d221530 100644 --- a/vcd/resource_vcd_vapp_network.go +++ b/vcd/resource_vcd_vapp_network.go @@ -282,7 +282,7 @@ func genericVappNetworkRead(d *schema.ResourceData, meta interface{}, origin str return fmt.Errorf("unable to get network ID from HREF: %s", err) } // Check name as well to support old resource IDs that are names and datasources that have names provided by the user - if d.Id() == networkId || networkConfig.NetworkName == vappNetworkName { + if extractUuid(d.Id()) == extractUuid(networkId) || networkConfig.NetworkName == vappNetworkName { vAppNetwork = networkConfig break } diff --git a/vcd/resource_vcd_vapp_org_network.go b/vcd/resource_vcd_vapp_org_network.go index 83825ea28..10dd2e558 100644 --- a/vcd/resource_vcd_vapp_org_network.go +++ b/vcd/resource_vcd_vapp_org_network.go @@ -2,11 +2,12 @@ package vcd import ( "fmt" + "log" + "strings" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/vmware/go-vcloud-director/v2/govcd" "github.com/vmware/go-vcloud-director/v2/types/v56" - "log" - "strings" ) func resourceVcdVappOrgNetwork() *schema.Resource { @@ -143,8 +144,9 @@ func genericVappOrgNetworkRead(d *schema.ResourceData, meta interface{}, origin return fmt.Errorf("unable to get network ID from HREF: %s", err) } // name check needed for datasource to find network as don't have ID - if d.Id() == networkId || networkConfig.NetworkName == d.Get("org_network_name").(string) { + if extractUuid(d.Id()) == extractUuid(networkId) || networkConfig.NetworkName == d.Get("org_network_name").(string) { vAppNetwork = networkConfig + break } } } From e34c5d2c53d3ae802c9be0ced0f735468078b961 Mon Sep 17 00:00:00 2001 From: Dainius Serplis Date: Thu, 28 Apr 2022 15:51:01 +0300 Subject: [PATCH 3/3] Add changelog Signed-off-by: Dainius Serplis --- .changes/v3.7.0/838-bug-fixes.md | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .changes/v3.7.0/838-bug-fixes.md diff --git a/.changes/v3.7.0/838-bug-fixes.md b/.changes/v3.7.0/838-bug-fixes.md new file mode 100644 index 000000000..a1b61b96d --- /dev/null +++ b/.changes/v3.7.0/838-bug-fixes.md @@ -0,0 +1,3 @@ +* Skip binary and upgrade tests for NVMe in VCD < 10.2.2 [GH-838] +* Network lookup could return incorrect ID for `vcd_vapp_network` and `vcd_vapp_org_network` [GH-838] +* Set missing `org` and `vdc` fields during import of `vcd_independent_disk` [GH-838]