provider/vSphere Disk Controller Type (#6785)
Gives the user the ability to specify the controller type they would like to connect their disk to. Supported options are scsi and ide.
This commit is contained in:
parent
6830993024
commit
c34ea953b0
|
@ -39,10 +39,11 @@ type networkInterface struct {
|
|||
}
|
||||
|
||||
type hardDisk struct {
|
||||
size int64
|
||||
iops int64
|
||||
initType string
|
||||
vmdkPath string
|
||||
size int64
|
||||
iops int64
|
||||
initType string
|
||||
vmdkPath string
|
||||
controller string
|
||||
}
|
||||
|
||||
//Additional options Vsphere can use clones of windows machines
|
||||
|
@ -377,6 +378,21 @@ func resourceVSphereVirtualMachine() *schema.Resource {
|
|||
Default: false,
|
||||
ForceNew: true,
|
||||
},
|
||||
|
||||
"controller_type": &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
Default: "scsi",
|
||||
ForceNew: true,
|
||||
ValidateFunc: func(v interface{}, k string) (ws []string, errors []error) {
|
||||
value := v.(string)
|
||||
if value != "scsi" && value != "ide" {
|
||||
errors = append(errors, fmt.Errorf(
|
||||
"only 'scsi' and 'ide' are supported values for 'controller_type'"))
|
||||
}
|
||||
return
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
@ -667,6 +683,9 @@ func resourceVSphereVirtualMachineCreate(d *schema.ResourceData, meta interface{
|
|||
if v, ok := disk["type"].(string); ok && v != "" {
|
||||
disks[i].initType = v
|
||||
}
|
||||
if v, ok := disk["controller_type"].(string); ok && v != "" {
|
||||
disks[i].controller = v
|
||||
}
|
||||
}
|
||||
vm.hardDisks = disks
|
||||
log.Printf("[DEBUG] disk init: %v", disks)
|
||||
|
@ -873,14 +892,14 @@ func resourceVSphereVirtualMachineDelete(d *schema.ResourceData, meta interface{
|
|||
}
|
||||
|
||||
// addHardDisk adds a new Hard Disk to the VirtualMachine.
|
||||
func addHardDisk(vm *object.VirtualMachine, size, iops int64, diskType string, datastore *object.Datastore, diskPath string) error {
|
||||
func addHardDisk(vm *object.VirtualMachine, size, iops int64, diskType string, datastore *object.Datastore, diskPath string, controller_type string) error {
|
||||
devices, err := vm.Device(context.TODO())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
log.Printf("[DEBUG] vm devices: %#v\n", devices)
|
||||
|
||||
controller, err := devices.FindDiskController("scsi")
|
||||
controller, err := devices.FindDiskController(controller_type)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -1463,7 +1482,7 @@ func (vm *virtualMachine) setupVirtualMachine(c *govmomi.Client) error {
|
|||
}
|
||||
for i := firstDisk; i < len(vm.hardDisks); i++ {
|
||||
log.Printf("[DEBUG] disk index: %v", i)
|
||||
err = addHardDisk(newVM, vm.hardDisks[i].size, vm.hardDisks[i].iops, vm.hardDisks[i].initType, datastore, vm.hardDisks[i].vmdkPath)
|
||||
err = addHardDisk(newVM, vm.hardDisks[i].size, vm.hardDisks[i].iops, vm.hardDisks[i].initType, datastore, vm.hardDisks[i].vmdkPath, vm.hardDisks[i].controller)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -125,13 +125,17 @@ func TestAccVSphereVirtualMachine_diskInitType(t *testing.T) {
|
|||
resource.TestCheckResourceAttr(
|
||||
"vsphere_virtual_machine.thin", "memory", "4096"),
|
||||
resource.TestCheckResourceAttr(
|
||||
"vsphere_virtual_machine.thin", "disk.#", "2"),
|
||||
"vsphere_virtual_machine.thin", "disk.#", "3"),
|
||||
resource.TestCheckResourceAttr(
|
||||
"vsphere_virtual_machine.thin", "disk.0.template", template),
|
||||
resource.TestCheckResourceAttr(
|
||||
"vsphere_virtual_machine.thin", "disk.0.type", "thin"),
|
||||
resource.TestCheckResourceAttr(
|
||||
"vsphere_virtual_machine.thin", "disk.1.type", "eager_zeroed"),
|
||||
resource.TestCheckResourceAttr(
|
||||
"vsphere_virtual_machine.thin", "disk.1.controller_type", "scsi"),
|
||||
resource.TestCheckResourceAttr(
|
||||
"vsphere_virtual_machine.thin", "disk.2.controller_type", "ide"),
|
||||
resource.TestCheckResourceAttr(
|
||||
"vsphere_virtual_machine.thin", "network_interface.#", "1"),
|
||||
resource.TestCheckResourceAttr(
|
||||
|
@ -968,6 +972,11 @@ resource "vsphere_virtual_machine" "thin" {
|
|||
disk {
|
||||
size = 1
|
||||
iops = 500
|
||||
controller_type = "scsi"
|
||||
}
|
||||
disk {
|
||||
size = 1
|
||||
controller_type = "ide"
|
||||
}
|
||||
}
|
||||
`
|
||||
|
|
|
@ -117,6 +117,7 @@ The `disk` block supports:
|
|||
* `type` - (Optional) 'eager_zeroed' (the default), or 'thin' are supported options.
|
||||
* `vmdk` - (Required if template and size not provided) Path to a vmdk in a vSphere datastore.
|
||||
* `bootable` - (Optional) Set to 'true' if a vmdk was given and it should attempt to boot after creation.
|
||||
* `controller_type` = (Optional) Controller type to attach the disk to. 'scsi' (the default), or 'ide' are supported options.
|
||||
|
||||
<a id="cdrom"></a>
|
||||
## CDROM
|
||||
|
|
Loading…
Reference in New Issue