From 2e6c91688027a0c0e093c2f66a53c3b14a77841b Mon Sep 17 00:00:00 2001 From: halradaideh Date: Sat, 6 Dec 2025 17:30:46 +0300 Subject: [PATCH 1/2] feat: add host_managed field to LXC network schema - Add host_managed as optional computed field in network schema - Allows provider to handle Proxmox 9.1+ OCI containers - Fixes: proxmox API returned new parameter 'host-managed' error Proxmox 9.1 automatically sets host-managed=1 for OCI-based LXC containers. This change allows the provider to recognize and handle this parameter without throwing an error. Related SDK change: https://github.com/Telmate/proxmox-api-go/commit/[SDK_COMMIT] --- proxmox/resource_lxc.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/proxmox/resource_lxc.go b/proxmox/resource_lxc.go index b1573aeb..e0b25f2f 100644 --- a/proxmox/resource_lxc.go +++ b/proxmox/resource_lxc.go @@ -297,6 +297,11 @@ func resourceLxc() *schema.Resource { Optional: true, Computed: true, }, + "host_managed": { + Type: schema.TypeBool, + Optional: true, + Computed: true, + }, }, }, }, From 9d174b35ddab55a631beadd090e71849ee7374c3 Mon Sep 17 00:00:00 2001 From: halradaideh Date: Sat, 6 Dec 2025 18:04:54 +0300 Subject: [PATCH 2/2] feat: add key normalization and type conversion for LXC networks - Update AssertNoNonSchemaValues() to handle hyphenated API keys - Normalize keys in adaptDeviceToConf() (hyphen to underscore) - Normalize keys and convert int to bool in FlattenDevicesList() - Add local SDK reference for testing This enables support for Proxmox 9.1 parameters like host-managed while maintaining backward compatibility with existing configurations. --- proxmox/resource_vm_qemu.go | 10 +++++++++- proxmox/util.go | 30 +++++++++++++++++++++--------- 2 files changed, 30 insertions(+), 10 deletions(-) diff --git a/proxmox/resource_vm_qemu.go b/proxmox/resource_vm_qemu.go index 588f6927..26fd28d2 100755 --- a/proxmox/resource_vm_qemu.go +++ b/proxmox/resource_vm_qemu.go @@ -1174,7 +1174,15 @@ func FlattenDevicesList(proxmoxDevices pveSDK.QemuDevices) ([]map[string]interfa } for configuration, value := range thisDevice { - thisFlattenedDevice[configuration] = value + // Normalize key: replace hyphens with underscores for Terraform schema compatibility + normalizedKey := strings.ReplaceAll(configuration, "-", "_") + + // Convert integer values to bool for boolean fields (e.g., host_managed: "1" -> true) + if intVal, ok := value.(int); ok && (normalizedKey == "host_managed" || normalizedKey == "firewall") { + thisFlattenedDevice[normalizedKey] = intVal == 1 + } else { + thisFlattenedDevice[normalizedKey] = value + } } flattenedDevices = append(flattenedDevices, thisFlattenedDevice) diff --git a/proxmox/util.go b/proxmox/util.go index 8d1b2f58..c9848cf8 100644 --- a/proxmox/util.go +++ b/proxmox/util.go @@ -7,6 +7,7 @@ import ( "os" "regexp" "strconv" + "strings" "testing" "time" @@ -293,12 +294,20 @@ func AssertNoNonSchemaValues( // the keys in our resource schema. if they aren't things fail in a very weird and hidden way for _, deviceEntry := range devices { for key := range deviceEntry { - if _, ok := schemaDef.Elem.(*schema.Resource).Schema[key]; !ok { - if key == "id" { // we purposely ignore id here as that is implied by the order in the TypeList/QemuDevice(list) - continue - } - return fmt.Errorf("proxmox provider error: proxmox API returned new parameter '%v' we cannot process", key) + // First try exact match + if _, ok := schemaDef.Elem.(*schema.Resource).Schema[key]; ok { + continue + } + // Try with underscores instead of hyphens (for keys like "host-managed" -> "host_managed") + keyWithUnderscore := strings.ReplaceAll(key, "-", "_") + if _, ok := schemaDef.Elem.(*schema.Resource).Schema[keyWithUnderscore]; ok { + continue + } + // Ignore "id" as it's implied by the order in the TypeList + if key == "id" { + continue } + return fmt.Errorf("proxmox provider error: proxmox API returned new parameter '%v' we cannot process", key) } } @@ -312,10 +321,13 @@ func adaptDeviceToConf( ) map[string]interface{} { // Value type should be one of types allowed by Terraform schema types. for key, value := range device { + // Normalize key: replace hyphens with underscores for Terraform schema compatibility + normalizedKey := strings.ReplaceAll(key, "-", "_") + // This nested switch is used for nested config like in `net[n]`, // where Proxmox uses `key=<0|1>` in string" at the same time // a boolean could be used in ".tf" files. - switch conf[key].(type) { + switch conf[normalizedKey].(type) { case bool: switch value := value.(type) { // If the key is bool and value is int (which comes from Proxmox API), @@ -324,15 +336,15 @@ func adaptDeviceToConf( sValue := strconv.Itoa(value) bValue, err := strconv.ParseBool(sValue) if err == nil { - conf[key] = bValue + conf[normalizedKey] = bValue } // If value is bool, which comes from Terraform conf, add it directly. case bool: - conf[key] = value + conf[normalizedKey] = value } // Anything else will be added as it is. default: - conf[key] = value + conf[normalizedKey] = value } }