hashicorp / terraform-provider-vsphere

Terraform Provider for VMware vSphere
https://registry.terraform.io/providers/hashicorp/vsphere/
Mozilla Public License 2.0
608 stars 448 forks source link

Add support to fetch datastores within a datastore cluster in `d/datastore_stats` #2159

Open mrdevops100 opened 3 months ago

mrdevops100 commented 3 months ago

Community Guidelines

Terraform

v1.7.5

Terraform Provider

v2.7.0

VMware vSphere

v7.0

Description

When I use the "vsphere_datastore_stats" datasource it only fetches the top level datastores in a DC. It doesn't list the datastores under a datastore cluster.

Affected Resources or Data Sources

d/vsphere_datastore_stats

Terraform Configuration

data "vsphere_datacenter" "datacenter" {
  name = "dc-01"
}

data "vsphere_datastore_stats" "datastore_stats" {
  datacenter_id = data.vsphere_datacenter.datacenter.id
}

locals {
  free_space_values   = { for k, v in data.vsphere_datastore_stats.datastore_stats.free_space : k => tonumber(v) }
  filtered_values     = { for k, v in local.free_space_values : k => tonumber(v) if v != null }
  numeric_values      = [for v in values(local.filtered_values) : tonumber(v)]
  max_free_space      = max(local.numeric_values...)
  max_free_space_name = [for k, v in local.filtered_values : k if v == local.max_free_space][0]
}

output "max_free_space_name" {
  value = local.max_free_space_name
}

output "max_free_space" {
  value = local.max_free_space
}

Debug Output

Not available

Panic Output

Not available

Expected Behavior

Show all the datastores including the ones under datastore cluster

Actual Behavior

Datasource only fetches the top level datastores in a DC

Steps to Reproduce

data "vsphere_datacenter" "datacenter" {
  name = "dc-01"
}

data "vsphere_datastore_stats" "datastore_stats" {
  datacenter_id = data.vsphere_datacenter.datacenter.id
}

locals {
  free_space_values   = { for k, v in data.vsphere_datastore_stats.datastore_stats.free_space : k => tonumber(v) }
  filtered_values     = { for k, v in local.free_space_values : k => tonumber(v) if v != null }
  numeric_values      = [for v in values(local.filtered_values) : tonumber(v)]
  max_free_space      = max(local.numeric_values...)
  max_free_space_name = [for k, v in local.filtered_values : k if v == local.max_free_space][0]
}

output "max_free_space_name" {
  value = local.max_free_space_name
}

output "max_free_space" {
  value = local.max_free_space
}

Environment Details

No response

Screenshots

n/a

References

n/a

github-actions[bot] commented 3 months ago

Hello, mrdevops100! 🖐

Thank you for submitting an issue for this provider. The issue will now enter into the issue lifecycle.

If you want to contribute to this project, please review the contributing guidelines and information on submitting pull requests.

tenthirtyam commented 1 month ago

Hi @nikfot 👋 - would you like to pick this item up to enhance your addition in #1896?

Ryan Johnson Distinguished Engineer, VMware by Broadcom

nikfot commented 2 weeks ago

Hello @tenthirtyam ! I'm glad you notified me on that! sure! I will fix this.