Skip to content

Commit 68961a4

Browse files
committed
Small edits to the PR
1 parent 422cd11 commit 68961a4

6 files changed

+39
-34
lines changed

vsphere/data_source_vsphere_vmfs_disks.go

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@ package vsphere
33
import (
44
"context"
55
"fmt"
6-
"github.com/hashicorp/terraform-provider-vsphere/vsphere/internal/helper/structure"
76
"regexp"
87
"sort"
98
"time"
109

10+
"github.com/hashicorp/terraform-provider-vsphere/vsphere/internal/helper/structure"
11+
1112
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
1213
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
1314
"github.com/vmware/govmomi/vim25/mo"
@@ -37,29 +38,29 @@ func dataSourceVSphereVmfsDisks() *schema.Resource {
3738
},
3839
"disks": {
3940
Type: schema.TypeList,
40-
Description: "The names of the disks discovered by the search.",
41+
Description: "The canonical names of the disks discovered by the search.",
4142
Computed: true,
4243
Elem: &schema.Schema{Type: schema.TypeString},
4344
},
44-
"disks_info": {
45+
"disk_details": {
4546
Type: schema.TypeList,
4647
Description: "The details of the disks discovered by the search.",
4748
Computed: true,
4849
Elem: &schema.Resource{Schema: map[string]*schema.Schema{
49-
"name": {
50+
"display_name": {
5051
Type: schema.TypeString,
5152
Computed: true,
52-
Description: "Display name of the disk",
53+
Description: "Display name of the disk.",
5354
},
54-
"path": {
55+
"device_path": {
5556
Type: schema.TypeString,
5657
Computed: true,
5758
Description: "Path of the physical volume of the disk.",
5859
},
59-
"capacity_in_gb": {
60+
"capacity_gb": {
6061
Type: schema.TypeInt,
6162
Computed: true,
62-
Description: "Capacity in GB.",
63+
Description: "Capacity of the disk in GiB.",
6364
},
6465
}},
6566
},
@@ -93,28 +94,33 @@ func dataSourceVSphereVmfsDisksRead(d *schema.ResourceData, meta interface{}) er
9394
d.SetId(time.Now().UTC().String())
9495

9596
var disks []string
96-
var disksInfo []map[string]interface{}
97+
diskDetailsMap := make(map[string]map[string]interface{})
9798
for _, sl := range hss.StorageDeviceInfo.ScsiLun {
9899
if hsd, ok := sl.(*types.HostScsiDisk); ok {
99100
if matched, _ := regexp.MatchString(d.Get("filter").(string), hsd.CanonicalName); matched {
100101
disk := make(map[string]interface{})
101-
disk["name"] = hsd.DisplayName
102-
disk["path"] = hsd.DevicePath
102+
disk["display_name"] = hsd.DisplayName
103+
disk["device_path"] = hsd.DevicePath
103104
block := hsd.Capacity.Block
104105
blockSize := int64(hsd.Capacity.BlockSize)
105-
disk["capacity_in_gb"] = structure.ByteToGiB(block * blockSize)
106-
disksInfo = append(disksInfo, disk)
106+
disk["capacity_gb"] = structure.ByteToGiB(block * blockSize)
107107
disks = append(disks, hsd.CanonicalName)
108+
diskDetailsMap[hsd.CanonicalName] = disk
108109
}
109110
}
110111
}
111112
sort.Strings(disks)
113+
// use the now sorted name list to create a matching order details list
114+
diskDetails := make([]map[string]interface{}, len(disks))
115+
for i, name := range disks {
116+
diskDetails[i] = diskDetailsMap[name]
117+
}
112118

113119
if err := d.Set("disks", disks); err != nil {
114120
return fmt.Errorf("error saving results to state: %s", err)
115121
}
116122

117-
if err := d.Set("disks_info", disksInfo); err != nil {
123+
if err := d.Set("disk_details", diskDetails); err != nil {
118124
return fmt.Errorf("error saving results to state: %s", err)
119125
}
120126

vsphere/data_source_vsphere_vmfs_disks_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ data "vsphere_vmfs_disks" "available" {
101101
}
102102
103103
output "found" {
104-
value = "${length(data.vsphere_vmfs_disks.available.disks_info) >= 1 ? "true" : "false" }"
104+
value = "${length(data.vsphere_vmfs_disks.available.disk_details) >= 1 ? "true" : "false" }"
105105
}
106106
`,
107107
testhelper.CombineConfigs(testhelper.ConfigDataRootDC1(), testhelper.ConfigDataRootPortGroup1()),

vsphere/internal/virtualdevice/virtual_machine_disk_subresource.go

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -206,15 +206,17 @@ func DiskSubresourceSchema() map[string]*schema.Schema {
206206
Description: "The type of controller the disk should be connected to. Must be 'scsi', 'sata', or 'ide'.",
207207
},
208208
"rdm_lun_path": {
209-
Type: schema.TypeString,
210-
Optional: true,
211-
Description: "The path to the Lun to be used for RDM disk.",
209+
Type: schema.TypeString,
210+
Optional: true,
211+
RequiredWith: []string{"compatibility_mode"},
212+
Description: "The path to the LUN to be used for RDM disk.",
212213
},
213214
"compatibility_mode": {
214215
Type: schema.TypeString,
215216
Optional: true,
217+
RequiredWith: []string{"rdm_lun_path"},
216218
ValidateFunc: validation.StringInSlice(diskSubresourceCompatibilityModeAllowedValues, false),
217-
Description: "compatibility mode for rdm disk {physical or virtual}.",
219+
Description: "Compatibility mode for RDM disk.",
218220
},
219221
}
220222
structure.MergeSchema(s, subresourceSchema())
@@ -1562,14 +1564,11 @@ func (r *DiskSubresource) DiffGeneral() error {
15621564
if r.Get("eagerly_scrub").(bool) && r.Get("thin_provisioned").(bool) {
15631565
return fmt.Errorf("%s: eagerly_scrub and thin_provisioned cannot both be set to true", name)
15641566
}
1565-
if r.Get("rdm_lun_path").(string) != "" && r.Get("compatibility_mode").(string) == "" {
1566-
return fmt.Errorf("%s: To add a RDM Disk, compatibility_mode is a required parameter", name)
1567-
}
1568-
if r.Get("rdm_lun_path").(string) != "" && r.Get("compatibility_mode").(string) == string(types.VirtualDiskCompatibilityModePhysicalMode) {
1569-
if r.Get("disk_mode").(string) != string(types.VirtualDiskModeIndependent_persistent) {
1570-
return fmt.Errorf("%s: To add RDM Disks in physical compatibility mode, only independent persistent disk mode is supported", name)
1571-
}
1567+
1568+
if r.Get("compatibility_mode").(string) == string(types.VirtualDiskCompatibilityModePhysicalMode) && r.Get("disk_mode").(string) != string(types.VirtualDiskModeIndependent_persistent) {
1569+
return fmt.Errorf("%s: To add RDM Disks in physical compatibility mode, only independent persistent disk mode is supported", name)
15721570
}
1571+
15731572
log.Printf("[DEBUG] %s: Diff validation complete", r)
15741573
return nil
15751574
}

vsphere/resource_vsphere_virtual_machine_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -546,6 +546,9 @@ func TestAccResourceVSphereVirtualMachine_RDMDisk(t *testing.T) {
546546
RunSweepers()
547547
testAccPreCheck(t)
548548
testAccResourceVSphereVirtualMachinePreCheck(t)
549+
if os.Getenv("TF_VAR_VSPHERE_RDM_DISK_LUN_PATH") == "" {
550+
t.Skip("set TF_VAR_VSPHERE_RDM_DISK_LUN_PATH to run vsphere_virtual_machine RDM tests")
551+
}
549552
},
550553
Providers: testAccProviders,
551554
CheckDestroy: testAccResourceVSphereVirtualMachineCheckExists(false),
@@ -2573,9 +2576,6 @@ func testAccResourceVSphereVirtualMachinePreCheck(t *testing.T) {
25732576
if os.Getenv("TF_VAR_VSPHERE_CONTENT_LIBRARY_FILES") == "" {
25742577
t.Skip("set TF_VAR_VSPHERE_CONTENT_LIBRARY_FILES to run vsphere_virtual_machine acceptance tests")
25752578
}
2576-
if os.Getenv("TF_VAR_VSPHERE_RDM_DISK_LUN_PATH") == "" {
2577-
t.Skip("set TF_VAR_VSPHERE_RDM_DISK_LUN_PATH to run vsphere_virtual_machine acceptance tests")
2578-
}
25792579
}
25802580

25812581
func testAccResourceVSphereVirtualMachineCheckExists(expected bool) resource.TestCheckFunc {

website/docs/d/vmfs_disks.html.markdown

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ the output `disks` attribute below, which is lexicographically sorted.
5858
* `disks` - A lexicographically sorted list of devices discovered by the
5959
operation, matching the supplied `filter`, if provided.
6060

61-
* `disks_info` - List of disks discovered by the operation with more details about them.
62-
* `name` - Display name of the disk
63-
* `path` - The path of the volume of the disk.
64-
* `capacity_in_gb` - Capacity of the disk in GB.
61+
* `disk_details` - List of disks discovered by the operation with more details about them. The order matches that of `disks`
62+
* `display_name` - Display name of the disk
63+
* `device_path` - Path of the physical volume of the disk.
64+
* `capacity_gb` - Capacity of the disk in GiB.

website/docs/r/virtual_machine.html.markdown

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -891,7 +891,7 @@ resource "vsphere_virtual_machine" "vm" {
891891
label = "disk2"
892892
size = "10"
893893
unit_number = 2
894-
rdm_lun_path = "//Target LUN path to add a RDM Disk"
894+
rdm_lun_path = "/path/to/lun"
895895
compatibility_mode = "physicalMode"
896896
}
897897

0 commit comments

Comments
 (0)