vsphere/resource_vsphere_datastore_cluster_vm_anti_affinity_rule.go
func resourceVSphereDatastoreClusterVMAntiAffinityRuleFindEntryByName(
	pod *object.StoragePod,
	name string,
) (*types.ClusterAntiAffinityRuleSpec, error) {
	props, err := storagepod.Properties(pod)
	if err != nil {
		return nil, fmt.Errorf("error fetching datastore cluster properties: %s", err)
	}

	for _, info := range props.PodStorageDrsEntry.StorageDrsConfig.PodConfig.Rule {
		if info.GetClusterRuleInfo().Name == name {
			if vmAntiAffinityRuleInfo, ok := info.(*types.ClusterAntiAffinityRuleSpec); ok {
				log.Printf("[DEBUG] Found VM anti-affinity rule %q in datastore cluster %q", name, pod.Name())
				return vmAntiAffinityRuleInfo, nil
			}
			return nil, fmt.Errorf("rule %q in datastore cluster %q is not a VM anti-affinity rule", name, pod.Name())
		}
	}

	return nil, fmt.Errorf("no VM anti-affinity rule %q found in datastore cluster %q", name, pod.Name())
}
func resourceVSphereDatastoreClusterVMAntiAffinityRuleFindEntryByName(
	pod *object.StoragePod,
	name string,
) (*types.ClusterAntiAffinityRuleSpec, error) {
	props, err := storagepod.Properties(pod)
	if err != nil {
		return nil, fmt.Errorf("error fetching datastore cluster properties: %s", err)
	}

	for _, info := range props.PodStorageDrsEntry.StorageDrsConfig.PodConfig.Rule {
		if info.GetClusterRuleInfo().Name == name {
			if vmAntiAffinityRuleInfo, ok := info.(*types.ClusterAntiAffinityRuleSpec); ok {
				log.Printf("[DEBUG] Found VM anti-affinity rule %q in datastore cluster %q", name, pod.Name())
				return vmAntiAffinityRuleInfo, nil
			}
			return nil, fmt.Errorf("rule %q in datastore cluster %q is not a VM anti-affinity rule", name, pod.Name())
		}
	}

	return nil, fmt.Errorf("no VM anti-affinity rule %q found in datastore cluster %q", name, pod.Name())
}
// resourceVSphereDatastoreClusterVMAntiAffinityRuleFindEntryByName attempts to
// locate an existing VM anti-affinity rule in a datastore cluster's
// configuration by name. It differs from the standard
// resourceVSphereDatastoreClusterVMAntiAffinityRuleFindEntry 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.