diff --git a/fwprovider/resource_options.go b/fwprovider/resource_options.go index 8ed001b6..d49d5c63 100644 --- a/fwprovider/resource_options.go +++ b/fwprovider/resource_options.go @@ -255,7 +255,8 @@ func (m *clusterOptionsModel) importFromOptionsAPI( m.Language = types.StringPointerValue(opts.Language) if opts.MaxWorkers != nil { - m.MaxWorkers = types.Int64PointerValue(opts.MaxWorkers.PointerInt64()) + value := int64(*opts.MaxWorkers) + m.MaxWorkers = types.Int64PointerValue(&value) } else { m.MaxWorkers = types.Int64Null() } diff --git a/proxmox/cluster/options_types.go b/proxmox/cluster/options_types.go index 8de486bb..4647bda7 100644 --- a/proxmox/cluster/options_types.go +++ b/proxmox/cluster/options_types.go @@ -63,16 +63,16 @@ type OptionsResponseBody struct { // OptionsResponseData contains the data from a cluster options response. type OptionsResponseData struct { optionsBaseData - MaxWorkers *types.CustomInt `json:"max_workers,omitempty"` - ClusterResourceScheduling *crs `json:"crs,omitempty"` - HASettings *haSettings `json:"ha,omitempty"` - TagStyle *tagStyle `json:"tag-style,omitempty"` - Migration *migration `json:"migration,omitempty"` - Webauthn *webauthn `json:"webauthn,omitempty"` - NextID *nextID `json:"next-id,omitempty"` - Notify *notify `json:"notify,omitempty"` - UserTagAccess *userTagAccess `json:"user-tag-access,omitempty"` - RegisteredTags *[]string `json:"registered-tags,omitempty"` + MaxWorkers *types.CustomInt64 `json:"max_workers,omitempty"` + ClusterResourceScheduling *crs `json:"crs,omitempty"` + HASettings *haSettings `json:"ha,omitempty"` + TagStyle *tagStyle `json:"tag-style,omitempty"` + Migration *migration `json:"migration,omitempty"` + Webauthn *webauthn `json:"webauthn,omitempty"` + NextID *nextID `json:"next-id,omitempty"` + Notify *notify `json:"notify,omitempty"` + UserTagAccess *userTagAccess `json:"user-tag-access,omitempty"` + RegisteredTags *[]string `json:"registered-tags,omitempty"` } // OptionsRequestData contains the body for cluster options request. diff --git a/proxmox/nodes/vms/vms_types.go b/proxmox/nodes/vms/vms_types.go index 8c59f3ca..11c36d79 100644 --- a/proxmox/nodes/vms/vms_types.go +++ b/proxmox/nodes/vms/vms_types.go @@ -432,11 +432,11 @@ type GetResponseData struct { CPULimit *types.CustomInt `json:"cpulimit,omitempty"` CPUSockets *int `json:"sockets,omitempty"` CPUUnits *int `json:"cpuunits,omitempty"` - DedicatedMemory *int64 `json:"memory,omitempty"` + DedicatedMemory *types.CustomInt64 `json:"memory,omitempty"` DeletionProtection *types.CustomBool `json:"protection,omitempty"` Description *string `json:"description,omitempty"` EFIDisk *CustomEFIDisk `json:"efidisk0,omitempty"` - FloatingMemory *int64 `json:"balloon,omitempty"` + FloatingMemory *types.CustomInt64 `json:"balloon,omitempty"` FloatingMemoryShares *int `json:"shares,omitempty"` Freeze *types.CustomBool `json:"freeze,omitempty"` HookScript *string `json:"hookscript,omitempty"` diff --git a/proxmox/types/common_types.go b/proxmox/types/common_types.go index 5eb3f22a..7b579667 100644 --- a/proxmox/types/common_types.go +++ b/proxmox/types/common_types.go @@ -9,6 +9,7 @@ package types import ( "bytes" "encoding/json" + "fmt" "strconv" "strings" "time" @@ -25,6 +26,9 @@ type CustomCommaSeparatedList []string // CustomInt allows a JSON integer value to also be a string. type CustomInt int +// CustomInt64 allows a JSON int64 value to also be a string. +type CustomInt64 int64 + // CustomLineBreakSeparatedList allows a multiline JSON string to also be a string array. type CustomLineBreakSeparatedList []string @@ -106,7 +110,7 @@ func (r *CustomInt) UnmarshalJSON(b []byte) error { i, err := strconv.ParseInt(s, 10, 32) if err != nil { - return err + return fmt.Errorf("cannot parse int %q: %w", s, err) } *r = CustomInt(i) @@ -114,15 +118,22 @@ func (r *CustomInt) UnmarshalJSON(b []byte) error { return nil } -// PointerInt64 returns a pointer to an int64. -func (r *CustomInt) PointerInt64() *int64 { - if r == nil { - return nil +// UnmarshalJSON converts a JSON value to an integer. +func (r *CustomInt64) UnmarshalJSON(b []byte) error { + s := string(b) + + if strings.HasPrefix(s, "\"") && strings.HasSuffix(s, "\"") { + s = s[1 : len(s)-1] } - i := int64(*r) + i, err := strconv.ParseInt(s, 10, 64) + if err != nil { + return fmt.Errorf("cannot parse int64 %q: %w", s, err) + } - return &i + *r = CustomInt64(i) + + return nil } // MarshalJSON converts a boolean to a JSON value.