vsphere/resource_vsphere_datastore_cluster.go
func flattenStorageDrsSpaceLoadBalanceConfig(
	d *schema.ResourceData,
	obj *types.StorageDrsSpaceLoadBalanceConfig,
	version viapi.VSphereVersion,
) error {
	attrs := map[string]interface{}{
		"sdrs_free_space_utilization_difference": obj.MinSpaceUtilizationDifference,
		"sdrs_free_space_threshold_mode":         obj.SpaceThresholdMode,
	}

	freeSpaceSupported := version.Newer(viapi.VSphereVersion{Product: version.Product, Major: 6})
	if freeSpaceSupported && obj.SpaceThresholdMode == string(types.StorageDrsSpaceLoadBalanceConfigSpaceThresholdModeFreeSpace) {
		attrs["sdrs_free_space_threshold"] = obj.FreeSpaceThresholdGB
	} else {
		attrs["sdrs_space_utilization_threshold"] = obj.SpaceUtilizationThreshold
	}

	for k, v := range attrs {
		if err := d.Set(k, v); err != nil {
			return fmt.Errorf("error setting attribute %q: %s", k, err)
		}
	}

	return nil
}
func flattenStorageDrsSpaceLoadBalanceConfig(
	d *schema.ResourceData,
	obj *types.StorageDrsSpaceLoadBalanceConfig,
	version viapi.VSphereVersion,
) error {
	attrs := map[string]interface{}{
		"sdrs_free_space_utilization_difference": obj.MinSpaceUtilizationDifference,
		"sdrs_free_space_threshold_mode":         obj.SpaceThresholdMode,
	}

	freeSpaceSupported := version.Newer(viapi.VSphereVersion{Product: version.Product, Major: 6})
	if freeSpaceSupported && obj.SpaceThresholdMode == string(types.StorageDrsSpaceLoadBalanceConfigSpaceThresholdModeFreeSpace) {
		attrs["sdrs_free_space_threshold"] = obj.FreeSpaceThresholdGB
	} else {
		attrs["sdrs_space_utilization_threshold"] = obj.SpaceUtilizationThreshold
	}

	for k, v := range attrs {
		if err := d.Set(k, v); err != nil {
			return fmt.Errorf("error setting attribute %q: %s", k, err)
		}
	}

	return nil
}
// flattenStorageDrsSpaceLoadBalanceConfig saves a
// StorageDrsSpaceLoadBalanceConfig into the supplied ResourceData.