Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

proxmox_virtual_environment_datastores should group attributes in an array scoped to a single datastore #1354

Open
vanillaSprinkles opened this issue Jun 5, 2024 · 1 comment
Labels
✨ enhancement New feature or request

Comments

@vanillaSprinkles
Copy link

vanillaSprinkles commented Jun 5, 2024

Describe the bug
use of proxmox_virtual_environment_datastores with multiple datastores currently utilizes each attribute as an array, resulting in a sorting tf-logic nightmare; the output should instead be a list of datastore objects (perhaps utilizing a filter on resource input?)
the output seems to not follow the "normal" paradigm of output structures

To Reproduce
Steps to reproduce the behavior:

  1. basic proxmox setup
  2. setup below minimal hcl
  3. tofu output

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

data "proxmox_virtual_environment_datastores" "first_node" {
  node_name = "first-node"
}

output datastores { value = data.proxmox_virtual_environment_datastores.first_node }
$ tofu output
datastores = {
  "active" = tolist([
    false,
    true,
  ])
  "content_types" = tolist([
    tolist([
      "backup",
      "iso",
      "vztmpl",
    ]),
    tolist([
      "backup",
      "images",
      "iso",
      "rootdir",
      "vztmpl",
    ]),
  ])
  "datastore_ids" = tolist([
    "local",
    "local-btrfs",
  ])
  "enabled" = tolist([
    false,
    true,
  ])
  "id" = "first_node_datastores"
  "node_name" = "first_node"
  "shared" = tolist([
    false,
    false,
  ])
  "space_available" = tolist([
    0,
    492695429120,
  ])
  "space_total" = tolist([
    0,
    499033051136,
  ])
  "space_used" = tolist([
    0,
    5329494016,
  ])
  "types" = tolist([
    "dir",
    "btrfs",
  ])
}

Expected behavior

data "proxmox_virtual_environment_datastores" "first_node" {
  node_name = "first-node"

  # filters = {
  #   enabled = true
  # }

}

output datastores { value = data.proxmox_virtual_environment_datastores.first_node }
$ tofo output
datastores = [
  {
    "active" = false
    "content_types" = tolist([
      "backup",
      "iso",
      "vztmpl",
    ])
    "datastore_ids" = "local"
    "enabled" = false
    "id" = "first_node_datastores"
    "node_name" = "first_node"
    "shared" = false
    "space_available" = 0
    "space_total" = 0
    "space_used" = 0
    "types" = "dir"
  },
  {
    "active" = true
    "content_types" = tolist([
      "backup",
      "images",
      "iso",
      "rootdir",
      "vztmpl",
    ])
    "datastore_ids" = "local-btrfs"
    "enabled" = true
    "id" = "first_node_datastores"
    "node_name" = "first_node"
    "shared" = false
    "space_available" = 492695429120
    "space_total" = 499033051136
    "space_used" = 5329494016
    "types" = "btrfs"
  },
]

Additional context
(cant quite decide if this is a bug or feature; more like a QoL bug)

  • Single or clustered Proxmox: Single
  • Proxmox version: 8.2.2
  • Provider version (ideally it should be the latest version): registry.opentofu.org/bpg/proxmox v0.58.1
  • Terraform/OpenTofu version: OpenTofu v1.7.1
  • OS (where you run Terraform/OpenTofu from): archlinux
  • Debug logs (TF_LOG=DEBUG terraform apply): N/A

Workaround
mangle the data object with a locals blob; though i am not proud of this, it does get the job done (i did not optimize it from zombie-brain coding):

locals {

  proxmox_virtual_environment_datastores__first_node = ({
    datastores = ([for index_num in range(0, length(data.proxmox_virtual_environment_datastores.first_node.enabled)) : merge(
      { id = data.proxmox_virtual_environment_datastores.first_node.id },
      { node_name = data.proxmox_virtual_environment_datastores.first_node.node_name },
      [
        for k, v in data.proxmox_virtual_environment_datastores.first_node : (
          {
            (k) = v[index_num]
          }
        ) if length(v) == length(data.proxmox_virtual_environment_datastores.first_node.enabled)
      ]...)
    ])
  }).datastores

  ## and to get a list of only enabled data stores:
  proxmox_virtual_environment_datastores__first_node__enabled = [for k, v in local.proxmox_virtual_environment_datastores__first_node : v if v.enabled]
}
@vanillaSprinkles vanillaSprinkles added the 🐛 bug Something isn't working label Jun 5, 2024
@bpg bpg added ✨ enhancement New feature or request and removed 🐛 bug Something isn't working labels Jun 5, 2024
@LtdJorge
Copy link

I'm having the same "problem". I believe this could be handled the same way proxmox_virtual_environment_hagroups and proxmox_virtual_environment_hagroup are, using a proxmox_virtual_environment_datastores data source that gets the entire list of ids and then using a proxmox_virtual_environment_datastore referencing an id to retrieve a datastore object.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
✨ enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants