Compute Cluster¶
Type: vsphere-compute-cluster
Artifact BuilderId: vsphere.compute-cluster
This data source retrieves information about existing compute clusters from
vSphere and returns the name, managed object ID, and root resource pool path
for a cluster that matches all specified filters. The result can be used with
the builders to set cluster.
Note
When more than one compute cluster matches the filters, the data source returns an error. Narrow the filters until exactly one cluster matches.
Configuration Reference¶
Filters Configuration¶
Optional:
-
name(string) - Basic filter with glob support (e.g.w01-cl01or*-cl*). Defaults to*. Using stricter globs does not reduce execution time because the vSphere API returns the full inventory, but can improve readability over regular expressions. -
name_regex(string) - Extended name filter with regular expression support (e.g.^w01-cl[0-9]+$). Default is empty. The match is checked by substring. Use^and$to define a full string. The expression must use Go Regex Syntax. -
tag([]Tag) - Filter to return only compute clusters that have all specified tags attached.
Tags Filter Configuration¶
Tag identifies a vSphere tag by name and category for datasource filters.
Specify one or more tag blocks; every listed tag must be attached.
Required:
name(string) - Name of the tag that must be attached to the object.-
category(string) - Name of the tag category that contains the tag.Note
Both
nameandcategorymust be specified in thetagfilter.
Connection Configuration¶
Optional:
vcenter_server(string) - The fully qualified domain name or IP address of the vCenter instance.username(string) - The username to authenticate with the vCenter instance.password(string) - The password to authenticate with the vCenter instance.-
insecure_connection(bool) - Do not validate the certificate of the vCenter instance. Defaults tofalse.Note
This option is beneficial in scenarios where the certificate is self-signed or does not meet standard validation criteria.
-
datacenter(string) - The name of the datacenter object in the vSphere inventory.Note
Required if more than one datacenter object exists in the vSphere inventory.
Output¶
name(string) - Name of the found compute cluster.id(string) - Managed object ID of the found compute cluster.resource_pool(string) - Inventory path of the cluster root resource pool. Builders treat an emptyresource_poolas this root; an absolute path (starting with/) can be passed through when an explicit pool is required.
Example Usage¶
Select Compute Cluster by Name¶
data "vsphere-compute-cluster" "build" {
vcenter_server = "vc01.example.com"
username = "administrator@vsphere.local"
password = "VMware1!"
datacenter = "dc-01"
name = "w01-cl01"
}
source "vsphere-clone" "example" {
vcenter_server = "vc01.example.com"
username = "administrator@vsphere.local"
password = "VMware1!"
cluster = data.vsphere-compute-cluster.build.name
datastore = "w01-cl01-vsan01"
template = "linux-debian"
vm_name = "linux-debian-from-cluster"
communicator = "none"
}
build {
sources = ["source.vsphere-clone.example"]
}
Filter by Tags¶
data "vsphere-compute-cluster" "build" {
vcenter_server = "vc01.example.com"
username = "administrator@vsphere.local"
password = "VMware1!"
datacenter = "dc-01"
tag {
category = "environment"
name = "production"
}
}
locals {
cluster_name = data.vsphere-compute-cluster.build.name
resource_pool = data.vsphere-compute-cluster.build.resource_pool
}