Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Data source and resource fixes + NVMe binary test skip for VCD <10.2.2 #838

Merged
merged 3 commits into from
May 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changes/v3.7.0/838-bug-fixes.md
Original file line number Diff line number Diff line change
@@ -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]
5 changes: 3 additions & 2 deletions vcd/datasource_vcd_independent_disk.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
}
Expand Down
2 changes: 2 additions & 0 deletions vcd/resource_vcd_independent_disk.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
15 changes: 11 additions & 4 deletions vcd/resource_vcd_independent_disk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion vcd/resource_vcd_vapp_network.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
8 changes: 5 additions & 3 deletions vcd/resource_vcd_vapp_org_network.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
}
}
Expand Down