bpg / terraform-provider-proxmox

Terraform Provider for Proxmox
https://registry.terraform.io/providers/bpg/proxmox
Mozilla Public License 2.0
804 stars 135 forks source link

datasource proxmox_virtual_environment_vms - strange behaviour when filtering using tags #1577

Closed camaeel closed 3 days ago

camaeel commented 6 days ago

Describe the bug I have VM with 2 tags: ABC, DEF. When I create data source like:

data "proxmox_virtual_environment_vms" "source-templates" {
  tags = [ "ABC",
     "DEF"]
}

this VM is not found.

To find it I have to specify resource like this

data "proxmox_virtual_environment_vms" "source-templates" {
  tags = [ "ABC,DEF"]
}

so tags need to be concatenated in alphabetical order in order to select VM

To Reproduce Steps to reproduce the behavior:

  1. create VM with 2 tags
  2. try to create datasource that will select this VM by tags

Please also provide a minimal Terraform configuration that reproduces the issue.

data "proxmox_virtual_environment_vms" "source-templates" {
  tags = [ "ABC,DEF"]
}

Expected behavior Documentation states that it is enough to provide list off tags like this:

[ "ABC", "DEF"]

Screenshots If applicable, add screenshots to help explain your problem.

Additional context Add any other context about the problem here.

bpg commented 4 days ago

PVE automatically lowercase tags. This use case works:

VM:

Screenshot 2024-10-09 at 7 53 39 PM

config:

data "proxmox_virtual_environment_vms" "test" {
  tags = [ "abc", "def" ]
}

output "vms" {
  value = data.proxmox_virtual_environment_vms.test.vms
}

tofu apply -auto-approve

❯ tofu apply -auto-approve
data.proxmox_virtual_environment_vms.test: Reading...
data.proxmox_virtual_environment_vms.test: Read complete after 0s [id=fae91e9a-8762-4d9f-a053-6b3aa2a1747a]

Changes to Outputs:
  + vms = [
      + {
          + name      = "VM 100"
          + node_name = "pve"
          + status    = "stopped"
          + tags      = [
              + "abc",
              + "def",
            ]
          + template  = false
          + vm_id     = 100
        },
    ]

You can apply this plan to save these new output values to the OpenTofu state, without changing any real infrastructure.

Apply complete! Resources: 0 added, 0 changed, 0 destroyed.

Outputs:

vms = tolist([
  {
    "name" = "VM 100"
    "node_name" = "pve"
    "status" = "stopped"
    "tags" = tolist([
      "abc",
      "def",
    ])
    "template" = false
    "vm_id" = 100
  },
])

@camaeel could you try your tags filter in lowercase and see if it works? If it still doesn't could you post output of qm config <your vm id> (run in PVE shell) pls?

camaeel commented 3 days ago

@bpg Thanx, it seems it works for me as well. No idea what was the issue, I change the code and the setup since then.