From fec2a7c9e15b4730098157acc8cd84007b77f3f6 Mon Sep 17 00:00:00 2001 From: Dan Petersen Date: Sat, 13 Feb 2021 03:22:29 +0100 Subject: [PATCH 1/4] fix: bump version --- CHANGELOG.md | 2 +- proxmoxtf/version.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7841519..2e302fe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,4 @@ -## v0.5.0 (UNRELEASED) +## v0.4.2 (UNRELEASED) OTHER: diff --git a/proxmoxtf/version.go b/proxmoxtf/version.go index 31e9295..99cde2b 100644 --- a/proxmoxtf/version.go +++ b/proxmoxtf/version.go @@ -9,5 +9,5 @@ const ( TerraformProviderName = "terraform-provider-proxmox" // TerraformProviderVersion specifies the version number. - TerraformProviderVersion = "0.4.1" + TerraformProviderVersion = "0.4.2" ) From 781d83535be2274e90f467dfa5bddb172c383fa7 Mon Sep 17 00:00:00 2001 From: Dan Petersen Date: Sat, 13 Feb 2021 07:18:29 +0100 Subject: [PATCH 2/4] fix: state diff issue --- CHANGELOG.md | 8 +- proxmox/virtual_environment_cluster_alias.go | 4 +- ...virtual_environment_cluster_alias_types.go | 15 ++- proxmox/virtual_environment_cluster_ipset.go | 4 +- ...virtual_environment_cluster_ipset_types.go | 14 +-- ...a_source_virtual_environment_datastores.go | 5 +- ...ource_virtual_environment_cluster_ipset.go | 2 +- proxmoxtf/resource_virtual_environment_vm.go | 51 +++++--- proxmoxtf/utils.go | 117 ++++++++++-------- 9 files changed, 129 insertions(+), 91 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2e302fe..670eb96 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,8 @@ -## v0.4.2 (UNRELEASED) +## v0.4.2 + +BUG FIXES: + +* resource/virtual_environment_vm: Fix `disk.file_id` diff issue OTHER: @@ -47,7 +51,7 @@ BUG FIXES: * resource/virtual_environment_container: Fix VM ID collision when `vm_id` is not specified * resource/virtual_environment_vm: Fix VM ID collision when `vm_id` is not specified * resource/virtual_environment_vm: Fix disk import issue when importing from directory-based datastores -* resource/virtual/environment/vm: Fix handling of storage name - correct handling of `-` +* resource/virtual_environment/vm: Fix handling of storage name - correct handling of `-` WORKAROUNDS: diff --git a/proxmox/virtual_environment_cluster_alias.go b/proxmox/virtual_environment_cluster_alias.go index 6fc57aa..2565a66 100644 --- a/proxmox/virtual_environment_cluster_alias.go +++ b/proxmox/virtual_environment_cluster_alias.go @@ -12,7 +12,7 @@ import ( ) // CreateAlias create an alias -func (c *VirtualEnvironmentClient) CreateAlias(d *VirtualEnvironmentClusterAliasCreateRequestBody) error { +func (c *VirtualEnvironmentClient) CreateAlias(d *VirtualEnvironmentClusterAliasCreateRequestBody) error { return c.DoRequest(hmPOST, "cluster/firewall/aliases", d, nil) } @@ -60,4 +60,4 @@ func (c *VirtualEnvironmentClient) ListAliases() ([]*VirtualEnvironmentClusterAl // UpdateAlias updates an alias. func (c *VirtualEnvironmentClient) UpdateAlias(id string, d *VirtualEnvironmentClusterAliasUpdateRequestBody) error { return c.DoRequest(hmPUT, fmt.Sprintf("cluster/firewall/aliases/%s", url.PathEscape(id)), d, nil) -} \ No newline at end of file +} diff --git a/proxmox/virtual_environment_cluster_alias_types.go b/proxmox/virtual_environment_cluster_alias_types.go index d681320..20d41fa 100644 --- a/proxmox/virtual_environment_cluster_alias_types.go +++ b/proxmox/virtual_environment_cluster_alias_types.go @@ -18,11 +18,11 @@ type VirtualEnvironmentClusterAliasGetResponseBody struct { // VirtualEnvironmentClusterAliasGetResponseData contains the data from an alias get response. type VirtualEnvironmentClusterAliasGetResponseData struct { - Comment *string `json:"comment,omitempty" url:"comment,omitempty"` - Name string `json:"name" url:"name"` - CIDR string `json:"cidr" url:"cidr"` - Digest *string `json:"digest" url:"digest"` - IPVersion int `json:"ipversion" url:"ipversion"` + Comment *string `json:"comment,omitempty" url:"comment,omitempty"` + Name string `json:"name" url:"name"` + CIDR string `json:"cidr" url:"cidr"` + Digest *string `json:"digest" url:"digest"` + IPVersion int `json:"ipversion" url:"ipversion"` } // VirtualEnvironmentClusterAliasListResponseBody contains the data from an alias get response. @@ -33,7 +33,6 @@ type VirtualEnvironmentClusterAliasListResponseBody struct { // VirtualEnvironmentClusterAliasUpdateRequestBody contains the data for an alias update request. type VirtualEnvironmentClusterAliasUpdateRequestBody struct { Comment *string `json:"comment,omitempty" url:"comment,omitempty"` - ReName string `json:"rename" url:"rename"` - CIDR string `json:"cidr" url:"cidr"` + ReName string `json:"rename" url:"rename"` + CIDR string `json:"cidr" url:"cidr"` } - diff --git a/proxmox/virtual_environment_cluster_ipset.go b/proxmox/virtual_environment_cluster_ipset.go index 3513bed..b158329 100644 --- a/proxmox/virtual_environment_cluster_ipset.go +++ b/proxmox/virtual_environment_cluster_ipset.go @@ -12,7 +12,7 @@ import ( ) // CreateIPSet create an IPSet -func (c *VirtualEnvironmentClient) CreateIPSet(d *VirtualEnvironmentClusterIPSetCreateRequestBody) error { +func (c *VirtualEnvironmentClient) CreateIPSet(d *VirtualEnvironmentClusterIPSetCreateRequestBody) error { return c.DoRequest(hmPOST, "cluster/firewall/ipset", d, nil) } @@ -70,4 +70,4 @@ func (c *VirtualEnvironmentClient) GetListIPSets() (*VirtualEnvironmentClusterIP }) return resBody, nil -} \ No newline at end of file +} diff --git a/proxmox/virtual_environment_cluster_ipset_types.go b/proxmox/virtual_environment_cluster_ipset_types.go index 36edaff..2f79e93 100644 --- a/proxmox/virtual_environment_cluster_ipset_types.go +++ b/proxmox/virtual_environment_cluster_ipset_types.go @@ -16,7 +16,7 @@ type VirtualEnvironmentClusterIPSetListResponseBody struct { // VirtualEnvironmentClusterIPSetCreateRequestBody contains the data for an IPSet create request type VirtualEnvironmentClusterIPSetCreateRequestBody struct { Comment string `json:"comment,omitempty" url:"comment,omitempty"` - Name string `json:"name" url:"name"` + Name string `json:"name" url:"name"` } // VirtualEnvironmentClusterIPSetGetResponseBody contains the body from an IPSet get response. @@ -26,22 +26,22 @@ type VirtualEnvironmentClusterIPSetGetResponseBody struct { // VirtualEnvironmentClusterIPSetGetResponseData contains the data from an IPSet get response. type VirtualEnvironmentClusterIPSetGetResponseData struct { - CIDR string `json:"cidr" url:"cidr"` - NoMatch *CustomBool `json:"nomatch,omitempty" url:"nomatch,omitempty,int"` - Comment string `json:"comment,omitempty" url:"comment,omitempty"` + CIDR string `json:"cidr" url:"cidr"` + NoMatch *CustomBool `json:"nomatch,omitempty" url:"nomatch,omitempty,int"` + Comment string `json:"comment,omitempty" url:"comment,omitempty"` } // VirtualEnvironmentClusterIPSetUpdateRequestBody contains the data for an IPSet update request. type VirtualEnvironmentClusterIPSetUpdateRequestBody struct { - ReName string `json:"rename,omitempty" url:"rename,omitempty"` + ReName string `json:"rename,omitempty" url:"rename,omitempty"` Comment *string `json:"comment,omitempty" url:"comment,omitempty"` Name string `json:"name" url:"name"` } // VirtualEnvironmentClusterIPSetGetResponseData contains list of IPSets from type VirtualEnvironmentClusterIPSetListResponseData struct { - Comment *string `json:"comment,omitempty" url:"comment,omitempty"` - Name string `json:"name" url:"name"` + Comment *string `json:"comment,omitempty" url:"comment,omitempty"` + Name string `json:"name" url:"name"` } // VirtualEnvironmentClusterIPSetContent is an array of VirtualEnvironmentClusterIPSetGetResponseData. diff --git a/proxmoxtf/data_source_virtual_environment_datastores.go b/proxmoxtf/data_source_virtual_environment_datastores.go index d1f3a51..4a63077 100644 --- a/proxmoxtf/data_source_virtual_environment_datastores.go +++ b/proxmoxtf/data_source_virtual_environment_datastores.go @@ -6,6 +6,7 @@ package proxmoxtf import ( "fmt" + "sort" "github.com/hashicorp/terraform-plugin-sdk/helper/schema" ) @@ -126,7 +127,9 @@ func dataSourceVirtualEnvironmentDatastoresRead(d *schema.ResourceData, m interf } if v.ContentTypes != nil { - contentTypes[i] = []string(*v.ContentTypes) + contentTypeList := []string(*v.ContentTypes) + sort.Strings(contentTypeList) + contentTypes[i] = contentTypeList } else { contentTypes[i] = []string{} } diff --git a/proxmoxtf/resource_virtual_environment_cluster_ipset.go b/proxmoxtf/resource_virtual_environment_cluster_ipset.go index a0e8602..0ca038a 100644 --- a/proxmoxtf/resource_virtual_environment_cluster_ipset.go +++ b/proxmoxtf/resource_virtual_environment_cluster_ipset.go @@ -177,7 +177,7 @@ func resourceVirtualEnvironmentClusterIPSetRead(d *schema.ResourceData, m interf return err } - for key, _ := range IPSet { + for key := range IPSet { d.Set(mkResourceVirtualEnvironmentClusterIPSetCIDR, IPSet[key]) } diff --git a/proxmoxtf/resource_virtual_environment_vm.go b/proxmoxtf/resource_virtual_environment_vm.go index 48fba72..60adae1 100644 --- a/proxmoxtf/resource_virtual_environment_vm.go +++ b/proxmoxtf/resource_virtual_environment_vm.go @@ -1395,8 +1395,7 @@ func resourceVirtualEnvironmentVMCreateClone(d *schema.ResourceData, m interface return err } - allDiskInfo := getDiskInfo(vmConfig) - + allDiskInfo := getDiskInfo(vmConfig, d) diskDeviceObjects, err := resourceVirtualEnvironmentVMGetDiskDeviceObjects(d, m, nil) if err != nil { @@ -1404,7 +1403,6 @@ func resourceVirtualEnvironmentVMCreateClone(d *schema.ResourceData, m interface } for i := range disk { - diskBlock := disk[i].(map[string]interface{}) diskInterface := diskBlock[mkResourcevirtualEnvironmentVMDiskInterface].(string) dataStoreID := diskBlock[mkResourceVirtualEnvironmentVMDiskDatastoreID].(string) @@ -1418,17 +1416,17 @@ func resourceVirtualEnvironmentVMCreateClone(d *schema.ResourceData, m interface switch prefix { case "virtio": if diskUpdateBody.VirtualIODevices == nil { - diskUpdateBody.VirtualIODevices = make(proxmox.CustomStorageDevices) + diskUpdateBody.VirtualIODevices = proxmox.CustomStorageDevices{} } diskUpdateBody.VirtualIODevices[diskInterface] = diskDeviceObjects[prefix][diskInterface] case "sata": if diskUpdateBody.SATADevices == nil { - diskUpdateBody.SATADevices = make(proxmox.CustomStorageDevices) + diskUpdateBody.SATADevices = proxmox.CustomStorageDevices{} } diskUpdateBody.SATADevices[diskInterface] = diskDeviceObjects[prefix][diskInterface] case "scsi": if diskUpdateBody.SCSIDevices == nil { - diskUpdateBody.SCSIDevices = make(proxmox.CustomStorageDevices) + diskUpdateBody.SCSIDevices = proxmox.CustomStorageDevices{} } diskUpdateBody.SCSIDevices[diskInterface] = diskDeviceObjects[prefix][diskInterface] } @@ -1798,7 +1796,7 @@ func resourceVirtualEnvironmentVMCreateCustomDisks(d *schema.ResourceData, m int fileFormat, _ := block[mkResourceVirtualEnvironmentVMDiskFileFormat].(string) size, _ := block[mkResourceVirtualEnvironmentVMDiskSize].(int) speed := block[mkResourceVirtualEnvironmentVMDiskSpeed].([]interface{}) - diskInterface,_ := block[mkResourcevirtualEnvironmentVMDiskInterface].(string) + diskInterface, _ := block[mkResourcevirtualEnvironmentVMDiskInterface].(string) if len(speed) == 0 { diskSpeedDefault, err := diskSpeedResource.DefaultValue() @@ -2087,12 +2085,14 @@ func resourceVirtualEnvironmentVMGetCPUArchitectureValidator() schema.SchemaVali func resourceVirtualEnvironmentVMGetDiskDeviceObjects(d *schema.ResourceData, m interface{}, disks []interface{}) (map[string]map[string]proxmox.CustomStorageDevice, error) { var diskDevice []interface{} + if disks != nil { diskDevice = disks } else { diskDevice = d.Get(mkResourceVirtualEnvironmentVMDisk).([]interface{}) } - diskDeviceObjects := make(map[string]map[string]proxmox.CustomStorageDevice) + + diskDeviceObjects := map[string]map[string]proxmox.CustomStorageDevice{} resource := resourceVirtualEnvironmentVM() for _, diskEntry := range diskDevice { @@ -2156,7 +2156,7 @@ func resourceVirtualEnvironmentVMGetDiskDeviceObjects(d *schema.ResourceData, m } if _, present := diskDeviceObjects[baseDiskInterface]; !present { - diskDeviceObjects[baseDiskInterface] = make(map[string]proxmox.CustomStorageDevice) + diskDeviceObjects[baseDiskInterface] = map[string]proxmox.CustomStorageDevice{} } diskDeviceObjects[baseDiskInterface][diskInterface] = diskDevice @@ -2439,7 +2439,6 @@ func resourceVirtualEnvironmentVMReadCustom(d *schema.ResourceData, m interface{ // Compare the IDE devices to the CDROM and cloud-init configurations stored in the state. if vmConfig.IDEDevice3 != nil { - cdrom := make([]interface{}, 1) cdromBlock := map[string]interface{}{} currentCDROM := d.Get(mkResourceVirtualEnvironmentVMCDROM).([]interface{}) @@ -2549,9 +2548,10 @@ func resourceVirtualEnvironmentVMReadCustom(d *schema.ResourceData, m interface{ d.Set(mkResourceVirtualEnvironmentVMCPU, []interface{}{cpu}) } + currentDiskList := d.Get(mkResourceVirtualEnvironmentVMDisk).([]interface{}) diskMap := map[string]interface{}{} + diskObjects := getDiskInfo(vmConfig, d) orderedDiskList := []interface{}{} - diskObjects := getDiskInfo(vmConfig) for di, dd := range diskObjects { disk := map[string]interface{}{} @@ -2564,12 +2564,16 @@ func resourceVirtualEnvironmentVMReadCustom(d *schema.ResourceData, m interface{ disk[mkResourceVirtualEnvironmentVMDiskDatastoreID] = fileIDParts[0] - disk[mkResourceVirtualEnvironmentVMDiskFileID] = dd.FileID if dd.Format == nil { disk[mkResourceVirtualEnvironmentVMDiskFileFormat] = "qcow2" } else { disk[mkResourceVirtualEnvironmentVMDiskFileFormat] = dd.Format } + + if dd.FileID != nil { + disk[mkResourceVirtualEnvironmentVMDiskFileID] = dd.FileID + } + disk[mkResourcevirtualEnvironmentVMDiskInterface] = di diskSize := 0 @@ -2622,18 +2626,22 @@ func resourceVirtualEnvironmentVMReadCustom(d *schema.ResourceData, m interface{ } keyList := []string{} + for key := range diskMap { keyList = append(keyList, key) } + sort.Strings(keyList) + for _, k := range keyList { orderedDiskList = append(orderedDiskList, diskMap[k]) } + if len(clone) > 0 { - if len(orderedDiskList) > 0 { + if len(currentDiskList) > 0 { d.Set(mkResourceVirtualEnvironmentVMDisk, orderedDiskList) } - } else if len(orderedDiskList) > 0 { + } else if len(currentDiskList) > 0 { d.Set(mkResourceVirtualEnvironmentVMDisk, orderedDiskList) } @@ -3378,7 +3386,7 @@ func resourceVirtualEnvironmentVMUpdate(d *schema.ResourceData, m interface{}) e return err } - diskDeviceInfo := getDiskInfo(vmConfig) + diskDeviceInfo := getDiskInfo(vmConfig, d) for prefix, diskMap := range diskDeviceObjects { if diskMap == nil { @@ -3400,27 +3408,30 @@ func resourceVirtualEnvironmentVMUpdate(d *schema.ResourceData, m interface{}) e case "virtio": { if updateBody.VirtualIODevices == nil { - updateBody.VirtualIODevices = make(proxmox.CustomStorageDevices) + updateBody.VirtualIODevices = proxmox.CustomStorageDevices{} } + updateBody.VirtualIODevices[key] = tmp } case "sata": { if updateBody.SATADevices == nil { - updateBody.SATADevices = make(proxmox.CustomStorageDevices) + updateBody.SATADevices = proxmox.CustomStorageDevices{} } + updateBody.SATADevices[key] = tmp } case "scsi": { if updateBody.SCSIDevices == nil { - updateBody.SCSIDevices = make(proxmox.CustomStorageDevices) + updateBody.SCSIDevices = proxmox.CustomStorageDevices{} } + updateBody.SCSIDevices[key] = tmp } case "ide": { - //not sure right now + // Investigate whether to support IDE mapping. } default: return fmt.Errorf("Device prefix %s not supported", prefix) @@ -3618,11 +3629,13 @@ func resourceVirtualEnvironmentVMUpdateDiskLocationAndSize(d *schema.ResourceDat diskOld, diskNew := d.GetChange(mkResourceVirtualEnvironmentVMDisk) diskOldEntries, err := resourceVirtualEnvironmentVMGetDiskDeviceObjects(d, m, diskOld.([]interface{})) + if err != nil { return err } diskNewEntries, err := resourceVirtualEnvironmentVMGetDiskDeviceObjects(d, m, diskNew.([]interface{})) + if err != nil { return err } diff --git a/proxmoxtf/utils.go b/proxmoxtf/utils.go index 5e1024c..690b1eb 100644 --- a/proxmoxtf/utils.go +++ b/proxmoxtf/utils.go @@ -384,55 +384,74 @@ func getVMIDValidator() schema.SchemaValidateFunc { } } -func getDiskInfo(data *proxmox.VirtualEnvironmentVMGetResponseData) map[string]*proxmox.CustomStorageDevice { - storageDevices := make(map[string]*proxmox.CustomStorageDevice) - storageDevices["ide0"] = data.IDEDevice0 - storageDevices["ide1"] = data.IDEDevice1 - storageDevices["ide2"] = data.IDEDevice2 - - storageDevices["sata0"] = data.SATADevice0 - storageDevices["sata1"] = data.SATADevice1 - storageDevices["sata2"] = data.SATADevice2 - storageDevices["sata3"] = data.SATADevice3 - storageDevices["sata4"] = data.SATADevice4 - storageDevices["sata5"] = data.SATADevice5 - - storageDevices["scsi0"] = data.SCSIDevice0 - storageDevices["scsi1"] = data.SCSIDevice1 - storageDevices["scsi2"] = data.SCSIDevice2 - storageDevices["scsi3"] = data.SCSIDevice3 - storageDevices["scsi4"] = data.SCSIDevice4 - storageDevices["scsi5"] = data.SCSIDevice5 - storageDevices["scsi6"] = data.SCSIDevice6 - storageDevices["scsi7"] = data.SCSIDevice7 - storageDevices["scsi8"] = data.SCSIDevice8 - storageDevices["scsi9"] = data.SCSIDevice9 - storageDevices["scsi10"] = data.SCSIDevice10 - storageDevices["scsi11"] = data.SCSIDevice11 - storageDevices["scsi12"] = data.SCSIDevice12 - storageDevices["scsi13"] = data.SCSIDevice13 - - storageDevices["virtio0"] = data.VirtualIODevice0 - storageDevices["virtio1"] = data.VirtualIODevice1 - storageDevices["virtio2"] = data.VirtualIODevice2 - storageDevices["virtio3"] = data.VirtualIODevice3 - storageDevices["virtio4"] = data.VirtualIODevice4 - storageDevices["virtio5"] = data.VirtualIODevice5 - storageDevices["virtio6"] = data.VirtualIODevice6 - storageDevices["virtio7"] = data.VirtualIODevice7 - storageDevices["virtio8"] = data.VirtualIODevice8 - storageDevices["virtio9"] = data.VirtualIODevice9 - storageDevices["virtio10"] = data.VirtualIODevice10 - storageDevices["virtio11"] = data.VirtualIODevice11 - storageDevices["virtio12"] = data.VirtualIODevice12 - storageDevices["virtio13"] = data.VirtualIODevice13 - storageDevices["virtio14"] = data.VirtualIODevice14 - storageDevices["virtio15"] = data.VirtualIODevice15 - - for key, value := range storageDevices { - if value != nil { - tmpKey := key - value.Interface = &tmpKey +func getDiskInfo(vm *proxmox.VirtualEnvironmentVMGetResponseData, d *schema.ResourceData) map[string]*proxmox.CustomStorageDevice { + currentDisk := d.Get(mkResourceVirtualEnvironmentVMDisk) + + currentDiskList := currentDisk.([]interface{}) + currentDiskMap := map[string]map[string]interface{}{} + + for _, v := range currentDiskList { + diskMap := v.(map[string]interface{}) + diskInterface := diskMap[mkResourcevirtualEnvironmentVMDiskInterface].(string) + + currentDiskMap[diskInterface] = diskMap + } + + storageDevices := map[string]*proxmox.CustomStorageDevice{} + + storageDevices["ide0"] = vm.IDEDevice0 + storageDevices["ide1"] = vm.IDEDevice1 + storageDevices["ide2"] = vm.IDEDevice2 + + storageDevices["sata0"] = vm.SATADevice0 + storageDevices["sata1"] = vm.SATADevice1 + storageDevices["sata2"] = vm.SATADevice2 + storageDevices["sata3"] = vm.SATADevice3 + storageDevices["sata4"] = vm.SATADevice4 + storageDevices["sata5"] = vm.SATADevice5 + + storageDevices["scsi0"] = vm.SCSIDevice0 + storageDevices["scsi1"] = vm.SCSIDevice1 + storageDevices["scsi2"] = vm.SCSIDevice2 + storageDevices["scsi3"] = vm.SCSIDevice3 + storageDevices["scsi4"] = vm.SCSIDevice4 + storageDevices["scsi5"] = vm.SCSIDevice5 + storageDevices["scsi6"] = vm.SCSIDevice6 + storageDevices["scsi7"] = vm.SCSIDevice7 + storageDevices["scsi8"] = vm.SCSIDevice8 + storageDevices["scsi9"] = vm.SCSIDevice9 + storageDevices["scsi10"] = vm.SCSIDevice10 + storageDevices["scsi11"] = vm.SCSIDevice11 + storageDevices["scsi12"] = vm.SCSIDevice12 + storageDevices["scsi13"] = vm.SCSIDevice13 + + storageDevices["virtio0"] = vm.VirtualIODevice0 + storageDevices["virtio1"] = vm.VirtualIODevice1 + storageDevices["virtio2"] = vm.VirtualIODevice2 + storageDevices["virtio3"] = vm.VirtualIODevice3 + storageDevices["virtio4"] = vm.VirtualIODevice4 + storageDevices["virtio5"] = vm.VirtualIODevice5 + storageDevices["virtio6"] = vm.VirtualIODevice6 + storageDevices["virtio7"] = vm.VirtualIODevice7 + storageDevices["virtio8"] = vm.VirtualIODevice8 + storageDevices["virtio9"] = vm.VirtualIODevice9 + storageDevices["virtio10"] = vm.VirtualIODevice10 + storageDevices["virtio11"] = vm.VirtualIODevice11 + storageDevices["virtio12"] = vm.VirtualIODevice12 + storageDevices["virtio13"] = vm.VirtualIODevice13 + storageDevices["virtio14"] = vm.VirtualIODevice14 + storageDevices["virtio15"] = vm.VirtualIODevice15 + + for k, v := range storageDevices { + if v != nil { + if currentDiskMap[k] != nil { + if currentDiskMap[k][mkResourceVirtualEnvironmentVMDiskFileID] != nil { + fileID := currentDiskMap[k][mkResourceVirtualEnvironmentVMDiskFileID].(string) + v.FileID = &fileID + } + } + + v.Interface = &k } } From fc655f236e5762e302070f23d576082e9b8f423e Mon Sep 17 00:00:00 2001 From: Dan Petersen Date: Sat, 13 Feb 2021 07:24:46 +0100 Subject: [PATCH 3/4] fix: update changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 670eb96..40e04be 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -51,7 +51,7 @@ BUG FIXES: * resource/virtual_environment_container: Fix VM ID collision when `vm_id` is not specified * resource/virtual_environment_vm: Fix VM ID collision when `vm_id` is not specified * resource/virtual_environment_vm: Fix disk import issue when importing from directory-based datastores -* resource/virtual_environment/vm: Fix handling of storage name - correct handling of `-` +* resource/virtual_environment_vm: Fix handling of storage name - correct handling of `-` WORKAROUNDS: From 5871fff2009ec30f6a28967dad5b5fa810f432f7 Mon Sep 17 00:00:00 2001 From: Dan Petersen Date: Sat, 13 Feb 2021 08:21:37 +0100 Subject: [PATCH 4/4] fix: disk resizing issue --- CHANGELOG.md | 1 + proxmoxtf/resource_virtual_environment_vm.go | 24 ++++++++++++++++---- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 40e04be..f81521f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ BUG FIXES: * resource/virtual_environment_vm: Fix `disk.file_id` diff issue +* resource/virtual_environment_vm: Fix disk resizing issue OTHER: diff --git a/proxmoxtf/resource_virtual_environment_vm.go b/proxmoxtf/resource_virtual_environment_vm.go index 60adae1..ddf9169 100644 --- a/proxmoxtf/resource_virtual_environment_vm.go +++ b/proxmoxtf/resource_virtual_environment_vm.go @@ -1413,6 +1413,7 @@ func resourceVirtualEnvironmentVMCreateClone(d *schema.ResourceData, m interface if currentDiskInfo == nil { diskUpdateBody := &proxmox.VirtualEnvironmentVMUpdateRequestBody{} prefix := diskDigitPrefix(diskInterface) + switch prefix { case "virtio": if diskUpdateBody.VirtualIODevices == nil { @@ -1432,6 +1433,7 @@ func resourceVirtualEnvironmentVMCreateClone(d *schema.ResourceData, m interface } err = veClient.UpdateVM(nodeName, vmID, diskUpdateBody) + if err != nil { return err } @@ -1450,6 +1452,7 @@ func resourceVirtualEnvironmentVMCreateClone(d *schema.ResourceData, m interface } deleteOriginalDisk := proxmox.CustomBool(true) + diskMoveBody := &proxmox.VirtualEnvironmentVMMoveDiskRequestBody{ DeleteOriginalDisk: &deleteOriginalDisk, Disk: diskInterface, @@ -1461,7 +1464,18 @@ func resourceVirtualEnvironmentVMCreateClone(d *schema.ResourceData, m interface Size: fmt.Sprintf("%dG", diskSize), } + moveDisk := false + if dataStoreID != "" { + moveDisk = true + + if allDiskInfo[diskInterface] != nil { + fileIDParts := strings.Split(allDiskInfo[diskInterface].FileVolume, ":") + moveDisk = dataStoreID != fileIDParts[0] + } + } + + if moveDisk { moveDiskTimeout := d.Get(mkResourceVirtualEnvironmentVMTimeoutMoveDisk).(int) err = veClient.MoveVMDisk(nodeName, vmID, diskMoveBody, moveDiskTimeout) @@ -1470,10 +1484,12 @@ func resourceVirtualEnvironmentVMCreateClone(d *schema.ResourceData, m interface } } - err = veClient.ResizeVMDisk(nodeName, vmID, diskResizeBody) + if diskSize > compareNumber { + err = veClient.ResizeVMDisk(nodeName, vmID, diskResizeBody) - if err != nil { - return err + if err != nil { + return err + } } } @@ -3649,7 +3665,7 @@ func resourceVirtualEnvironmentVMUpdateDiskLocationAndSize(d *schema.ResourceDat return fmt.Errorf("Deletion of disks not supported. Please delete disk by hand. Old Interface was %s", *oldDisk.Interface) } - if oldDisk.ID != diskNewEntries[prefix][oldKey].ID { + if *oldDisk.ID != *diskNewEntries[prefix][oldKey].ID { deleteOriginalDisk := proxmox.CustomBool(true) diskMoveBodies = append(diskMoveBodies, &proxmox.VirtualEnvironmentVMMoveDiskRequestBody{