terraform-provider-vsphere
terraform-provider-vsphere copied to clipboard
`d/*`: add support for plural datasources
Description
Suppose you'd like to bootstrap your vCenter environment in Terraform. This may include finding all data stores that meet specific criteria, e.g. ends with "-data" and tag them as a data disk. The current vsphere_datastore data source requires that you specify a name, which implies that you have to know all data sources upfront.
Introduce the plural of data sources, e.g. vsphere_datastores which returns all the data stores for a specific data center, host, cluster, and whatnot.
Potential Terraform Configuration
Datastores in Data Centers
To return all data stores for a data center:
data "vsphere_datacenter" "dc" {
name = "Example"
}
data "vsphere_datastores" "dc" {
datacenter_id = data.vsphere_datacenter.dc.id
}
This would be the equivalent of going to vCenter, selecting the data center in question, and returning all the items in the "Datastores" tab.
Datastores in Hosts
To return all data stores of a host:
data "vsphere_datacenter" "main" {
name = "Example"
}
data "vsphere_host" "main" {
name = "esxi1"
datacenter_id = data.vsphere_datacenter.main.id
}
data "vsphere_datastores" "main" {
host_id = data. vsphere_host.main.id
}
This would be the equivalent of going to vCenter, selecting the host in question, and returning all the items in the "Datastores" tab.
The same pattern can be applied to any vSphere resource that has a data store. For each datastore, do return the datacenter, hosts, and whatnot that references it. This would be the equivalent of the properties when viewing a datastore in vCenter. One can see the hosts, VMS, devices backing it, and so forth.
References
Community Note
- Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
- Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request
- If you are interested in working on this issue or have submitted a pull request, please leave a comment
In line with this request, there's a need to return "a list of resources" for almost everything out there, which would result in a large number of enhancement requests. I'd be happy to create the enhancement requests for each.
For a given vCenter installation, all the
- hosts
- data centers
- virtual machines
- templates
- resource pools
- networks
- content libraries
- tags
- custom attributes
- vApps
- distributed switches
- port groups
- distributed port groups
- clusters
This is particularly useful during bootstrapping infrastructure in every cluster, in every data center, in networks ending in "shared", on data stores ending in "vms" using a template in the respective content library ending with "templates" that the respective cluster has access to.
Examples:
- Active Directory
- Caching Servers (e.g. an APT mirror)
Assigned to @appilon to add comments on plural data sources.
Ryan
Hello @bloudraak,
Plural datasources is a concept that has been brought up a few times over the years. The demand for them has made more sense with Terraform's 0.13 release which included the for_each meta argument, however it has posed questions such as do we error when no results are returned? The precedent from other providers seems to not error.
The effort to pluralize datasources will be considered going forward in our effort to implement the most in demand features for the provider. Please continue to upvote this issue for us to better gauge the demand, we appreciate all community feedback.
I was very disappointed today. I tried the vsphere provider the first time. I was expecting data resources that can give me for example all VMs/hosts on a datacenter. Or all datacenters with that account. And much more data sources. On other providers these data resources are basic. But without this, it would probably too much work for the most people to move to terraform with vsphere. Or have I done anything wrong or missunderstood?
Hi @h3-dev,
I'm sorry that you are disappointed in your first impressions of the provider.
Today, the provider is used by many organizations and enthusiasts. It is maintained by small number of individuals. For example, I help maintain and triage this project and others in my spare time.
There are many opportunities for improvement, including data sources, and there is a rather well-maintained backlog for enhancements. Contributions by the community are always welcome, but we ask that they are aligned with an enhancement such as this issue for tracking.
For further discussion topics, please consider using discuss.hashicorp.com or the #terraform channel on the https://vmwarecode.slack.com workspace.
Ryan Johnson Senior Staff Solutions Architect | Product Engineering @ VMware, Inc.
Hi @tenthirtyam ,
at first, big thanks for this project at all and for maintaining. Maybe my post was a little bit harsh because I was frustrated. But am I right that there is no data source that provides the opportunity to get all VMs? Like with the official API? https://developer.vmware.com/apis/vsphere-automation/latest/vcenter/api/vcenter/vm/get/
H @h3-dev - today, you can only use the d/virtual_machne to return a single resource id. The effort to pluralize datasources will be considered going forward in our effort to implement the most in demand features for the provider. '
Please continue to upvote this issue for us to better gauge the demand, we appreciate all community feedback.
Ryan Johnson Senior Staff Solutions Architect | Product Engineering @ VMware, Inc.
@tenthirtyam Is there any plan to introduce any sort of vm "search" functionality? To be able to ask for something like 'latest dated VM template' instead of just a single match? That sort of 'search by pattern' functionality might address many of the curtain shortcomings as compared to the AWS modules that allow searching for things like the latest AMI matching a name prefix.
Hi @nneul, please consider opening an enhancement request specifically for this feature ask. Thanks!
#1785