diff --git a/internal/services/azuremanagedlustrefilesystem/managed_lustre_file_system_resource.go b/internal/services/azuremanagedlustrefilesystem/managed_lustre_file_system_resource.go index 94091ac36646..3d88bf7a00e3 100644 --- a/internal/services/azuremanagedlustrefilesystem/managed_lustre_file_system_resource.go +++ b/internal/services/azuremanagedlustrefilesystem/managed_lustre_file_system_resource.go @@ -50,12 +50,57 @@ type MaintenanceWindow struct { TimeOfDayInUTC string `tfschema:"time_of_day_in_utc"` } +type SkuProperties struct { + Name string + MinimumStorage int +} + type ManagedLustreFileSystemResource struct{} var _ sdk.ResourceWithUpdate = ManagedLustreFileSystemResource{} - var _ sdk.ResourceWithCustomizeDiff = ManagedLustreFileSystemResource{} +func GetSkuPropertiesByName(skuName string) *SkuProperties { + for _, sku := range PossibleSkuProperties() { + if skuName == sku.Name { + return pointer.To(sku) + } + } + + return nil +} + +func PossibleValuesForSkuName() []string { + skus := make([]string, 0) + + for _, sku := range PossibleSkuProperties() { + skus = append(skus, sku.Name) + } + + return skus +} + +func PossibleSkuProperties() []SkuProperties { + return []SkuProperties{ + { + Name: "AMLFS-Durable-Premium-40", + MinimumStorage: 48, + }, + { + Name: "AMLFS-Durable-Premium-125", + MinimumStorage: 16, + }, + { + Name: "AMLFS-Durable-Premium-250", + MinimumStorage: 8, + }, + { + Name: "AMLFS-Durable-Premium-500", + MinimumStorage: 4, + }, + } +} + func (r ManagedLustreFileSystemResource) ResourceType() string { return "azurerm_managed_lustre_file_system" } @@ -103,25 +148,17 @@ func (r ManagedLustreFileSystemResource) Arguments() map[string]*pluginsdk.Schem }, "sku_name": { - Type: pluginsdk.TypeString, - Required: true, - ForceNew: true, - ValidateFunc: validation.StringInSlice([]string{ - "AMLFS-Durable-Premium-40", - "AMLFS-Durable-Premium-125", - "AMLFS-Durable-Premium-250", - "AMLFS-Durable-Premium-500", - }, false), + Type: pluginsdk.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: validation.StringInSlice(PossibleValuesForSkuName(), false), }, "storage_capacity_in_tb": { - Type: pluginsdk.TypeInt, - Required: true, - ForceNew: true, - ValidateFunc: validation.All( - validation.IntBetween(8, 128), - validation.IntDivisibleBy(8), - ), + Type: pluginsdk.TypeInt, + Required: true, + ForceNew: true, + ValidateFunc: validation.IntAtLeast(4), }, "subnet_id": { @@ -205,6 +242,20 @@ func (r ManagedLustreFileSystemResource) CustomizeDiff() sdk.ResourceFunc { } } + configSku := metadata.ResourceDiff.Get("sku_name") + configCapacity := metadata.ResourceDiff.Get("storage_capacity_in_tb") + skuProperties := GetSkuPropertiesByName(configSku.(string)) + + if skuProperties != nil { + if configCapacity.(int) < skuProperties.MinimumStorage { + return fmt.Errorf("'storage_capacity_in_tb' field cannot be less than '%d' for the %q sku, got '%d'", skuProperties.MinimumStorage, configSku, configCapacity) + } + + if configCapacity.(int)%skuProperties.MinimumStorage != 0 { + return fmt.Errorf("'storage_capacity_in_tb' field must be defined in increments of '%d' for the %q sku, got '%d'", skuProperties.MinimumStorage, configSku, configCapacity) + } + } + return nil }, } diff --git a/website/docs/r/managed_lustre_file_system.html.markdown b/website/docs/r/managed_lustre_file_system.html.markdown index 97944a8d612c..0f9786bcac83 100644 --- a/website/docs/r/managed_lustre_file_system.html.markdown +++ b/website/docs/r/managed_lustre_file_system.html.markdown @@ -62,7 +62,8 @@ The following arguments are supported: * `sku_name` - (Required) The SKU name for the Azure Managed Lustre File System. Possible values are `AMLFS-Durable-Premium-40`, `AMLFS-Durable-Premium-125`, `AMLFS-Durable-Premium-250` and `AMLFS-Durable-Premium-500`. Changing this forces a new resource to be created. -* `storage_capacity_in_tb` - (Required) The size of the Azure Managed Lustre File System in TiB. Possible values are between 8 and 128 and must be divisible by 8. Changing this forces a new resource to be created. +* `storage_capacity_in_tb` - (Required) The size of the Azure Managed Lustre File System in TiB. The valid values for this field are dependant on which `sku_name` has been defined in the configuration file. For more information on the valid values for this field please see the [product documentation](https://learn.microsoft.com/azure/azure-managed-lustre/create-file-system-resource-manager#file-system-type-and-size-options). Changing this forces a new resource to be created. + * `subnet_id` - (Required) The resource ID of the Subnet that is used for managing the Azure Managed Lustre file system and for client-facing operations. This subnet should have at least a /24 subnet mask within the Virtual Network's address space. Changing this forces a new resource to be created.