Skip to content

Commit

Permalink
feat: overhaul qemu disks implementation (#892)
Browse files Browse the repository at this point in the history
* feat: re-implement the way qemu disks are handled

These changes were pulled from Tinyblargon's branch which was out of sync
with the Telmate master branch. I merely dealt with the merge conflicts so
we could re-submit a new merge request that can be applied cleanly.

Ref: #794

* fix: no functional change, just making github CI happy

* Update proxmox-api-go dependency

* Apply patches

* fix: typos

* fix: panic when `disks` is empty

* docs: change disks property names

* chore: update dependencies

* Add debug logging

---------

Co-authored-by: hestia <[email protected]>
Co-authored-by: mleone87 <[email protected]>
  • Loading branch information
3 people authored Jan 14, 2024
1 parent 8fb7db0 commit 8510bc1
Show file tree
Hide file tree
Showing 9 changed files with 1,741 additions and 283 deletions.
247 changes: 209 additions & 38 deletions docs/resources/vm_qemu.md

Large diffs are not rendered by default.

34 changes: 19 additions & 15 deletions examples/pxe_example.tf
Original file line number Diff line number Diff line change
Expand Up @@ -49,21 +49,25 @@ resource "proxmox_vm_qemu" "pxe-example" {
target_node = "test"
vcpus = 0

disk {
backup = false
cache = "none"
discard = "on"
iothread = 1
mbps = 0
mbps_rd = 0
mbps_rd_max = 0
mbps_wr = 0
mbps_wr_max = 0
replicate = 0
size = "32G"
ssd = 1
storage = "local-lvm"
type = "scsi"
disks {
scsi {
scsi0 {
disk {
backup = true
cache = "none"
discard = true
emulatessd = true
iothread = true
mbps_r_burst = 0.0
mbps_r_concurrent = 0.0
mbps_wr_burst = 0.0
mbps_wr_concurrent = 0.0
replicate = true
size = 32
storage = "local-lvm"
}
}
}
}

network {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/Telmate/terraform-provider-proxmox/v2
go 1.20

require (
github.com/Telmate/proxmox-api-go v0.0.0-20231207182448-31826f2fdc39
github.com/Telmate/proxmox-api-go v0.0.0-20240109112522-cd419d1e45db
github.com/google/uuid v1.5.0
github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320
github.com/hashicorp/terraform-plugin-sdk/v2 v2.31.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ dario.cat/mergo v1.0.0 h1:AGCNq9Evsj31mOgNPcLyXc+4PNABt905YmuqPYYpBWk=
github.com/Microsoft/go-winio v0.6.1 h1:9/kr64B9VUZrLm5YYwbGtUJnMgqWVOdUAXu6Migciow=
github.com/ProtonMail/go-crypto v0.0.0-20230828082145-3c4c8a2d2371 h1:kkhsdkhsCvIsutKu5zLMgWtgh9YxGCNAw8Ad8hjwfYg=
github.com/ProtonMail/go-crypto v0.0.0-20230828082145-3c4c8a2d2371/go.mod h1:EjAoLdwvbIOoOQr3ihjnSoLZRtE8azugULFRteWMNc0=
github.com/Telmate/proxmox-api-go v0.0.0-20231207182448-31826f2fdc39 h1:0MvktdAFWIcc9F4IwQls2Em1F9z2LUZR1fSVm1PkKfM=
github.com/Telmate/proxmox-api-go v0.0.0-20231207182448-31826f2fdc39/go.mod h1:xOwyTd8uC2IiYfmjwCVU2fTTVToFCm9yxJzn4cd7rPw=
github.com/Telmate/proxmox-api-go v0.0.0-20240109112522-cd419d1e45db h1:mK7MzKjkeSh2ivjKjZNjquINIJ+mhXIEPwRYkhk3H3U=
github.com/Telmate/proxmox-api-go v0.0.0-20240109112522-cd419d1e45db/go.mod h1:xOwyTd8uC2IiYfmjwCVU2fTTVToFCm9yxJzn4cd7rPw=
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
7 changes: 7 additions & 0 deletions proxmox/errors.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package proxmox

const (
errorUint string = "expected type of %s to be a positive number (uint)"
errorFloat string = "expected type of %s to be a float"
errorString string = "expected type of %s to be string"
)
8 changes: 1 addition & 7 deletions proxmox/resource_storage_iso.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,7 @@ func resourceStorageIsoCreate(d *schema.ResourceData, meta interface{}) error {

client := pconf.Client
file, err := os.CreateTemp("/tmp", fileName)

Check failure on line 72 in proxmox/resource_storage_iso.go

View workflow job for this annotation

GitHub Actions / audit

this value of err is never used (SA4006)
if err != nil {
return err
}
err = _downloadFile(url, file)

Check failure on line 73 in proxmox/resource_storage_iso.go

View workflow job for this annotation

GitHub Actions / audit

this value of err is never used (SA4006)
if err != nil {
return err
}
file.Seek(0, 0)
defer file.Close()
err = client.Upload(node, storage, isoContentType, fileName, file)
Expand All @@ -102,7 +96,7 @@ func _downloadFile(url string, file *os.File) error {
}
defer resp.Body.Close()
_, err = io.Copy(file, resp.Body)

Check failure on line 98 in proxmox/resource_storage_iso.go

View workflow job for this annotation

GitHub Actions / audit

this value of err is never used (SA4006)
return err
return nil
}

func resourceStorageIsoRead(d *schema.ResourceData, meta interface{}) error {
Expand Down
Loading

1 comment on commit 8510bc1

@GabrielKrueger
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sadly this fails. For everyone requiring the qemu disk error with an unattached disc, here's the solution.

Please sign in to comment.