0
0
mirror of https://github.com/bpg/terraform-provider-proxmox.git synced 2025-07-04 04:22:59 +00:00

fix(vm): type error when unmarshalling GetResponseData.data.memory (#728)

* fix(vm): type error when unmarshalling `GetResponseData.data.memory`

Signed-off-by: Pavel Boldyrev <627562+bpg@users.noreply.github.com>

* linter

Signed-off-by: Pavel Boldyrev <627562+bpg@users.noreply.github.com>

---------

Signed-off-by: Pavel Boldyrev <627562+bpg@users.noreply.github.com>
This commit is contained in:
Pavel Boldyrev 2023-11-17 18:39:13 -05:00 committed by GitHub
parent 4faf993b82
commit b429f95ca5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 32 additions and 20 deletions

View File

@ -255,7 +255,8 @@ func (m *clusterOptionsModel) importFromOptionsAPI(
m.Language = types.StringPointerValue(opts.Language) m.Language = types.StringPointerValue(opts.Language)
if opts.MaxWorkers != nil { if opts.MaxWorkers != nil {
m.MaxWorkers = types.Int64PointerValue(opts.MaxWorkers.PointerInt64()) value := int64(*opts.MaxWorkers)
m.MaxWorkers = types.Int64PointerValue(&value)
} else { } else {
m.MaxWorkers = types.Int64Null() m.MaxWorkers = types.Int64Null()
} }

View File

@ -63,16 +63,16 @@ type OptionsResponseBody struct {
// OptionsResponseData contains the data from a cluster options response. // OptionsResponseData contains the data from a cluster options response.
type OptionsResponseData struct { type OptionsResponseData struct {
optionsBaseData optionsBaseData
MaxWorkers *types.CustomInt `json:"max_workers,omitempty"` MaxWorkers *types.CustomInt64 `json:"max_workers,omitempty"`
ClusterResourceScheduling *crs `json:"crs,omitempty"` ClusterResourceScheduling *crs `json:"crs,omitempty"`
HASettings *haSettings `json:"ha,omitempty"` HASettings *haSettings `json:"ha,omitempty"`
TagStyle *tagStyle `json:"tag-style,omitempty"` TagStyle *tagStyle `json:"tag-style,omitempty"`
Migration *migration `json:"migration,omitempty"` Migration *migration `json:"migration,omitempty"`
Webauthn *webauthn `json:"webauthn,omitempty"` Webauthn *webauthn `json:"webauthn,omitempty"`
NextID *nextID `json:"next-id,omitempty"` NextID *nextID `json:"next-id,omitempty"`
Notify *notify `json:"notify,omitempty"` Notify *notify `json:"notify,omitempty"`
UserTagAccess *userTagAccess `json:"user-tag-access,omitempty"` UserTagAccess *userTagAccess `json:"user-tag-access,omitempty"`
RegisteredTags *[]string `json:"registered-tags,omitempty"` RegisteredTags *[]string `json:"registered-tags,omitempty"`
} }
// OptionsRequestData contains the body for cluster options request. // OptionsRequestData contains the body for cluster options request.

View File

@ -432,11 +432,11 @@ type GetResponseData struct {
CPULimit *types.CustomInt `json:"cpulimit,omitempty"` CPULimit *types.CustomInt `json:"cpulimit,omitempty"`
CPUSockets *int `json:"sockets,omitempty"` CPUSockets *int `json:"sockets,omitempty"`
CPUUnits *int `json:"cpuunits,omitempty"` CPUUnits *int `json:"cpuunits,omitempty"`
DedicatedMemory *int64 `json:"memory,omitempty"` DedicatedMemory *types.CustomInt64 `json:"memory,omitempty"`
DeletionProtection *types.CustomBool `json:"protection,omitempty"` DeletionProtection *types.CustomBool `json:"protection,omitempty"`
Description *string `json:"description,omitempty"` Description *string `json:"description,omitempty"`
EFIDisk *CustomEFIDisk `json:"efidisk0,omitempty"` EFIDisk *CustomEFIDisk `json:"efidisk0,omitempty"`
FloatingMemory *int64 `json:"balloon,omitempty"` FloatingMemory *types.CustomInt64 `json:"balloon,omitempty"`
FloatingMemoryShares *int `json:"shares,omitempty"` FloatingMemoryShares *int `json:"shares,omitempty"`
Freeze *types.CustomBool `json:"freeze,omitempty"` Freeze *types.CustomBool `json:"freeze,omitempty"`
HookScript *string `json:"hookscript,omitempty"` HookScript *string `json:"hookscript,omitempty"`

View File

@ -9,6 +9,7 @@ package types
import ( import (
"bytes" "bytes"
"encoding/json" "encoding/json"
"fmt"
"strconv" "strconv"
"strings" "strings"
"time" "time"
@ -25,6 +26,9 @@ type CustomCommaSeparatedList []string
// CustomInt allows a JSON integer value to also be a string. // CustomInt allows a JSON integer value to also be a string.
type CustomInt int 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. // CustomLineBreakSeparatedList allows a multiline JSON string to also be a string array.
type CustomLineBreakSeparatedList []string type CustomLineBreakSeparatedList []string
@ -106,7 +110,7 @@ func (r *CustomInt) UnmarshalJSON(b []byte) error {
i, err := strconv.ParseInt(s, 10, 32) i, err := strconv.ParseInt(s, 10, 32)
if err != nil { if err != nil {
return err return fmt.Errorf("cannot parse int %q: %w", s, err)
} }
*r = CustomInt(i) *r = CustomInt(i)
@ -114,15 +118,22 @@ func (r *CustomInt) UnmarshalJSON(b []byte) error {
return nil return nil
} }
// PointerInt64 returns a pointer to an int64. // UnmarshalJSON converts a JSON value to an integer.
func (r *CustomInt) PointerInt64() *int64 { func (r *CustomInt64) UnmarshalJSON(b []byte) error {
if r == nil { s := string(b)
return nil
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. // MarshalJSON converts a boolean to a JSON value.