vsphere/resource_vsphere_compute_cluster_vm_host_rule.go
func resourceVSphereComputeClusterVMHostRuleFindEntryByName(
	cluster *object.ClusterComputeResource,
	name string,
) (*types.ClusterVmHostRuleInfo, 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).Rule {
		if info.GetClusterRuleInfo().Name == name {
			if vmHostRuleInfo, ok := info.(*types.ClusterVmHostRuleInfo); ok {
				log.Printf("[DEBUG] Found VM/host rule %q in cluster %q", name, cluster.Name())
				return vmHostRuleInfo, nil
			}
			return nil, fmt.Errorf("rule %q in cluster %q is not a VM/host rule", name, cluster.Name())
		}
	}

	return nil, fmt.Errorf("no VM/host rule %q found in cluster %q", name, cluster.Name())
}
func resourceVSphereComputeClusterVMHostRuleFindEntryByName(
	cluster *object.ClusterComputeResource,
	name string,
) (*types.ClusterVmHostRuleInfo, 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).Rule {
		if info.GetClusterRuleInfo().Name == name {
			if vmHostRuleInfo, ok := info.(*types.ClusterVmHostRuleInfo); ok {
				log.Printf("[DEBUG] Found VM/host rule %q in cluster %q", name, cluster.Name())
				return vmHostRuleInfo, nil
			}
			return nil, fmt.Errorf("rule %q in cluster %q is not a VM/host rule", name, cluster.Name())
		}
	}

	return nil, fmt.Errorf("no VM/host rule %q found in cluster %q", name, cluster.Name())
}
// resourceVSphereComputeClusterVMHostRuleFindEntryByName attempts to locate an
// existing VM/host rule in a cluster's configuration by name. It differs from
// the standard resourceVSphereComputeClusterVMHostRuleFindEntry in that we
// don't allow missing entries, as it's designed to be used in places where we
// don't want to allow for missing entries, such as during creation and import.