hashicorp / terraform-provider-vsphere

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

Add support for a `vsphere_distributed_port_group` data source #1410

Closed pezhore closed 3 days ago

pezhore commented 3 years ago

Description

Although we have a resource for creating/manipulating a new distributed port group, there is no data source for retrieving a current distributed port group. This is challenging when attempting to use other resources (e.g. vsphere_entity_permissions) - requiring the end user to find the mo-ref/entity id manually.

The data resource would require a parent distributed virtual switch id and a port group name (used for searching/filtering distributed port groups). For brevity, I chose dvs_id but that could easily be virtualswitch_id or something else that's more robust.

Potential Terraform Configuration

data "vsphere_datacenter" "datacenter" {
  name = "dc1"
}

data "vsphere_distributed_virtual_switch" "dvs" {
  name          = "terraform-test-dvs"
  datacenter_id = data.vsphere_datacenter.datacenter.id
}

data "vsphere_distributed_port_group" "my-dvpg" {
 name   = "terraform-test-dvpg"
 dvs_id = data.vspherer_distributed_virtual_switch.dvs.id
}

References

Community Note

cerrakoth commented 2 years ago

To add colour to why this would be useful - We would like to start deploying VMs via Terraform in an environment which already contains distributed port groups. We currently would need to create a new dpg managed by Terraform or import the existing dpg to the state which is not an optimal way of doing this.

burnsjared0415 commented 1 week ago

so this was just write for vsphere_network to pull back the distribution or standard switch portgroup by network_type and name would it work for this problem? https://github.com/hashicorp/terraform-provider-vsphere/pull/2281

pezhore commented 1 week ago

That might work? From my read of the Changelog on that PR, it would seem to cover my use case.

burnsjared0415 commented 1 week ago

i updated it so it would look like this

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

data "vsphere_network" "my_port_group" {
  datacenter_id = data.vsphere_datacenter.datacenter.id
  name          = "VM Network"
  network_type = "Network"
  }

give it a run through, we can create a new data source with the same type code but did not know if this would work

pezhore commented 1 week ago

yeah that should work for me.!

burnsjared0415 commented 1 week ago

I had to make a couple changes to the code, once it is release it, i will close out this issue

github-actions[bot] commented 3 days ago

This functionality has been released in v2.10.0 of the Terraform Provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading.

For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template. Thank you!