vsphere/resource_vsphere_compute_cluster_vm_group.go
func resourceVSphereComputeClusterVMGroupFindEntry(
	cluster *object.ClusterComputeResource,
	name string,
) (*types.ClusterVmGroup, error) {
	props, err := clustercomputeresource.Properties(cluster)
	if err != nil {
		return nil, fmt.Errorf("error fetching cluster properties: %s", err)
	}

	for _, info := range props.ConfigurationEx.(*types.ClusterConfigInfoEx).Group {
		if info.GetClusterGroupInfo().Name == name {
			if vmInfo, ok := info.(*types.ClusterVmGroup); ok {
				log.Printf("[DEBUG] Found VM group %q in cluster %q", name, cluster.Name())
				return vmInfo, nil
			}
			return nil, fmt.Errorf("unique group name %q in cluster %q is not a VM group", name, cluster.Name())
		}
	}

	log.Printf("[DEBUG] No VM group name %q found in cluster %q", name, cluster.Name())
	return nil, nil
}
func resourceVSphereComputeClusterVMGroupFindEntry(
	cluster *object.ClusterComputeResource,
	name string,
) (*types.ClusterVmGroup, error) {
	props, err := clustercomputeresource.Properties(cluster)
	if err != nil {
		return nil, fmt.Errorf("error fetching cluster properties: %s", err)
	}

	for _, info := range props.ConfigurationEx.(*types.ClusterConfigInfoEx).Group {
		if info.GetClusterGroupInfo().Name == name {
			if vmInfo, ok := info.(*types.ClusterVmGroup); ok {
				log.Printf("[DEBUG] Found VM group %q in cluster %q", name, cluster.Name())
				return vmInfo, nil
			}
			return nil, fmt.Errorf("unique group name %q in cluster %q is not a VM group", name, cluster.Name())
		}
	}

	log.Printf("[DEBUG] No VM group name %q found in cluster %q", name, cluster.Name())
	return nil, nil
}
// resourceVSphereComputeClusterVMGroupFindEntry attempts to locate an existing
// VM group config in a cluster's configuration. It's used by the resource's
// read functionality and tests. nil is returned if the entry cannot be found.