Skip to content

Commit

Permalink
Merge pull request Telmate#1038 from Tinyblargon/pool-type
Browse files Browse the repository at this point in the history
fix: Pool typecast
  • Loading branch information
Tinyblargon authored Jun 8, 2024
2 parents c3b2931 + dac60f7 commit a4d8f3a
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 25 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.21
toolchain go1.21.0

require (
github.com/Telmate/proxmox-api-go v0.0.0-20240515161628-30cfc1aa4ae4
github.com/Telmate/proxmox-api-go v0.0.0-20240608213934-9d245a204c42
github.com/google/uuid v1.6.0
github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320
github.com/hashicorp/terraform-plugin-sdk/v2 v2.34.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ github.com/Microsoft/go-winio v0.6.1 h1:9/kr64B9VUZrLm5YYwbGtUJnMgqWVOdUAXu6Migc
github.com/Microsoft/go-winio v0.6.1/go.mod h1:LRdKpFKfdobln8UmuiYcKPot9D2v6svN5+sAH+4kjUM=
github.com/ProtonMail/go-crypto v1.1.0-alpha.2-proton h1:HKz85FwoXx86kVtTvFke7rgHvq/HoloSUvW5semjFWs=
github.com/ProtonMail/go-crypto v1.1.0-alpha.2-proton/go.mod h1:rA3QumHc/FZ8pAHreoekgiAbzpNsfQAosU5td4SnOrE=
github.com/Telmate/proxmox-api-go v0.0.0-20240515161628-30cfc1aa4ae4 h1:UsCuxsMGA0ePmUBYaYNvh1kFxoZ35ARpHCfEw9KZxec=
github.com/Telmate/proxmox-api-go v0.0.0-20240515161628-30cfc1aa4ae4/go.mod h1:bscBzOUx0tJAdVGmQvcnoWPg5eI2eJ6anJKV1ueZ1oU=
github.com/Telmate/proxmox-api-go v0.0.0-20240608213934-9d245a204c42 h1:wDo4xTIS+h2hF2m06Gz/Jw0F8fuczh4dZSYgDNEZ7BU=
github.com/Telmate/proxmox-api-go v0.0.0-20240608213934-9d245a204c42/go.mod h1:bscBzOUx0tJAdVGmQvcnoWPg5eI2eJ6anJKV1ueZ1oU=
github.com/agext/levenshtein v1.2.3 h1:YB2fHEn0UJagG8T1rrWknE3ZQzWM06O8AMAatNn7lmo=
github.com/agext/levenshtein v1.2.3/go.mod h1:JEDfjyjHDjOF/1e4FlBE/PkbqA9OfWu2ki2W0IB5558=
github.com/apparentlymart/go-textseg/v12 v12.0.0/go.mod h1:S/4uRK2UtaQttw1GenVJEynmyUenKwP++x/+DdGV/Ec=
Expand Down
4 changes: 2 additions & 2 deletions proxmox/resource_lxc.go
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ func resourceLxcCreate(d *schema.ResourceData, meta interface{}) error {
config.OnBoot = d.Get("onboot").(bool)
config.OsType = d.Get("ostype").(string)
config.Password = d.Get("password").(string)
config.Pool = d.Get("pool").(string)
config.Pool = pointer(pxapi.PoolName(d.Get("pool").(string)))
config.Protection = d.Get("protection").(bool)
config.Restore = d.Get("restore").(bool)
config.SearchDomain = d.Get("searchdomain").(string)
Expand Down Expand Up @@ -651,7 +651,7 @@ func resourceLxcUpdate(d *schema.ResourceData, meta interface{}) error {
config.OnBoot = d.Get("onboot").(bool)
config.OsType = d.Get("ostype").(string)
config.Password = d.Get("password").(string)
config.Pool = d.Get("pool").(string)
config.Pool = pointer(pxapi.PoolName(d.Get("pool").(string)))
config.Protection = d.Get("protection").(bool)
config.Restore = d.Get("restore").(bool)
config.SearchDomain = d.Get("searchdomain").(string)
Expand Down
16 changes: 10 additions & 6 deletions proxmox/resource_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package proxmox
import (
"fmt"

pxapi "github.com/Telmate/proxmox-api-go/proxmox"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

Expand Down Expand Up @@ -42,9 +43,11 @@ func resourcePoolCreate(d *schema.ResourceData, meta interface{}) error {
defer lock.unlock()

poolid := d.Get("poolid").(string)
comment := d.Get("comment").(string)

err := client.CreatePool(poolid, comment)
err := pxapi.ConfigPool{
Name: pxapi.PoolName(poolid),
Comment: pointer(d.Get("comment").(string)),
}.Create(client)
if err != nil {
return err
}
Expand Down Expand Up @@ -107,8 +110,10 @@ func resourcePoolUpdate(d *schema.ResourceData, meta interface{}) error {
logger.Info().Str("poolid", poolID).Msg("Starting update of the Pool resource")

if d.HasChange("comment") {
nextComment := d.Get("comment").(string)
err := client.UpdatePoolComment(poolID, nextComment)
err := pxapi.ConfigPool{
Name: pxapi.PoolName(poolID),
Comment: pointer(d.Get("comment").(string)),
}.Update(client)
if err != nil {
return err
}
Expand All @@ -128,8 +133,7 @@ func resourcePoolDelete(d *schema.ResourceData, meta interface{}) error {
if err != nil {
return err
}
err = client.DeletePool(poolID)
if err != nil {
if err = pxapi.PoolName(poolID).Delete(client); err != nil {
return err
}

Expand Down
24 changes: 12 additions & 12 deletions proxmox/resource_vm_qemu.go
Original file line number Diff line number Diff line change
Expand Up @@ -872,12 +872,12 @@ func resourceVmQemuCreate(ctx context.Context, d *schema.ResourceData, meta inte
config := pxapi.ConfigQemu{
Name: vmName,
Description: d.Get("desc").(string),
Pool: d.Get("pool").(string),
Pool: pointer(pxapi.PoolName(d.Get("pool").(string))),
Bios: d.Get("bios").(string),
Onboot: BoolPointer(d.Get("onboot").(bool)),
Onboot: pointer(d.Get("onboot").(bool)),
Startup: d.Get("startup").(string),
Protection: BoolPointer(d.Get("protection").(bool)),
Tablet: BoolPointer(d.Get("tablet").(bool)),
Protection: pointer(d.Get("protection").(bool)),
Tablet: pointer(d.Get("tablet").(bool)),
Boot: d.Get("boot").(string),
BootDisk: d.Get("bootdisk").(string),
Agent: mapToStruct_QemuGuestAgent(d),
Expand All @@ -888,8 +888,8 @@ func resourceVmQemuCreate(ctx context.Context, d *schema.ResourceData, meta inte
QemuSockets: d.Get("sockets").(int),
QemuVcpus: d.Get("vcpus").(int),
QemuCpu: d.Get("cpu").(string),
QemuNuma: BoolPointer(d.Get("numa").(bool)),
QemuKVM: BoolPointer(d.Get("kvm").(bool)),
QemuNuma: pointer(d.Get("numa").(bool)),
QemuKVM: pointer(d.Get("kvm").(bool)),
Hotplug: d.Get("hotplug").(string),
Scsihw: d.Get("scsihw").(string),
HaState: d.Get("hastate").(string),
Expand Down Expand Up @@ -1148,12 +1148,12 @@ func resourceVmQemuUpdate(ctx context.Context, d *schema.ResourceData, meta inte
config := pxapi.ConfigQemu{
Name: d.Get("name").(string),
Description: d.Get("desc").(string),
Pool: d.Get("pool").(string),
Pool: pointer(pxapi.PoolName(d.Get("pool").(string))),
Bios: d.Get("bios").(string),
Onboot: BoolPointer(d.Get("onboot").(bool)),
Onboot: pointer(d.Get("onboot").(bool)),
Startup: d.Get("startup").(string),
Protection: BoolPointer(d.Get("protection").(bool)),
Tablet: BoolPointer(d.Get("tablet").(bool)),
Protection: pointer(d.Get("protection").(bool)),
Tablet: pointer(d.Get("tablet").(bool)),
Boot: d.Get("boot").(string),
BootDisk: d.Get("bootdisk").(string),
Agent: mapToStruct_QemuGuestAgent(d),
Expand All @@ -1164,8 +1164,8 @@ func resourceVmQemuUpdate(ctx context.Context, d *schema.ResourceData, meta inte
QemuSockets: d.Get("sockets").(int),
QemuVcpus: d.Get("vcpus").(int),
QemuCpu: d.Get("cpu").(string),
QemuNuma: BoolPointer(d.Get("numa").(bool)),
QemuKVM: BoolPointer(d.Get("kvm").(bool)),
QemuNuma: pointer(d.Get("numa").(bool)),
QemuKVM: pointer(d.Get("kvm").(bool)),
Hotplug: d.Get("hotplug").(string),
Scsihw: d.Get("scsihw").(string),
HaState: d.Get("hastate").(string),
Expand Down
4 changes: 2 additions & 2 deletions proxmox/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -479,8 +479,8 @@ func testOptionalArguments(t *testing.T, s *schema.Resource) {
}
}

func BoolPointer(b bool) *bool {
return &b
func pointer[T any](item T) *T {
return &item
}

func permissions_check(s1 []string, s2 []string) []string {
Expand Down

0 comments on commit a4d8f3a

Please sign in to comment.