Closed mattd-krystal closed 10 months ago
@mattd-krystal It works for me on 0.36.0 and PVE 8.0.3. Maybe you should try to update your PVE instance? I'm not sure we even know the oldest/lowest PVE version that's supported by provider (maybe @bpg does). If I'm not mistaken unmarshal error in Go appears when there's a variable type mismatch or type conversion failure. I created VM then removed it from state file and imported back:
ratiborus@HOMEWORLD:~/WORKSPACE/terraform_yandex/proxmox$ terraform state rm module.proxmox.proxmox_virtual_environment_vm.base
Removed module.proxmox.proxmox_virtual_environment_vm.base
Successfully removed 1 resource instance(s).
ratiborus@HOMEWORLD:~/WORKSPACE/terraform_yandex/proxmox$ terraform import module.proxmox.proxmox_virtual_environment_vm.base prox-srv1/104
module.proxmox.data.proxmox_virtual_environment_vms.template_vms: Reading...
module.proxmox.proxmox_virtual_environment_vm.base: Importing from ID "prox-srv1/104"...
module.proxmox.proxmox_virtual_environment_vm.base: Import prepared!
Prepared proxmox_virtual_environment_vm for import
module.proxmox.proxmox_virtual_environment_vm.base: Refreshing state... [id=104]
module.proxmox.data.proxmox_virtual_environment_vms.template_vms: Read complete after 0s [id=b496787d-1806-4d45-8253-2194665568be]
Import successful!
The resources that were imported are shown above. These resources are now in
your Terraform state and will henceforth be managed by Terraform.
@bpg There may also be another problem with import though - after importing VM as above the 'disk {}' and 'clone {}' arguments are gone and it triggers VM reprovisioning. There's also a bunch of other arguments that are missing but at least they don't trigger resource destruction. I also see we've lost 'vm_id' argument which is usually (always?) the same as 'id' one which is present. Maybe that's why there's reprovisioning triggered - we're kinda losing ownership of disk (at least from terraform's POV)?
ratiborus@HOMEWORLD:~/WORKSPACE/terraform_yandex/proxmox$ terraform state show module.proxmox.proxmox_virtual_environment_vm.base
# module.proxmox.proxmox_virtual_environment_vm.base:
resource "proxmox_virtual_environment_vm" "base" {
acpi = true
bios = "seabios"
description = "Managed by Terraform"
id = "104"
ipv4_addresses = [
[
"127.0.0.1",
],
[
"10.177.144.56",
],
]
ipv6_addresses = [
[
"::1",
],
[
"fe80::bc29:a9ff:fe96:291",
],
]
keyboard_layout = "en-us"
mac_addresses = [
"00:00:00:00:00:00",
"BE:29:A9:96:02:91",
]
name = "astra-test-vm"
network_interface_names = [
"lo",
"eth0",
]
node_name = "prox-srv1"
scsi_hardware = "virtio-scsi-single"
started = true
tablet_device = true
tags = [
"astra-1.7.4-base",
"terraform",
]
template = false
agent {
enabled = true
timeout = "15m"
trim = true
type = "virtio"
}
cpu {
architecture = "x86_64"
cores = 2
flags = []
hotplugged = 0
numa = true
sockets = 2
type = "host"
units = 1024
}
initialization {
datastore_id = "vzdata"
interface = "ide2"
ip_config {
ipv4 {
address = "dhcp"
}
}
}
memory {
dedicated = 4096
floating = 0
shared = 0
}
network_device {
bridge = "vmbr0"
enabled = true
firewall = false
mac_address = "BE:29:A9:96:02:91"
model = "virtio"
mtu = 0
queues = 0
rate_limit = 0
vlan_id = 0
}
operating_system {
type = "l26"
}
serial_device {
device = "socket"
}
vga {
enabled = true
memory = 32
type = "serial0"
}
}
ratiborus@HOMEWORLD:~/WORKSPACE/terraform_yandex/proxmox$ terraform apply
module.proxmox.data.proxmox_virtual_environment_vms.template_vms: Reading...
module.proxmox.proxmox_virtual_environment_file.cloud_image_astra_174_base: Refreshing state... [id=local:iso/alse-vanilla-1.7.4-cloud-base.img]
module.proxmox.proxmox_virtual_environment_file.cloud_config_userdata_raw_file["prox-srv1"]: Refreshing state... [id=local:snippets/userdata-proxmox-raw-file.yml]
module.proxmox.proxmox_virtual_environment_file.cloud_image_debian_12: Refreshing state... [id=local:iso/debian-12-generic-amd64.img]
module.proxmox.proxmox_virtual_environment_file.cloud_image_ubuntu_2204: Refreshing state... [id=local:iso/ubuntu-22.04-server-cloudimg-amd64.img]
module.proxmox.proxmox_virtual_environment_pool.templates: Refreshing state... [id=templates]
module.proxmox.proxmox_virtual_environment_file.cloud_config_userdata_raw_file["prox-srv2"]: Refreshing state... [id=local:snippets/userdata-proxmox-raw-file.yml]
module.proxmox.proxmox_virtual_environment_file.cloud_config_userdata_raw_file["prox-srv3"]: Refreshing state... [id=local:snippets/userdata-proxmox-raw-file.yml]
module.proxmox.data.proxmox_virtual_environment_vms.template_vms: Read complete after 0s [id=bf551716-a176-4d74-b9bb-e4227bdcde66]
module.proxmox.proxmox_virtual_environment_vm.template_astra_174_base: Refreshing state... [id=1001]
module.proxmox.proxmox_virtual_environment_vm.base: Refreshing state... [id=104]
module.proxmox.proxmox_virtual_environment_vm.template_ubuntu_2204: Refreshing state... [id=1011]
module.proxmox.proxmox_virtual_environment_vm.base2: Refreshing state... [id=105]
Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
-/+ destroy and then create replacement
Terraform will perform the following actions:
# module.proxmox.proxmox_virtual_environment_vm.base must be replaced
-/+ resource "proxmox_virtual_environment_vm" "base" {
~ id = "104" -> (known after apply)
~ ipv4_addresses = [
- [
- "127.0.0.1",
],
- [
- "10.177.144.56",
],
] -> (known after apply)
~ ipv6_addresses = [
- [
- "::1",
],
- [
- "fe80::bc29:a9ff:fe96:291",
],
] -> (known after apply)
~ mac_addresses = [
- "00:00:00:00:00:00",
- "BE:29:A9:96:02:91",
] -> (known after apply)
+ migrate = true
name = "astra-test-vm"
~ network_interface_names = [
- "lo",
- "eth0",
] -> (known after apply)
+ on_boot = true
+ reboot = true
tags = [
"astra-1.7.4-base",
"terraform",
]
+ timeout_clone = 1800
+ timeout_create = 1800
+ timeout_migrate = 1800
+ timeout_move_disk = 1800
+ timeout_reboot = 1800
+ timeout_shutdown_vm = 1800
+ timeout_start_vm = 1800
+ timeout_stop_vm = 300
+ vm_id = (known after apply)
# (9 unchanged attributes hidden)
+ clone {
+ full = true # forces replacement
+ node_name = "prox-srv1" # forces replacement
+ retries = 3 # forces replacement
+ vm_id = 1001 # forces replacement
}
~ cpu {
- flags = [] -> null
# (7 unchanged attributes hidden)
}
+ disk { # forces replacement
+ cache = "none"
+ datastore_id = "vzdata"
+ discard = "on"
+ file_format = "qcow2" # forces replacement
+ interface = "scsi0"
+ iothread = true
+ path_in_datastore = (known after apply)
+ size = 50
+ ssd = true
}
~ network_device {
~ mac_address = "BE:29:A9:96:02:91" -> (known after apply)
# (8 unchanged attributes hidden)
}
- vga {
- enabled = true -> null
- memory = 32 -> null
- type = "serial0" -> null
}
# (5 unchanged blocks hidden)
}
Plan: 1 to add, 0 to change, 1 to destroy.
@ratiborusx Believe me I would love to update my PVE instance to the latest version, unfortunately at least for the forseeable future I have to keep it at this version. I was originally trying to build a module with this but run into this issue.
@bpg If you are able to, would you mind confirming what versions of PVE are supported with this provider? If my version is a bit too far out of date, happy to close this issue.
@mattd-krystal Just recently with the latest PR's docs were updated to include more info in requirements. I don't have good news for you, but maybe there's some workarounds... https://github.com/bpg/terraform-provider-proxmox#requirements
Hi @mattd-krystal,
Per README.md
This provider is compatible with the latest version of Proxmox VE (currently 8.0). While it may work with older 7.x versions, it is not guaranteed to do so.
Practically, most of the 7.x APIs should work with the current provider version, however acceptance tests are run only against 8.x.
To my knowledge, the difference between 6.x and 8.x is more severe, though I never used 6.x in my lab. But funny enough, one of the first changes that I've made to this provider was to fix GetStatusResponseData.data.pid
field that was causing issue on my 7.x PVE back then.
@ratiborusx Resources import is a quite recent (and probably the least tested) feature of the provider. There is no much acceptance testing around it, and personally I'm not using imports at all, so if some arguments got missed / scrambled at import it will be harder to spot and fix. Imports definitely need some more love and polishing.
@bpg @ratiborusx Right okay, thank you both for your comments and assistance, since my version of PVE is too out of date for this, think I will close this issue for now, it's out of scope for the provider and the actual version is now EOL as well.
Might be worth raising a separate issue for the import functionality that you were discussing in previous comments?
Describe the bug When importing a running virtula machine I get the following error:
Reason: json: cannot unmarshal string into Go struct field GetStatusResponseData.data.pid of type int
Proxmox version is 6.3.6
To Reproduce Steps to reproduce the behavior:
Please also provide a minimal Terraform configuration that reproduces the issue.
Expected behavior The resource would be imported into terraform state
Additional context Add any other context about the problem here.
TF_LOG=DEBUG terraform apply
):Have a feeling this maybe potentially related to the issue that was reported earlier for lxc containers here: https://github.com/bpg/terraform-provider-proxmox/issues/552