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

added cloudinit fix #108

Closed
Prev Previous commit
Next Next commit
added cloudinit fix
  • Loading branch information
yannickstruyf3 committed Apr 3, 2020
commit c83a8b93b81b1efe2abc428cfa3a441270e05f45
23 changes: 22 additions & 1 deletion nutanix/resource_nutanix_virtual_machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ var (
vmTimeout = 1 * time.Minute
vmDelay = 3 * time.Second
vmMinTimeout = 3 * time.Second
IDE = "IDE"
)

func resourceNutanixVirtualMachine() *schema.Resource {
Expand Down Expand Up @@ -1197,7 +1198,7 @@ func resourceNutanixVirtualMachineUpdate(d *schema.ResourceData, meta interface{
if err != nil {
return err
}
if res.DiskList, err = expandDiskList(d, false); err != nil {
if res.DiskList, err = expandDiskListUpdate(d, response); err != nil {
return err
}
postCdromCount, err := CountDiskListCdrom(res.DiskList)
Expand Down Expand Up @@ -1658,6 +1659,26 @@ func expandIPAddressList(ipl []interface{}) []*v3.IPAddress {
return nil
}

func expandDiskListUpdate(d *schema.ResourceData, vm *v3.VMIntentResponse) ([]*v3.VMDisk, error) {
var eDiskList []*v3.VMDisk
var err error
if eDiskList, err = expandDiskList(d, false); err != nil {
return eDiskList, err
}
if vm.Spec != nil && vm.Spec.Resources != nil {
for _, disk := range vm.Spec.Resources.DiskList {
if disk.DeviceProperties != nil && disk.DeviceProperties.DiskAddress != nil {
index := disk.DeviceProperties.DiskAddress.DeviceIndex
adapterType := disk.DeviceProperties.DiskAddress.AdapterType
if *index == 3 && *adapterType == IDE {
eDiskList = append(eDiskList, disk)
}
}
}
}
return eDiskList, nil
}

func expandDiskList(d *schema.ResourceData, isCreation bool) ([]*v3.VMDisk, error) {
if v, ok := d.GetOk("disk_list"); ok {
dsk := v.([]interface{})
Expand Down
19 changes: 0 additions & 19 deletions nutanix/resource_nutanix_virtual_machine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,13 +218,6 @@ func TestAccNutanixVirtualMachine_CdromGuestCustomisationReboot(t *testing.T) {
Providers: testAccProviders,
CheckDestroy: testAccCheckNutanixVirtualMachineDestroy,
Steps: []resource.TestStep{
{
Config: testAccNutanixVMConfigCdromGuestCustomisationReboot(r),
Check: resource.ComposeTestCheckFunc(
testAccCheckNutanixVirtualMachineExists(resourceName),
),
ExpectNonEmptyPlan: true,
},
{
Config: testAccNutanixVMConfigCdromGuestCustomisationReboot(r),
Check: resource.ComposeTestCheckFunc(
Expand All @@ -249,18 +242,6 @@ func TestAccNutanixVirtualMachine_CloudInitCustomKeyValues(t *testing.T) {
Providers: testAccProviders,
CheckDestroy: testAccCheckNutanixVirtualMachineDestroy,
Steps: []resource.TestStep{
{
Config: testAccNutanixVMConfigCloudInitCustomKeyValues(r),
Check: resource.ComposeTestCheckFunc(
testAccCheckNutanixVirtualMachineExists(resourceName),
resource.TestCheckResourceAttr(resourceName, "hardware_clock_timezone", "UTC"),
resource.TestCheckResourceAttr(resourceName, "power_state", "ON"),
resource.TestCheckResourceAttr(resourceName, "memory_size_mib", "186"),
resource.TestCheckResourceAttr(resourceName, "num_sockets", "1"),
resource.TestCheckResourceAttr(resourceName, "num_vcpus_per_socket", "1"),
),
ExpectNonEmptyPlan: true,
},
{
Config: testAccNutanixVMConfigCloudInitCustomKeyValues(r),
Check: resource.ComposeTestCheckFunc(
Expand Down
16 changes: 10 additions & 6 deletions nutanix/structure.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ func flattenNicList(nics []*v3.VMNic) []map[string]interface{} {
func flattenDiskList(disks []*v3.VMDisk) []map[string]interface{} {
diskList := make([]map[string]interface{}, 0)
if disks != nil {
diskList = make([]map[string]interface{}, len(disks))
for k, v := range disks {
diskList = make([]map[string]interface{}, 0)
for _, v := range disks {
disk := make(map[string]interface{})

disk["uuid"] = utils.StringValue(v.UUID)
Expand All @@ -117,10 +117,14 @@ func flattenDiskList(disks []*v3.VMDisk) []map[string]interface{} {
if v.DeviceProperties != nil {
deviceProps = make([]map[string]interface{}, 1)
deviceProp := make(map[string]interface{})

index := fmt.Sprintf("%d", utils.Int64Value(v.DeviceProperties.DiskAddress.DeviceIndex))
adapter := v.DeviceProperties.DiskAddress.AdapterType
if index == "3" && *adapter == IDE {
continue
}
diskAddress := map[string]interface{}{
"device_index": fmt.Sprintf("%d", utils.Int64Value(v.DeviceProperties.DiskAddress.DeviceIndex)),
"adapter_type": v.DeviceProperties.DiskAddress.AdapterType,
"device_index": index,
"adapter_type": adapter,
}

deviceProp["disk_address"] = diskAddress
Expand All @@ -132,7 +136,7 @@ func flattenDiskList(disks []*v3.VMDisk) []map[string]interface{} {
disk["data_source_reference"] = flattenReferenceValues(v.DataSourceReference)
disk["volume_group_reference"] = flattenReferenceValues(v.VolumeGroupReference)

diskList[k] = disk
diskList = append(diskList, disk)
}
}
return diskList
Expand Down