Skip to content

Commit

Permalink
Merge with upstream and update api dependency
Browse files Browse the repository at this point in the history
This updates dependencies to the latest version, which fixes an error with
DELETE of vms.

Also reconfigures the go.mod file to streamline it and remove unneeded
dependencies.
  • Loading branch information
tagur87 committed May 7, 2021
2 parents 9d559d6 + f9cad84 commit d625689
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 13 deletions.
2 changes: 2 additions & 0 deletions docs/guides/cloud_init.md
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,8 @@ EOF
the snippets folder in the local storage in the Proxmox VE server.
*/
cicustom = "user=local:snippets/user_data_vm-${count.index}.yml"
/* Create the cloud-init drive on the "local-lvm" storage */
cloudinit_cdrom_storage = "local-lvm"
provisioner "remote-exec" {
inline = [
Expand Down
3 changes: 2 additions & 1 deletion docs/resources/vm_qemu.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ When creating a VM Qemu resource, you create a `proxmox_vm_qemu` resource block.

```hcl
resource "proxmox_vm_qemu" "resource-name" {
name = "VM name"
name = "VM-name"
target_node = "Node to create the VM on"
iso = "ISO file name"
# or
Expand Down Expand Up @@ -118,6 +118,7 @@ The following arguments are supported in the top level resource block.
|`ciuser`|`str`||Override the default cloud-init user for provisioning.|
|`cipassword`|`str`||Override the default cloud-init user's password. Sensitive.|
|`cicustom`|`str`||Instead specifying ciuser, cipasword, etc... you can specify the path to a custom cloud-init config file here. Grants more flexibility in configuring cloud-init.|
|`cloudinit_cdrom_storage`|`str`||Set the storage location for the cloud-init drive. Required when specifying `cicustom`.|
|`searchdomain`|`str`||Sets default DNS search domain suffix.|
|`nameserver`|`str`||Sets default DNS server for guest.|
|`sshkeys`|`str`||Newline delimited list of SSH public keys to add to authorized keys file for the cloud-init user.|
Expand Down
2 changes: 1 addition & 1 deletion examples/vagrant_example.tf
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ provider "proxmox" {
}

resource "proxmox_vm_qemu" "example" {
name = "servy_mcserverface"
name = "servy-mcserverface"
desc = "A test for using terraform and vagrant"
target_node = "pve"
}
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
go 1.16

require (
github.com/Telmate/proxmox-api-go v0.0.0-20210429201316-cb769f4e78c9
github.com/Telmate/proxmox-api-go v0.0.0-20210507143528-c60bbda13c0c
github.com/hashicorp/terraform-plugin-sdk/v2 v2.6.1
github.com/rs/zerolog v1.21.0
)
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ github.com/Masterminds/sprig v2.22.0+incompatible/go.mod h1:y6hNFY5UBTIWBxnzTeuN
github.com/Microsoft/go-winio v0.4.14/go.mod h1:qXqCSQ3Xa7+6tgxaGTIe4Kpcdsi+P8jBhyzoq1bpyYA=
github.com/Microsoft/go-winio v0.4.16 h1:FtSW/jqD+l4ba5iPBj9CODVtgfYAD8w2wS923g/cFDk=
github.com/Microsoft/go-winio v0.4.16/go.mod h1:XB6nPKklQyQ7GC9LdcBEcBl8PF76WugXOPRXwdLnMv0=
github.com/Telmate/proxmox-api-go v0.0.0-20210429201316-cb769f4e78c9 h1:BR84I9FTOYKO/kgk7y/ikEswpUT1BtrD2Z3fjJFTBC8=
github.com/Telmate/proxmox-api-go v0.0.0-20210429201316-cb769f4e78c9/go.mod h1:keBhXWLa+UBajvf79xvKcfiqeIc7vZL9wOqxuy1CBGw=
github.com/Telmate/proxmox-api-go v0.0.0-20210507143528-c60bbda13c0c h1:s8BXeCeP5hLudxqEVwSScJMS/V25eyatTKpIg7JMSNQ=
github.com/Telmate/proxmox-api-go v0.0.0-20210507143528-c60bbda13c0c/go.mod h1:keBhXWLa+UBajvf79xvKcfiqeIc7vZL9wOqxuy1CBGw=
github.com/agext/levenshtein v1.2.1/go.mod h1:JEDfjyjHDjOF/1e4FlBE/PkbqA9OfWu2ki2W0IB5558=
github.com/agext/levenshtein v1.2.2 h1:0S/Yg6LYmFJ5stwQeRp6EeOcCbj7xiqQSdNelsXvaqE=
github.com/agext/levenshtein v1.2.2/go.mod h1:JEDfjyjHDjOF/1e4FlBE/PkbqA9OfWu2ki2W0IB5558=
Expand Down
26 changes: 18 additions & 8 deletions proxmox/resource_vm_qemu.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,10 @@ func resourceVmQemu() *schema.Resource {
Type: schema.TypeString,
Optional: true,
},
"args": {
Type: schema.TypeString,
Optional: true,
},
"memory": {
Type: schema.TypeInt,
Optional: true,
Expand Down Expand Up @@ -334,10 +338,10 @@ func resourceVmQemu() *schema.Resource {
},
},
"unused_disk": &schema.Schema{
Type: schema.TypeList,
Computed: true,
Type: schema.TypeList,
Computed: true,
//Optional: true,
Description: "Record unused disks in proxmox. This is intended to be read-only for now.",
Description: "Record unused disks in proxmox. This is intended to be read-only for now.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"storage": &schema.Schema{
Expand Down Expand Up @@ -409,7 +413,7 @@ func resourceVmQemu() *schema.Resource {
"ssd": &schema.Schema{
Type: schema.TypeInt,
Optional: true,
Default: 0,
Default: 0,
},
"discard": &schema.Schema{
Type: schema.TypeString,
Expand Down Expand Up @@ -682,8 +686,8 @@ func resourceVmQemu() *schema.Resource {
ForceNew: true,
},
"reboot_required": {
Type: schema.TypeBool,
Computed: true,
Type: schema.TypeBool,
Computed: true,
Description: "Internal variable, true if any of the modified parameters require a reboot to take effect.",
},
"default_ipv4_address": {
Expand Down Expand Up @@ -743,6 +747,7 @@ func resourceVmQemuCreate(d *schema.ResourceData, meta interface{}) error {
HaState: d.Get("hastate").(string),
QemuOs: d.Get("qemu_os").(string),
Tags: d.Get("tags").(string),
Args: d.Get("args").(string),
QemuNetworks: qemuNetworks,
QemuDisks: qemuDisks,
QemuSerials: qemuSerials,
Expand Down Expand Up @@ -834,7 +839,7 @@ func resourceVmQemuCreate(d *schema.ResourceData, meta interface{}) error {
// proxmox needs so we can correctly update the existing disks (post-clone)
// instead of accidentially causing the existing disk to be detached.
// see https://github.com/Telmate/terraform-provider-proxmox/issues/239
for slot, disk := range(config_post_clone.QemuDisks) {
for slot, disk := range config_post_clone.QemuDisks {
// only update the desired configuration if it was not set by the user
// we do not want to overwrite the desired config with the results from
// proxmox if the user indicates they wish a particular file or volume config
Expand Down Expand Up @@ -997,6 +1002,7 @@ func resourceVmQemuUpdate(d *schema.ResourceData, meta interface{}) error {
HaState: d.Get("hastate").(string),
QemuOs: d.Get("qemu_os").(string),
Tags: d.Get("tags").(string),
Args: d.Get("args").(string),
QemuNetworks: qemuNetworks,
QemuDisks: qemuDisks,
QemuSerials: qemuSerials,
Expand Down Expand Up @@ -1229,6 +1235,7 @@ func _resourceVmQemuRead(d *schema.ResourceData, meta interface{}) error {
d.Set("hastate", vmr.HaState())
d.Set("qemu_os", config.QemuOs)
d.Set("tags", config.Tags)
d.Set("args", config.Args)
// Cloud-init.
d.Set("ciuser", config.CIuser)
// we purposely use the password from the terraform config here
Expand All @@ -1243,12 +1250,15 @@ func _resourceVmQemuRead(d *schema.ResourceData, meta interface{}) error {
d.Set("ipconfig2", config.Ipconfig2)

// Some dirty hacks to populate undefined keys with default values.
checkedKeys := []string{"clone_wait", "additional_wait", "force_create", "full_clone", "define_connection_info", "preprovision"}
checkedKeys := []string{"clone_wait", "additional_wait", "force_create", "define_connection_info", "preprovision"}
for _, key := range checkedKeys {
if _, ok := d.GetOk(key); !ok {
d.Set(key, thisResource.Schema[key].Default)
}
}
// Check "full_clone" separately, as it causes issues in loop above due to how GetOk returns values on false bools.
// Since "full_clone" has a default of true, it will always be in the configuration, so no need to verify.
d.Set("full_clone", d.Get("full_clone"))

// Disks.
// add an explicit check that the keys in the config.QemuDisks map are a strict subset of
Expand Down

0 comments on commit d625689

Please sign in to comment.