mirror of
https://github.com/letic/terraform-provider-proxmox.git
synced 2024-09-28 22:16:03 +00:00
Merge pull request #102 from in0rdr/fix/issues/44/remove_id
LXC: Remove Device IDs
This commit is contained in:
commit
05fe0fbdb7
@ -12,7 +12,6 @@ resource "proxmox_lxc" "lxc-test" {
|
||||
}
|
||||
hostname = "terraform-new-container"
|
||||
network {
|
||||
id = 0
|
||||
name = "eth0"
|
||||
bridge = "vmbr0"
|
||||
ip = "dhcp"
|
||||
|
@ -112,10 +112,6 @@ func resourceLxc() *schema.Resource {
|
||||
Optional: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"id": {
|
||||
Type: schema.TypeInt,
|
||||
Required: true,
|
||||
},
|
||||
"volume": {
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
@ -160,10 +156,6 @@ func resourceLxc() *schema.Resource {
|
||||
Optional: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"id": {
|
||||
Type: schema.TypeInt,
|
||||
Required: true,
|
||||
},
|
||||
"name": {
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
@ -342,14 +334,18 @@ func resourceLxcCreate(d *schema.ResourceData, meta interface{}) error {
|
||||
// proxmox api allows multiple mountpoint sets,
|
||||
// having a unique 'id' parameter foreach set
|
||||
mountpoints := d.Get("mountpoint").(*schema.Set)
|
||||
lxcMountpoints := DevicesSetToMap(mountpoints)
|
||||
if len(mountpoints.List()) > 0 {
|
||||
lxcMountpoints := DevicesSetToMapWithoutId(mountpoints)
|
||||
config.Mountpoints = lxcMountpoints
|
||||
}
|
||||
config.Nameserver = d.Get("nameserver").(string)
|
||||
// proxmox api allows multiple network sets,
|
||||
// having a unique 'id' parameter foreach set
|
||||
networks := d.Get("network").(*schema.Set)
|
||||
lxcNetworks := DevicesSetToMap(networks)
|
||||
if len(networks.List()) > 0 {
|
||||
lxcNetworks := DevicesSetToMapWithoutId(networks)
|
||||
config.Networks = lxcNetworks
|
||||
}
|
||||
config.OnBoot = d.Get("onboot").(bool)
|
||||
config.OsType = d.Get("ostype").(string)
|
||||
config.Password = d.Get("password").(string)
|
||||
@ -442,14 +438,18 @@ func resourceLxcUpdate(d *schema.ResourceData, meta interface{}) error {
|
||||
// proxmox api allows multiple mountpoint sets,
|
||||
// having a unique 'id' parameter foreach set
|
||||
mountpoints := d.Get("mountpoint").(*schema.Set)
|
||||
lxcMountpoints := DevicesSetToMap(mountpoints)
|
||||
if len(mountpoints.List()) > 0 {
|
||||
lxcMountpoints := DevicesSetToMapWithoutId(mountpoints)
|
||||
config.Mountpoints = lxcMountpoints
|
||||
}
|
||||
config.Nameserver = d.Get("nameserver").(string)
|
||||
// proxmox api allows multiple network sets,
|
||||
// having a unique 'id' parameter foreach set
|
||||
networks := d.Get("network").(*schema.Set)
|
||||
lxcNetworks := DevicesSetToMap(networks)
|
||||
if len(networks.List()) > 0 {
|
||||
lxcNetworks := DevicesSetToMapWithoutId(networks)
|
||||
config.Networks = lxcNetworks
|
||||
}
|
||||
config.OnBoot = d.Get("onboot").(bool)
|
||||
config.OsType = d.Get("ostype").(string)
|
||||
config.Password = d.Get("password").(string)
|
||||
@ -532,14 +532,22 @@ func resourceLxcRead(d *schema.ResourceData, meta interface{}) error {
|
||||
d.Set("memory", config.Memory)
|
||||
|
||||
configMountpointSet := d.Get("mountpoint").(*schema.Set)
|
||||
configMountpointSet = AddIds(configMountpointSet)
|
||||
if len(configMountpointSet.List()) > 0 {
|
||||
activeMountpointSet := UpdateDevicesSet(configMountpointSet, config.Mountpoints)
|
||||
activeMountpointSet = RemoveIds(activeMountpointSet)
|
||||
d.Set("mountpoint", activeMountpointSet)
|
||||
}
|
||||
|
||||
d.Set("nameserver", config.Nameserver)
|
||||
|
||||
configNetworksSet := d.Get("network").(*schema.Set)
|
||||
configNetworksSet = AddIds(configNetworksSet)
|
||||
if len(configNetworksSet.List()) > 0 {
|
||||
activeNetworksSet := UpdateDevicesSet(configNetworksSet, config.Networks)
|
||||
activeNetworksSet = RemoveIds(activeNetworksSet)
|
||||
d.Set("network", activeNetworksSet)
|
||||
}
|
||||
|
||||
d.Set("onboot", config.OnBoot)
|
||||
d.Set("ostemplate", config.Ostemplate)
|
||||
|
@ -31,3 +31,41 @@ func UpdateDeviceConfDefaults(
|
||||
return defaultDeviceConf
|
||||
}
|
||||
|
||||
func DevicesSetToMapWithoutId(devicesSet *schema.Set) pxapi.QemuDevices {
|
||||
|
||||
devicesMap := pxapi.QemuDevices{}
|
||||
i := 1
|
||||
for _, set := range devicesSet.List() {
|
||||
setMap, isMap := set.(map[string]interface{})
|
||||
if isMap {
|
||||
// setMap["id"] = i
|
||||
devicesMap[i] = setMap
|
||||
i += 1
|
||||
}
|
||||
}
|
||||
return devicesMap
|
||||
}
|
||||
|
||||
func AddIds(configSet *schema.Set) *schema.Set {
|
||||
// add device config ids
|
||||
var i = 1
|
||||
for _, setConf := range configSet.List() {
|
||||
configSet.Remove(setConf)
|
||||
setConfMap := setConf.(map[string]interface{})
|
||||
setConfMap["id"] = i
|
||||
i += 1
|
||||
configSet.Add(setConfMap)
|
||||
}
|
||||
return configSet
|
||||
}
|
||||
|
||||
func RemoveIds(configSet *schema.Set) *schema.Set {
|
||||
// remove device config ids
|
||||
for _, setConf := range configSet.List() {
|
||||
configSet.Remove(setConf)
|
||||
setConfMap := setConf.(map[string]interface{})
|
||||
delete(setConfMap, "id")
|
||||
configSet.Add(setConfMap)
|
||||
}
|
||||
return configSet
|
||||
}
|
Loading…
Reference in New Issue
Block a user