diff --git a/proxmox/resource_lxc.go b/proxmox/resource_lxc.go index 2ebcaa8..8becd25 100644 --- a/proxmox/resource_lxc.go +++ b/proxmox/resource_lxc.go @@ -71,6 +71,11 @@ func resourceLxc() *schema.Resource { Type: schema.TypeString, Optional: true, }, + "force": { + Type: schema.TypeBool, + Optional: true, + Default: false, + }, }, } } @@ -81,16 +86,15 @@ func resourceLxcCreate(d *schema.ResourceData, meta interface{}) error { client := pconf.Client vmName := d.Get("hostname").(string) networks := d.Get("networks").(*schema.Set) - lxcNetworks := lxcDevicesSetToMap(networks) + lxcNetworks := DevicesSetToMap(networks) - config := pxapi.ConfigLxc{ - Ostemplate: d.Get("ostemplate").(string), - Storage: d.Get("storage").(string), - Pool: d.Get("pool").(string), - Password: d.Get("password").(string), - Hostname: vmName, - Networks: lxcNetworks, - } + config := pxapi.NewConfigLxc() + config.Ostemplate = d.Get("ostemplate").(string) + config.Hostname = vmName + config.Networks = lxcNetworks + config.Password = d.Get("password").(string) + config.Pool = d.Get("pool").(string) + config.Storage = d.Get("storage").(string) targetNode := d.Get("target_node").(string) //vmr, _ := client.GetVmRefByName(vmName) @@ -126,17 +130,3 @@ func resourceLxcRead(d *schema.ResourceData, meta interface{}) error { func resourceLxcDelete(d *schema.ResourceData, meta interface{}) error { return nil } - -func lxcDevicesSetToMap(devicesSet *schema.Set) pxapi.LxcDevices { - - devicesMap := pxapi.LxcDevices{} - - for _, set := range devicesSet.List() { - setMap, isMap := set.(map[string]interface{}) - if isMap { - setID := setMap["id"].(int) - devicesMap[setID] = setMap - } - } - return devicesMap -} diff --git a/proxmox/resource_vm_qemu.go b/proxmox/resource_vm_qemu.go index c915af9..83267d0 100644 --- a/proxmox/resource_vm_qemu.go +++ b/proxmox/resource_vm_qemu.go @@ -354,9 +354,9 @@ func resourceVmQemuCreate(d *schema.ResourceData, meta interface{}) error { client := pconf.Client vmName := d.Get("name").(string) networks := d.Get("network").(*schema.Set) - qemuNetworks := devicesSetToMap(networks) + qemuNetworks := DevicesSetToMap(networks) disks := d.Get("disk").(*schema.Set) - qemuDisks := devicesSetToMap(disks) + qemuDisks := DevicesSetToMap(disks) config := pxapi.ConfigQemu{ Name: vmName, @@ -504,9 +504,9 @@ func resourceVmQemuUpdate(d *schema.ResourceData, meta interface{}) error { return err } configDisksSet := d.Get("disk").(*schema.Set) - qemuDisks := devicesSetToMap(configDisksSet) + qemuDisks := DevicesSetToMap(configDisksSet) configNetworksSet := d.Get("network").(*schema.Set) - qemuNetworks := devicesSetToMap(configNetworksSet) + qemuNetworks := DevicesSetToMap(configNetworksSet) config := pxapi.ConfigQemu{ Name: d.Get("name").(string), @@ -706,7 +706,7 @@ func diskSizeGB(dcSize interface{}) float64 { // Converting from schema.TypeSet to map of id and conf for each device, // which will be sent to Proxmox API. -func devicesSetToMap(devicesSet *schema.Set) pxapi.QemuDevices { +func DevicesSetToMap(devicesSet *schema.Set) pxapi.QemuDevices { devicesMap := pxapi.QemuDevices{} @@ -727,7 +727,7 @@ func updateDevicesSet( devicesMap pxapi.QemuDevices, ) *schema.Set { - configDevicesMap := devicesSetToMap(devicesSet) + configDevicesMap := DevicesSetToMap(devicesSet) activeDevicesMap := updateDevicesDefaults(devicesMap, configDevicesMap) for _, setConf := range devicesSet.List() {