Plan updates tags that have not changed

I am very new to terraform, so i am not sure if it is something in my configuration files, terraform, or the provider (proxmox bpg). I created a configuration file to create some VMs for a kubernetes cluster. the plan runs just fine and the apply does as well, but if i re-run the plan, even though nothing has changed, it says the tags will be updated:

data.proxmox_virtual_environment_nodes.proxmox_nodes: Reading...
data.proxmox_virtual_environment_nodes.proxmox_nodes: Read complete after 0s [id=nodes]
proxmox_virtual_environment_vm.example[2]: Refreshing state... [id=2002]
proxmox_virtual_environment_vm.example[3]: Refreshing state... [id=2020]
proxmox_virtual_environment_vm.example[4]: Refreshing state... [id=2021]
proxmox_virtual_environment_vm.example[1]: Refreshing state... [id=2001]
proxmox_virtual_environment_vm.example[0]: Refreshing state... [id=2000]
proxmox_virtual_environment_vm.example[5]: Refreshing state... [id=2022]

Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
  ~ update in-place

Terraform will perform the following actions:

  # proxmox_virtual_environment_vm.example[0] will be updated in-place
  ~ resource "proxmox_virtual_environment_vm" "example" {
        id                      = "2000"
        name                    = "k3s-master-01"
      ~ tags                    = [
          - "kubernetes",
          - "local-storage",
          - "master",
            "terraform",
            "ubuntu-2204",
          + "local-storage",
          + "kubernetes",
          + "master",
        ]
        # (21 unchanged attributes hidden)

        # (7 unchanged blocks hidden)
    }

same change repeats for all 6 of the VMs that were created. the configuration file is pretty vanilla:

# get the nodes in the cluster
data "proxmox_virtual_environment_nodes" "proxmox_nodes" {}

# VM Definition
resource "proxmox_virtual_environment_vm" "example" {
  count             = var.vm_count
  name              = count.index + 1 <= var.vm_masters ? "${var.vm_name}-master-${format("%02d", count.index + 1)}" : "${var.vm_name}-worker-${format("%02d", count.index - (var.vm_masters - 1))}"
  node_name         = data.proxmox_virtual_environment_nodes.proxmox_nodes.names[count.index % length(data.proxmox_virtual_environment_nodes.proxmox_nodes.names)]
  vm_id             = count.index + 1 <= var.vm_masters ? var.vm_proxmox_id + count.index : var.vm_proxmox_id + count.index + (20 - var.vm_masters)
  tags              = count.index + 1 <= var.vm_masters ?  "${concat(var.vm_proxmox_tags, ["master"])}" :  "${concat(var.vm_proxmox_tags, ["worker"])}"
  # reboot            = true

  agent {
    enabled         = true
    trim            = true
  }

  cpu {
    sockets         = var.vm_sockets
    cores           = var.vm_cores
  }

  memory {
    dedicated       = count.index + 1 <= var.vm_masters ? var.vm_mem_master : var.vm_mem_worker
  }

  disk {
    interface       = "scsi0"
    datastore_id    = var.clone_target_datastore
    ssd             = true
    size            = 36
    iothread        = true
    discard         = "on"
  }

  # Define the network interface with the specific Mac Address
  network_device {
    model           = "virtio"
    mac_address     = count.index + 1 <= var.vm_masters ? "${var.net_mac_address_base}AA:${format("%02d", count.index)}" : "${var.net_mac_address_base}BB:${format("%02d",  count.index - var.vm_masters)}"
    vlan_id         = var.net_vlan_id
    bridge          = var.net_bridge
  }

  serial_device {}

  # clone information
  clone {
    vm_id           = var.clone_vm_id + (count.index % var.vm_masters) 
    datastore_id    = var.clone_target_datastore
    node_name       = data.proxmox_virtual_environment_nodes.proxmox_nodes.names[count.index % length(data.proxmox_virtual_environment_nodes.proxmox_nodes.names)]
  }
}

am i doing something wroing?

From your plan diff, it appears Terraform is attempting to move the tags specified into a particular order, whilst Proxmox is sorting the submitted tags alphabetically.

You can address this for now by specifying the tags in sorted order within your configuration - sort - Functions - Configuration Language | Terraform | HashiCorp Developer - though really terraform-provider-proxmox ought to be taking care of this detail of the API automatically.

2 Likes

modified the plan with:

  tags              = count.index + 1 <= var.vm_masters ?  "${sort(concat(var.vm_proxmox_tags, ["master"]))}" :  "${sort(concat(var.vm_proxmox_tags, ["worker"]))}"

and it runs without changes. thank you!

is this something i should be notifying the developer of the provider?

FYI, you’re currently using a legacy syntax that dates back to Terraform 0.11 here… there is no need to enclose your expressions in "${ }".

You’re also repeating part of the expression unnecessarily - e.g.:

  tags = sort(concat(var.vm_proxmox_tags,
    [count.index + 1 <= var.vm_masters ? "master" : "worker"]))

Yes, it would be appropriate to open a bug report.

2 Likes

Should be fixed in v0.18.2