hashicorp / terraform-provider-vsphere

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

Add `parent_resource_pool_id` to `d/vsphere_resource_pool` to match `r/vsphere_resource_pool` #1271

Open desertmoose706 opened 3 years ago

desertmoose706 commented 3 years ago

Terraform Version

Terraform v0.13.5

vSphere Provider Version

Affected Resource(s)

resource vsphere_resource_pool data vsphere_resource_pool

Description

Need to reference a resource pool within a Cluster.

E.g. I create the resource pool using this code in multiple clusters in the same datacenter:

resource "vsphere_resource_pool" "resource_pool1" {
    name                    = "Veeam"
    parent_resource_pool_id = data.vsphere_compute_cluster.compute_cluster1.resource_pool_id
}
resource "vsphere_resource_pool" "resource_pool2" {
    name                    = "Veeam"
    parent_resource_pool_id = data.vsphere_compute_cluster.compute_cluster2.resource_pool_id
}

Then seemingly only option to extract data for that pool name is:

data "vsphere_resource_pool" "pool" {
    name          = "Veeam"
    datacenter_id = data.vsphere_datacenter.dc.id
}

Which returns the following error:

Error: error fetching resource pool: path 'Veeam' resolves to multiple resource pools

  on vars.tf line 29, in data "vsphere_resource_pool" "pool":
  29: data "vsphere_resource_pool" "pool" {

Potential Terraform Configuration

Recommend implementing parent_resource_pool_id for data vsphere_resource_pool to match the resource. e.g.:

data "vsphere_resource_pool" "pool" {
    name                    = "Veeam"
    parent_resource_pool_id = data.vsphere_compute_cluster.cluster.resource_pool_id
}

References

Community Note

AspenForester commented 3 years ago

I'm running into a similar situation where I need to reference a resource pool whose name is not unique in the data center, but is unique to the Cluster.

AspenForester commented 3 years ago

@desertmoose706 Today I Learned that you can specify the Resource Pool as /Compute Cluster Name/Resource Pool Name That fact is not covered by the vsphere provider documentation but is mentioned in the docs for vmware's "vm" module

I still like your "parent_resource_pool_id" suggestion.