Open
Description
Describe the bug
every plan/apply after the inital apply cuase a recreation or modification of the vm due to the ip addresses being reported as changed. This also triggers an index error as terraform doesnt know the ip addresses
To Reproduce
Steps to reproduce the behavior:
- create a vm using cloud init to set the ip with agent enabled
- have something access the ip via ipv4_address[1][0] for its private ipv4
- plan and apply to create the resource
- plan an apply again
- see error
Please also provide a minimal Terraform configuration that reproduces the issue.
# >>> put your example here <<< #
resource "proxmox_virtual_environment_vm" "master" {
for_each = local.servers
node_name = local.node
vm_id = random_integer.vm_id[each.value].result
name = each.value
bios = "ovmf"
machine = "q35"
clone {
vm_id = 900
datastore_id = local.datastore_id
}
initialization {
datastore_id = local.datastore_id
ip_config {
ipv4 {
address = "192.168.0.2"
gateway = "192.168.0.1"
}
}
user_account {
username = "provision"
keys = [trimspace(tls_private_key.ssh[each.value].public_key_openssh)]
}
}
connection {
type = "ssh"
host = self.ipv4_addresses[1][0]
user = "provision"
private_key = trimspace(tls_private_key.ssh[each.value].private_key_openssh)
}
provisioner "remote-exec" {
inline = ["sudo sed -i 's/^#PasswordAuthentication yes/PasswordAuthentication no/' /etc/ssh/sshd_config",
"sudo sed -i 's/^PasswordAuthentication yes/PasswordAuthentication no/' /etc/ssh/sshd_config"]
}
}
and the output of terraform|tofu apply
.
module.control_plane.random_integer.vm_id["master1"]: Refreshing state... [id=647]
module.control_plane.random_integer.vm_id["master2"]: Refreshing state... [id=340]
module.control_plane.random_integer.vm_id["master0"]: Refreshing state... [id=237]
module.control_plane.tls_private_key.ssh["master2"]: Refreshing state... [id=cae0bfa0fbf0611b8b27da0552faa7d81db411b6]
module.control_plane.tls_private_key.ssh["master1"]: Refreshing state... [id=7811938fa05d41152507b0daa7bf5e6891d4f553]
module.control_plane.tls_private_key.ssh["master0"]: Refreshing state... [id=e96e289e00ca61e2c30f46841e432e4aabaf3a47]
data.proxmox_virtual_environment_nodes.nodes: Reading...
module.control_plane.data.proxmox_virtual_environment_nodes.nodes: Reading...
data.proxmox_virtual_environment_nodes.nodes: Read complete after 0s [id=nodes]
module.control_plane.data.proxmox_virtual_environment_nodes.nodes: Read complete after 0s [id=nodes]
module.control_plane.data.proxmox_virtual_environment_datastores.datastores: Reading...
module.control_plane.data.proxmox_virtual_environment_datastores.datastores: Read complete after 0s [id=pve_datastores]
module.control_plane.proxmox_virtual_environment_vm.master["master2"]: Refreshing state... [id=340]
module.control_plane.proxmox_virtual_environment_vm.master["master0"]: Refreshing state... [id=237]
module.control_plane.proxmox_virtual_environment_vm.master["master1"]: Refreshing state... [id=647]
module.control_plane.terraform_data.hosts_file["master0"]: Refreshing state... [id=c6a2b460-3967-79c4-230c-948c13284660]
module.control_plane.terraform_data.hosts_file["master1"]: Refreshing state... [id=89eb7fc2-e5af-74a0-be72-ac8ec3641d97]
module.control_plane.terraform_data.hosts_file["master2"]: Refreshing state... [id=fd543a54-b909-9381-0a84-c642130fd55d]
OpenTofu used the selected providers to generate the following execution plan. Resource actions are indicated with the following
symbols:
~ update in-place
-/+ destroy and then create replacement
OpenTofu will perform the following actions:
# module.control_plane.proxmox_virtual_environment_vm.master["master0"] will be updated in-place
~ resource "proxmox_virtual_environment_vm" "master" {
id = "237"
~ ipv4_addresses = [
- [
- "127.0.0.1",
],
- [
- "192.168.0.200",
],
] -> (known after apply)
~ ipv6_addresses = [
- [
- "::1",
],
- [
- "fe80::be24:11ff:fe4c:62d6",
],
] -> (known after apply)
name = "master0"
~ network_interface_names = [
- "lo",
- "eth0",
] -> (known after apply)
# (24 unchanged attributes hidden)
- network_device {
- bridge = "vmbr0" -> null
- disconnected = false -> null
- enabled = true -> null
- firewall = false -> null
- mac_address = "BC:24:11:4C:62:D6" -> null
- model = "virtio" -> null
- mtu = 0 -> null
- queues = 0 -> null
- rate_limit = 0 -> null
- vlan_id = 0 -> null
}
# (2 unchanged blocks hidden)
}
# module.control_plane.proxmox_virtual_environment_vm.master["master1"] will be updated in-place
~ resource "proxmox_virtual_environment_vm" "master" {
id = "647"
~ ipv4_addresses = [
- [
- "127.0.0.1",
],
- [
- "192.168.0.201",
],
] -> (known after apply)
~ ipv6_addresses = [
- [
- "::1",
],
- [
- "fe80::be24:11ff:fe18:93fa",
],
] -> (known after apply)
name = "master1"
~ network_interface_names = [
- "lo",
- "eth0",
] -> (known after apply)
# (24 unchanged attributes hidden)
- network_device {
- bridge = "vmbr0" -> null
- disconnected = false -> null
- enabled = true -> null
- firewall = false -> null
- mac_address = "BC:24:11:18:93:FA" -> null
- model = "virtio" -> null
- mtu = 0 -> null
- queues = 0 -> null
- rate_limit = 0 -> null
- vlan_id = 0 -> null
}
# (2 unchanged blocks hidden)
}
# module.control_plane.proxmox_virtual_environment_vm.master["master2"] will be updated in-place
~ resource "proxmox_virtual_environment_vm" "master" {
id = "340"
~ ipv4_addresses = [
- [
- "127.0.0.1",
],
- [
- "192.168.0.202",
],
] -> (known after apply)
~ ipv6_addresses = [
- [
- "::1",
],
- [
- "fe80::be24:11ff:fe34:18f8",
],
] -> (known after apply)
name = "master2"
~ network_interface_names = [
- "lo",
- "eth0",
] -> (known after apply)
# (24 unchanged attributes hidden)
- network_device {
- bridge = "vmbr0" -> null
- disconnected = false -> null
- enabled = true -> null
- firewall = false -> null
- mac_address = "BC:24:11:34:18:F8" -> null
- model = "virtio" -> null
- mtu = 0 -> null
- queues = 0 -> null
- rate_limit = 0 -> null
- vlan_id = 0 -> null
}
# (2 unchanged blocks hidden)
}
# module.control_plane.terraform_data.hosts_file["master0"] will be replaced due to changes in replace_triggered_by
-/+ resource "terraform_data" "hosts_file" {
~ id = "c6a2b460-3967-79c4-230c-948c13284660" -> (known after apply)
}
# module.control_plane.terraform_data.hosts_file["master1"] will be replaced due to changes in replace_triggered_by
-/+ resource "terraform_data" "hosts_file" {
~ id = "89eb7fc2-e5af-74a0-be72-ac8ec3641d97" -> (known after apply)
}
# module.control_plane.terraform_data.hosts_file["master2"] will be replaced due to changes in replace_triggered_by
-/+ resource "terraform_data" "hosts_file" {
~ id = "fd543a54-b909-9381-0a84-c642130fd55d" -> (known after apply)
}
Plan: 3 to add, 3 to change, 3 to destroy.
module.control_plane.terraform_data.hosts_file["master0"]: Destroying... [id=c6a2b460-3967-79c4-230c-948c13284660]
module.control_plane.terraform_data.hosts_file["master1"]: Destroying... [id=89eb7fc2-e5af-74a0-be72-ac8ec3641d97]
module.control_plane.terraform_data.hosts_file["master2"]: Destroying... [id=fd543a54-b909-9381-0a84-c642130fd55d]
module.control_plane.terraform_data.hosts_file["master0"]: Destruction complete after 0s
module.control_plane.terraform_data.hosts_file["master1"]: Destruction complete after 0s
module.control_plane.terraform_data.hosts_file["master2"]: Destruction complete after 0s
module.control_plane.proxmox_virtual_environment_vm.master["master0"]: Modifying... [id=237]
module.control_plane.proxmox_virtual_environment_vm.master["master2"]: Modifying... [id=340]
module.control_plane.proxmox_virtual_environment_vm.master["master1"]: Modifying... [id=647]
module.control_plane.proxmox_virtual_environment_vm.master["master0"]: Modifications complete after 7s [id=237]
module.control_plane.proxmox_virtual_environment_vm.master["master2"]: Modifications complete after 7s [id=340]
module.control_plane.proxmox_virtual_environment_vm.master["master1"]: Modifications complete after 8s [id=647]
╷
│ Error: Invalid index
│
│ on modules/k8/master/main.tf line 3, in locals:
│ 3: leader_ip = proxmox_virtual_environment_vm.master[element(var.servers, 0)].ipv4_addresses[1][0] # aka the first one
│ ├────────────────
│ │ proxmox_virtual_environment_vm.master is object with 3 attributes
│ │ var.servers is list of string with 3 elements
│
│ The given key does not identify an element in this collection value.
any plans after that get stuck on refreshing state
Expected behavior
second plan report nothing as changed
Screenshots
If applicable, add screenshots to help explain your problem.
Additional context
Add any other context about the problem here.
- Single or clustered Proxmox:
- Proxmox version: 8.3.4
- Provider version (ideally it should be the latest version):
- Terraform/OpenTofu version:
- OpenTofu v1.9.0
on linux_amd64
- provider registry.opentofu.org/bpg/proxmox v0.72.0
- provider registry.opentofu.org/hashicorp/local v2.5.2
- provider registry.opentofu.org/hashicorp/oci v6.21.0
- provider registry.opentofu.org/hashicorp/random v3.6.3
- provider registry.opentofu.org/hashicorp/tls v4.0.6
- OS (where you run Terraform/OpenTofu from): archlinux
- Debug logs (
TF_LOG=DEBUG terraform apply
):
Metadata
Metadata
Assignees
Labels
Projects
Status
☑️ Todo