From a38a23a765c9efe8797f93b8c3dae6aa5aa19243 Mon Sep 17 00:00:00 2001 From: Yannick Struyf Date: Mon, 5 Jul 2021 16:30:00 +0200 Subject: [PATCH 1/5] testing cloud-init fix --- nutanix/resource_nutanix_role_test.go | 78 +-------- nutanix/resource_nutanix_virtual_machine.go | 135 ++++++++++----- nutanix/structure.go | 174 +++++++++++++------- 3 files changed, 210 insertions(+), 177 deletions(-) diff --git a/nutanix/resource_nutanix_role_test.go b/nutanix/resource_nutanix_role_test.go index 621fdffc7..970a4b08b 100644 --- a/nutanix/resource_nutanix_role_test.go +++ b/nutanix/resource_nutanix_role_test.go @@ -132,88 +132,12 @@ resource "nutanix_role" "test" { description = "%[2]s" permission_reference_list { kind = "permission" - uuid = "d08ea95c-8221-4590-a77a-52d69639959a" - } - permission_reference_list { - kind = "permission" - uuid = "1a8a65c0-4333-42c6-9039-fd2585ceead7" - } - permission_reference_list { - kind = "permission" - uuid = "bea75573-e8fe-42a3-817a-bd1bd98ab110" - } - permission_reference_list { - kind = "permission" - uuid = "93e1cc93-d799-4f44-84ad-534814f6db0d" - } - permission_reference_list { - kind = "permission" - uuid = "62f53a1a-324c-4da6-bcb8-2cecc07b2cb7" - } - permission_reference_list { - kind = "permission" - uuid = "62f53a1a-324c-4da6-bcb8-2cecc07b2cb7" - } - permission_reference_list { - kind = "permission" - uuid = "ef38a553-a20f-4a2b-b12d-bb9cca03cbdd" - } - permission_reference_list { - kind = "permission" - uuid = "6e768a07-21ef-4615-84d0-7ec442ec942f" - } - permission_reference_list { - kind = "permission" - uuid = "91b77724-b163-473f-94a8-d016e75c18bd" - } - permission_reference_list { - kind = "permission" - uuid = "491ae1d0-5a8f-4bcc-9cee-068cd01c9274" - } - permission_reference_list { - kind = "permission" - uuid = "1dbfb7b4-9896-4c2a-b6fe-fbf113bae306" - } - permission_reference_list { - kind = "permission" - uuid = "740d29f7-18ae-4d07-aeef-3fc901c1887a" - } - permission_reference_list { - kind = "permission" - uuid = "b28f35be-6561-4a4a-9d90-a298d2de33d7" - } - permission_reference_list { - kind = "permission" - uuid = "428fad6c-8735-4a7d-bad3-8497bef051c8" - } - permission_reference_list { - kind = "permission" - uuid = "ea445ec5-f9bb-4af6-92e8-0d72d11ada85" - } - permission_reference_list { - kind = "permission" - uuid = "85a24ad8-67b6-4b63-b30f-96da1baca161" - } - permission_reference_list { - kind = "permission" - uuid = "d370823b-82d8-4518-a486-b75ba8e130d6" - } - permission_reference_list { - kind = "permission" - uuid = "2e9988df-47ae-44ae-9114-ada346657b90" + uuid = "16b81a55-2bca-48c6-9fab-4f82c6bb4284" } permission_reference_list { kind = "permission" uuid = "4e8e9007-8fbe-4709-a069-278259238e55" } - permission_reference_list { - kind = "permission" - uuid = "2e9988df-47ae-44ae-9114-ada346657b90" - } - permission_reference_list { - kind = "permission" - uuid = "2e9988df-47ae-44ae-9114-ada346657b90" - } } `, name, description) } diff --git a/nutanix/resource_nutanix_virtual_machine.go b/nutanix/resource_nutanix_virtual_machine.go index a57021b94..d457a3b8b 100644 --- a/nutanix/resource_nutanix_virtual_machine.go +++ b/nutanix/resource_nutanix_virtual_machine.go @@ -28,11 +28,12 @@ var ( func resourceNutanixVirtualMachine() *schema.Resource { return &schema.Resource{ - Create: resourceNutanixVirtualMachineCreate, - Read: resourceNutanixVirtualMachineRead, - Update: resourceNutanixVirtualMachineUpdate, - Delete: resourceNutanixVirtualMachineDelete, - Exists: resourceNutanixVirtualMachineExists, + Create: resourceNutanixVirtualMachineCreate, + Read: resourceNutanixVirtualMachineRead, + Update: resourceNutanixVirtualMachineUpdate, + Delete: resourceNutanixVirtualMachineDelete, + Exists: resourceNutanixVirtualMachineExists, + CustomizeDiff: resourceNutanixVirtualMachineDiff, Importer: &schema.ResourceImporter{ State: schema.ImportStatePassthrough, }, @@ -666,6 +667,7 @@ func resourceNutanixVirtualMachine() *schema.Resource { "disk_list": { Type: schema.TypeList, Optional: true, + Computed: true, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ "uuid": { @@ -1313,7 +1315,7 @@ func resourceNutanixVirtualMachineUpdate(d *schema.ResourceData, meta interface{ return err } res.DiskList = expandDiskListUpdate(d, response) - + utils.PrintToJSON(res.DiskList, "[YST] disk update res.DiskList: ") postCdromCount, err := CountDiskListCdrom(res.DiskList) if err != nil { return err @@ -1846,48 +1848,53 @@ func expandDiskListUpdate(d *schema.ResourceData, vm *v3.VMIntentResponse) []*v3 func expandDiskList(d *schema.ResourceData) []*v3.VMDisk { if v, ok := d.GetOk("disk_list"); ok { - dsk := v.([]interface{}) - if len(dsk) > 0 { - dls := make([]*v3.VMDisk, len(dsk)) + return expandDiskListRaw(v) + } + return nil +} - for k, val := range dsk { - v := val.(map[string]interface{}) - dl := &v3.VMDisk{} +func expandDiskListRaw(diskList interface{}) []*v3.VMDisk { + dsk := diskList.([]interface{}) + if len(dsk) > 0 { + dls := make([]*v3.VMDisk, len(dsk)) - // uuid - if v1, ok1 := v["uuid"]; ok1 && v1.(string) != "" { - dl.UUID = utils.StringPtr(v1.(string)) - } - // storage_config - if v, ok1 := v["storage_config"]; ok1 { - dl.StorageConfig = expandStorageConfig(v.([]interface{})) - } - // device_properties - if v1, ok1 := v["device_properties"]; ok1 { - dl.DeviceProperties = expandDeviceProperties(v1.([]interface{})) - } - // data_source_reference - if v1, ok := v["data_source_reference"]; ok && len(v1.(map[string]interface{})) != 0 { - dsref := v1.(map[string]interface{}) - dl.DataSourceReference = validateShortRef(dsref) - } - // volume_group_reference - if v1, ok := v["volume_group_reference"]; ok { - volgr := v1.(map[string]interface{}) - dl.VolumeGroupReference = validateRef(volgr) - } - // disk_size_bytes - if v1, ok1 := v["disk_size_bytes"]; ok1 && v1.(int) != 0 { - dl.DiskSizeBytes = utils.Int64Ptr(int64(v1.(int))) - } - // disk_size_mib - if v1, ok := v["disk_size_mib"]; ok && v1.(int) != 0 { - dl.DiskSizeMib = utils.Int64Ptr(int64(v1.(int))) - } - dls[k] = dl + for k, val := range dsk { + v := val.(map[string]interface{}) + dl := &v3.VMDisk{} + + // uuid + if v1, ok1 := v["uuid"]; ok1 && v1.(string) != "" { + dl.UUID = utils.StringPtr(v1.(string)) + } + // storage_config + if v, ok1 := v["storage_config"]; ok1 { + dl.StorageConfig = expandStorageConfig(v.([]interface{})) } - return dls + // device_properties + if v1, ok1 := v["device_properties"]; ok1 { + dl.DeviceProperties = expandDeviceProperties(v1.([]interface{})) + } + // data_source_reference + if v1, ok := v["data_source_reference"]; ok && len(v1.(map[string]interface{})) != 0 { + dsref := v1.(map[string]interface{}) + dl.DataSourceReference = validateShortRef(dsref) + } + // volume_group_reference + if v1, ok := v["volume_group_reference"]; ok { + volgr := v1.(map[string]interface{}) + dl.VolumeGroupReference = validateRef(volgr) + } + // disk_size_bytes + if v1, ok1 := v["disk_size_bytes"]; ok1 && v1.(int) != 0 { + dl.DiskSizeBytes = utils.Int64Ptr(int64(v1.(int))) + } + // disk_size_mib + if v1, ok := v["disk_size_mib"]; ok && v1.(int) != 0 { + dl.DiskSizeMib = utils.Int64Ptr(int64(v1.(int))) + } + dls[k] = dl } + return dls } return nil } @@ -1903,6 +1910,7 @@ func expandStorageConfig(storageConfig []interface{}) *v3.VMStorageConfig { URL: cast.ToString(scr["url"]), Kind: cast.ToString(scr["kind"]), UUID: cast.ToString(scr["uuid"]), + Name: cast.ToString(scr["name"]), }, } } @@ -2185,6 +2193,45 @@ func setVMTimeout(meta interface{}) { } } +func resourceNutanixVirtualMachineDiff(d *schema.ResourceDiff, m interface{}) error { + log.Printf("[YST ]resourceNutanixVirtualMachineDiff") + cio, cin := d.GetChange("cloud_init_cdrom_uuid") + log.Printf("[YST] cio: %s", cio.(string)) + log.Printf("[YST] cin: %s", cin.(string)) + if cloudInitCdromUUID, ok := d.GetOk("cloud_init_cdrom_uuid"); !ok { + usesGuestCustomization := usesGuestCustomizationDiff(d) + if usesGuestCustomization { + stateFileDiskList, apiDiskList := d.GetChange("disk_list") + newlyGeneratedDiff := expandDiskListRaw(stateFileDiskList) + apiDiskListExpanded := expandDiskListRaw(apiDiskList) + cloudInitHelper, flatDiskList, err := flattenDiskListFilterCloudInitHelper(cloudInitCdromUUID.(string), usesGuestCustomization, apiDiskListExpanded, newlyGeneratedDiff, false) + if err != nil { + return err + } + utils.PrintToJSON(stateFileDiskList, "[YST] stateFileDiskList: ") + utils.PrintToJSON(apiDiskList, "[YST] apiDiskList: ") + utils.PrintToJSON(flatDiskList, "[YST] flatDiskList: ") + utils.PrintToJSON(cloudInitHelper, "[YST] cloudInitHelper: ") + newDiskList := make([]interface{}, 0) + added := false + for i, d := range apiDiskList.([]interface{}) { + if i == cloudInitHelper.Index && cloudInitHelper.UUID != "" { + newDiskList = append(newDiskList, flattenDisk(cloudInitHelper.CloudInitCDrom)) + added = true + } + newDiskList = append(newDiskList, d) + } + if !added && cloudInitHelper.UUID != "" { + newDiskList = append(newDiskList, flattenDisk(cloudInitHelper.CloudInitCDrom)) + } + d.SetNew("cloud_init_cdrom_uuid", cloudInitHelper.UUID) + utils.PrintToJSON(newDiskList, "[YST] newDiskList: ") + d.SetNew("disk_list", newDiskList) + } + } + return nil +} + func resourceNutanixVirtualMachineInstanceResourceV0() *schema.Resource { return &schema.Resource{ Schema: map[string]*schema.Schema{ diff --git a/nutanix/structure.go b/nutanix/structure.go index 2014ce25b..73916e48c 100644 --- a/nutanix/structure.go +++ b/nutanix/structure.go @@ -2,6 +2,7 @@ package nutanix import ( "fmt" + "log" "strconv" "github.com/hashicorp/terraform-plugin-sdk/helper/schema" @@ -119,6 +120,22 @@ func usesGuestCustomization(d *schema.ResourceData) bool { return false } +func usesGuestCustomizationDiff(d *schema.ResourceDiff) bool { + keys := []string{ + "guest_customization_cloud_init_user_data", + "guest_customization_cloud_init_meta_data", + "guest_customization_cloud_init_custom_key_values", + "guest_customization_is_overridable", + "guest_customization_sysprep", + "guest_customization_sysprep_custom_key_values"} + for _, k := range keys { + if _, ok := d.GetOk(k); ok { + return true + } + } + return false +} + func getDeviceIndexForDisk(disk *v3.VMDisk) (*int64, error) { if disk.DeviceProperties == nil { return nil, fmt.Errorf("deviceproperties was nil for disk") @@ -133,22 +150,49 @@ func getDeviceIndexForDisk(disk *v3.VMDisk) (*int64, error) { return &diskIndex, nil } +type CloudInitHelper struct { + Index int + CloudInitCDrom *v3.VMDisk + UUID string +} + func flattenDiskListFilterCloudInit(d *schema.ResourceData, disks []*v3.VMDisk) ([]map[string]interface{}, error) { //todo check if guestcust is passed -> if it is not passed, just continue without searching for cloud-init uuid // reason: no device_index or disk id will result in crash cloudInitCdromUUID := "" + cloudInitWasSet := false if cloudInitCdromUUIDInput, cliOk := d.GetOk("cloud_init_cdrom_uuid"); cliOk { cloudInitCdromUUID = cloudInitCdromUUIDInput.(string) + cloudInitWasSet = true } + cloudInitHelper, fDiskList, err := flattenDiskListFilterCloudInitHelper(cloudInitCdromUUID, usesGuestCustomization(d), expandDiskList(d), disks, true) + if err != nil { + return fDiskList, err + } + cloudInitCdromUUID = cloudInitHelper.UUID + if !cloudInitWasSet { + d.Set("cloud_init_cdrom_uuid", cloudInitCdromUUID) + } + return fDiskList, nil +} + +func flattenDiskListFilterCloudInitHelper( + cloudInitCdromUUID string, + usesGuestCustomization bool, + expandedDisks, disks []*v3.VMDisk, + removeCloudInit bool) (*CloudInitHelper, []map[string]interface{}, error) { + //todo check if guestcust is passed -> if it is not passed, just continue without searching for cloud-init uuid + // reason: no device_index or disk id will result in crash + cloudInitHelper := &CloudInitHelper{} filteredDiskList := disks - potentialCloudInitIDs := make([]string, 0) - if cloudInitCdromUUID == "" && usesGuestCustomization(d) { + potentialCloudInitHelpers := make([]CloudInitHelper, 0) + if cloudInitCdromUUID == "" && usesGuestCustomization { filteredDiskList = make([]*v3.VMDisk, 0) //expand the user inputted list of disks - expandedOrgDiskList := expandDiskList(d) + expandedOrgDiskList := expandedDisks //extract the CD-rom drives userCdromDiskList := GetCdromDiskList(expandedOrgDiskList) - for _, eDisk := range disks { + for index, eDisk := range disks { //if existing disk is not CD-rom, append it to the list and continue if !isCdromDisk(eDisk) { filteredDiskList = append(filteredDiskList, eDisk) @@ -157,7 +201,7 @@ func flattenDiskListFilterCloudInit(d *schema.ResourceData, disks []*v3.VMDisk) //Get existing CDrom device Index eDiskIndexP, err := getDeviceIndexForDisk(eDisk) //*eDisk.DeviceProperties.DiskAddress.DeviceIndex if err != nil { - return nil, err + return nil, nil, err } eDiskIndex := *eDiskIndexP match := false @@ -166,7 +210,7 @@ func flattenDiskListFilterCloudInit(d *schema.ResourceData, disks []*v3.VMDisk) //extract the device index of the user defined cdrom uDiskIndexP, err := getDeviceIndexForDisk(uDisk) if err != nil { - return nil, err + return nil, nil, err } uDiskIndex := *uDiskIndexP // if there is a matching device index for a userdefined and an existing cdrom, it is not the cloud-init one @@ -177,73 +221,91 @@ func flattenDiskListFilterCloudInit(d *schema.ResourceData, disks []*v3.VMDisk) } } if !match { - potentialCloudInitIDs = append(potentialCloudInitIDs, *eDisk.UUID) + potentialCloudInitHelpers = append(potentialCloudInitHelpers, CloudInitHelper{ + UUID: *eDisk.UUID, + CloudInitCDrom: eDisk, + Index: index, + }) + if !removeCloudInit { + filteredDiskList = append(filteredDiskList, eDisk) + } } } } - if len(potentialCloudInitIDs) == 1 { - cloudInitCdromUUID = potentialCloudInitIDs[0] - d.Set("cloud_init_cdrom_uuid", cloudInitCdromUUID) + log.Printf("[YST] pre if potentialCloudInitHelpers ") + if len(potentialCloudInitHelpers) == 1 { + log.Printf("[YST] in if potentialCloudInitHelpers ") + cloudInitHelper = &potentialCloudInitHelpers[0] + cloudInitCdromUUID = cloudInitHelper.UUID + // d.Set("cloud_init_cdrom_uuid", cloudInitCdromUUID) } - if len(potentialCloudInitIDs) > 1 { - return nil, fmt.Errorf("more than 1 unknown cd-rom device: %v", potentialCloudInitIDs) + log.Printf("[YST] post if potentialCloudInitHelpers ") + if len(potentialCloudInitHelpers) > 1 { + return nil, nil, fmt.Errorf("more than 1 unknown cd-rom device") } } - fDiskList := flattenDiskListHelper(filteredDiskList, cloudInitCdromUUID) - return fDiskList, nil + fDiskList := flattenDiskListHelper(filteredDiskList, cloudInitCdromUUID, removeCloudInit) + return cloudInitHelper, fDiskList, nil } + func flattenDiskList(disks []*v3.VMDisk) []map[string]interface{} { - return flattenDiskListHelper(disks, "") + return flattenDiskListHelper(disks, "", true) } -func flattenDiskListHelper(disks []*v3.VMDisk, cloudInitCdromUUID string) []map[string]interface{} { +func flattenDiskListHelper(disks []*v3.VMDisk, cloudInitCdromUUID string, removeCloudInit bool) []map[string]interface{} { + utils.PrintToJSON(disks, "[YST] flattendisklisthelper disks: ") diskList := make([]map[string]interface{}, 0) for _, v := range disks { - var deviceProps []map[string]interface{} - var storageConfig []map[string]interface{} - - if v.DeviceProperties != nil { - deviceProps = make([]map[string]interface{}, 1) - index := fmt.Sprintf("%d", utils.Int64Value(v.DeviceProperties.DiskAddress.DeviceIndex)) - adapter := v.DeviceProperties.DiskAddress.AdapterType - - deviceProps[0] = map[string]interface{}{ - "device_type": v.DeviceProperties.DeviceType, - "disk_address": map[string]interface{}{ - "device_index": index, - "adapter_type": adapter, - }, - } + flatDisk := flattenDisk(v) + diskUUID := flatDisk["uuid"] + if cloudInitCdromUUID == diskUUID && removeCloudInit { + continue } + diskList = append(diskList, flatDisk) + } + return diskList +} - if v.StorageConfig != nil { - storageConfig = append(storageConfig, map[string]interface{}{ - "flash_mode": cast.ToString(v.StorageConfig.FlashMode), - "storage_container_reference": []map[string]interface{}{ - { - "url": cast.ToString(v.StorageConfig.StorageContainerReference.URL), - "kind": cast.ToString(v.StorageConfig.StorageContainerReference.Kind), - "name": cast.ToString(v.StorageConfig.StorageContainerReference.Name), - "uuid": cast.ToString(v.StorageConfig.StorageContainerReference.UUID), - }, - }, - }) - } +func flattenDisk(v *v3.VMDisk) map[string]interface{} { + var deviceProps []map[string]interface{} + var storageConfig []map[string]interface{} - diskUUID := utils.StringValue(v.UUID) - if cloudInitCdromUUID == diskUUID { - continue + if v.DeviceProperties != nil { + deviceProps = make([]map[string]interface{}, 1) + index := fmt.Sprintf("%d", utils.Int64Value(v.DeviceProperties.DiskAddress.DeviceIndex)) + adapter := v.DeviceProperties.DiskAddress.AdapterType + + deviceProps[0] = map[string]interface{}{ + "device_type": v.DeviceProperties.DeviceType, + "disk_address": map[string]interface{}{ + "device_index": index, + "adapter_type": adapter, + }, } - diskList = append(diskList, map[string]interface{}{ - "uuid": diskUUID, - "disk_size_bytes": utils.Int64Value(v.DiskSizeBytes), - "disk_size_mib": utils.Int64Value(v.DiskSizeMib), - "device_properties": deviceProps, - "storage_config": storageConfig, - "data_source_reference": flattenReferenceValues(v.DataSourceReference), - "volume_group_reference": flattenReferenceValues(v.VolumeGroupReference), + } + + if v.StorageConfig != nil { + storageConfig = append(storageConfig, map[string]interface{}{ + "flash_mode": cast.ToString(v.StorageConfig.FlashMode), + "storage_container_reference": []map[string]interface{}{ + { + "url": cast.ToString(v.StorageConfig.StorageContainerReference.URL), + "kind": cast.ToString(v.StorageConfig.StorageContainerReference.Kind), + "name": cast.ToString(v.StorageConfig.StorageContainerReference.Name), + "uuid": cast.ToString(v.StorageConfig.StorageContainerReference.UUID), + }, + }, }) } - return diskList + + return map[string]interface{}{ + "uuid": utils.StringValue(v.UUID), + "disk_size_bytes": utils.Int64Value(v.DiskSizeBytes), + "disk_size_mib": utils.Int64Value(v.DiskSizeMib), + "device_properties": deviceProps, + "storage_config": storageConfig, + "data_source_reference": flattenReferenceValues(v.DataSourceReference), + "volume_group_reference": flattenReferenceValues(v.VolumeGroupReference), + } } func flattenSerialPortList(serialPorts []*v3.VMSerialPort) []map[string]interface{} { From 784bdaabf3c9eaca84c510bb51463f29d59405c7 Mon Sep 17 00:00:00 2001 From: Yannick Struyf Date: Wed, 8 Sep 2021 22:00:57 +0200 Subject: [PATCH 2/5] removed debug logging --- nutanix/resource_nutanix_virtual_machine.go | 9 --------- 1 file changed, 9 deletions(-) diff --git a/nutanix/resource_nutanix_virtual_machine.go b/nutanix/resource_nutanix_virtual_machine.go index d457a3b8b..54edb56b2 100644 --- a/nutanix/resource_nutanix_virtual_machine.go +++ b/nutanix/resource_nutanix_virtual_machine.go @@ -1315,7 +1315,6 @@ func resourceNutanixVirtualMachineUpdate(d *schema.ResourceData, meta interface{ return err } res.DiskList = expandDiskListUpdate(d, response) - utils.PrintToJSON(res.DiskList, "[YST] disk update res.DiskList: ") postCdromCount, err := CountDiskListCdrom(res.DiskList) if err != nil { return err @@ -2194,10 +2193,7 @@ func setVMTimeout(meta interface{}) { } func resourceNutanixVirtualMachineDiff(d *schema.ResourceDiff, m interface{}) error { - log.Printf("[YST ]resourceNutanixVirtualMachineDiff") cio, cin := d.GetChange("cloud_init_cdrom_uuid") - log.Printf("[YST] cio: %s", cio.(string)) - log.Printf("[YST] cin: %s", cin.(string)) if cloudInitCdromUUID, ok := d.GetOk("cloud_init_cdrom_uuid"); !ok { usesGuestCustomization := usesGuestCustomizationDiff(d) if usesGuestCustomization { @@ -2208,10 +2204,6 @@ func resourceNutanixVirtualMachineDiff(d *schema.ResourceDiff, m interface{}) er if err != nil { return err } - utils.PrintToJSON(stateFileDiskList, "[YST] stateFileDiskList: ") - utils.PrintToJSON(apiDiskList, "[YST] apiDiskList: ") - utils.PrintToJSON(flatDiskList, "[YST] flatDiskList: ") - utils.PrintToJSON(cloudInitHelper, "[YST] cloudInitHelper: ") newDiskList := make([]interface{}, 0) added := false for i, d := range apiDiskList.([]interface{}) { @@ -2225,7 +2217,6 @@ func resourceNutanixVirtualMachineDiff(d *schema.ResourceDiff, m interface{}) er newDiskList = append(newDiskList, flattenDisk(cloudInitHelper.CloudInitCDrom)) } d.SetNew("cloud_init_cdrom_uuid", cloudInitHelper.UUID) - utils.PrintToJSON(newDiskList, "[YST] newDiskList: ") d.SetNew("disk_list", newDiskList) } } From 4d70aa59339ab4453a24c75d04f08ebfb9c06297 Mon Sep 17 00:00:00 2001 From: Yannick Struyf Date: Wed, 8 Sep 2021 22:05:48 +0200 Subject: [PATCH 3/5] removed unused variables based on linter output --- nutanix/resource_nutanix_virtual_machine.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/nutanix/resource_nutanix_virtual_machine.go b/nutanix/resource_nutanix_virtual_machine.go index 54edb56b2..86b2bddd1 100644 --- a/nutanix/resource_nutanix_virtual_machine.go +++ b/nutanix/resource_nutanix_virtual_machine.go @@ -2193,14 +2193,13 @@ func setVMTimeout(meta interface{}) { } func resourceNutanixVirtualMachineDiff(d *schema.ResourceDiff, m interface{}) error { - cio, cin := d.GetChange("cloud_init_cdrom_uuid") if cloudInitCdromUUID, ok := d.GetOk("cloud_init_cdrom_uuid"); !ok { usesGuestCustomization := usesGuestCustomizationDiff(d) if usesGuestCustomization { stateFileDiskList, apiDiskList := d.GetChange("disk_list") newlyGeneratedDiff := expandDiskListRaw(stateFileDiskList) apiDiskListExpanded := expandDiskListRaw(apiDiskList) - cloudInitHelper, flatDiskList, err := flattenDiskListFilterCloudInitHelper(cloudInitCdromUUID.(string), usesGuestCustomization, apiDiskListExpanded, newlyGeneratedDiff, false) + cloudInitHelper, _, err := flattenDiskListFilterCloudInitHelper(cloudInitCdromUUID.(string), usesGuestCustomization, apiDiskListExpanded, newlyGeneratedDiff, false) if err != nil { return err } From 9adaa823ee40dd7e732fbd52a79f9635516e3226 Mon Sep 17 00:00:00 2001 From: Yannick Struyf Date: Wed, 8 Sep 2021 22:37:33 +0200 Subject: [PATCH 4/5] removed debug logs --- nutanix/structure.go | 5 ----- 1 file changed, 5 deletions(-) diff --git a/nutanix/structure.go b/nutanix/structure.go index 73916e48c..803c5e681 100644 --- a/nutanix/structure.go +++ b/nutanix/structure.go @@ -2,7 +2,6 @@ package nutanix import ( "fmt" - "log" "strconv" "github.com/hashicorp/terraform-plugin-sdk/helper/schema" @@ -232,14 +231,11 @@ func flattenDiskListFilterCloudInitHelper( } } } - log.Printf("[YST] pre if potentialCloudInitHelpers ") if len(potentialCloudInitHelpers) == 1 { - log.Printf("[YST] in if potentialCloudInitHelpers ") cloudInitHelper = &potentialCloudInitHelpers[0] cloudInitCdromUUID = cloudInitHelper.UUID // d.Set("cloud_init_cdrom_uuid", cloudInitCdromUUID) } - log.Printf("[YST] post if potentialCloudInitHelpers ") if len(potentialCloudInitHelpers) > 1 { return nil, nil, fmt.Errorf("more than 1 unknown cd-rom device") } @@ -252,7 +248,6 @@ func flattenDiskList(disks []*v3.VMDisk) []map[string]interface{} { return flattenDiskListHelper(disks, "", true) } func flattenDiskListHelper(disks []*v3.VMDisk, cloudInitCdromUUID string, removeCloudInit bool) []map[string]interface{} { - utils.PrintToJSON(disks, "[YST] flattendisklisthelper disks: ") diskList := make([]map[string]interface{}, 0) for _, v := range disks { flatDisk := flattenDisk(v) From ceec5345ab99c5abc93c96c86d06422781a7afa3 Mon Sep 17 00:00:00 2001 From: Yannick Struyf Date: Fri, 10 Sep 2021 14:52:27 +0200 Subject: [PATCH 5/5] removed log in structure.go --- nutanix/structure.go | 1 - 1 file changed, 1 deletion(-) diff --git a/nutanix/structure.go b/nutanix/structure.go index 803c5e681..5d54f8e17 100644 --- a/nutanix/structure.go +++ b/nutanix/structure.go @@ -234,7 +234,6 @@ func flattenDiskListFilterCloudInitHelper( if len(potentialCloudInitHelpers) == 1 { cloudInitHelper = &potentialCloudInitHelpers[0] cloudInitCdromUUID = cloudInitHelper.UUID - // d.Set("cloud_init_cdrom_uuid", cloudInitCdromUUID) } if len(potentialCloudInitHelpers) > 1 { return nil, nil, fmt.Errorf("more than 1 unknown cd-rom device")