From 41b3b610277b17543a878e096c801489cc80cba4 Mon Sep 17 00:00:00 2001 From: Jeffrey Cline <20408400+WodansSon@users.noreply.github.com> Date: Sat, 30 Sep 2023 02:23:29 -0600 Subject: [PATCH 1/4] Initial Check-in... --- .../managed_lustre_file_system_resource.go | 74 ++++++++++++++----- 1 file changed, 57 insertions(+), 17 deletions(-) diff --git a/internal/services/azuremanagedlustrefilesystem/managed_lustre_file_system_resource.go b/internal/services/azuremanagedlustrefilesystem/managed_lustre_file_system_resource.go index 94091ac36646..080d7a886a83 100644 --- a/internal/services/azuremanagedlustrefilesystem/managed_lustre_file_system_resource.go +++ b/internal/services/azuremanagedlustrefilesystem/managed_lustre_file_system_resource.go @@ -50,12 +50,45 @@ type MaintenanceWindow struct { TimeOfDayInUTC string `tfschema:"time_of_day_in_utc"` } +type SkuProperties struct { + Name string + MinumumStorage int +} + type ManagedLustreFileSystemResource struct{} var _ sdk.ResourceWithUpdate = ManagedLustreFileSystemResource{} - var _ sdk.ResourceWithCustomizeDiff = ManagedLustreFileSystemResource{} +func GetSkuPropertiesByName(skuName string) interface{} { + for _, sku := range PossibleSkuProperties() { + if skuName == sku.Name { + return sku + } + } + + return nil +} + +func PossibleValuesForSkuName() []string { + var skus []string + + for _, sku := range PossibleSkuProperties() { + skus = append(skus, sku.Name) + } + + return skus +} + +func PossibleSkuProperties() []SkuProperties { + return []SkuProperties{ + {"AMLFS-Durable-Premium-40", 48}, + {"AMLFS-Durable-Premium-125", 16}, + {"AMLFS-Durable-Premium-250", 8}, + {"AMLFS-Durable-Premium-500", 4}, + } +} + func (r ManagedLustreFileSystemResource) ResourceType() string { return "azurerm_managed_lustre_file_system" } @@ -103,25 +136,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 +230,21 @@ func (r ManagedLustreFileSystemResource) CustomizeDiff() sdk.ResourceFunc { } } + _, configSku := metadata.ResourceDiff.GetChange("sku_name") + _, configCapacity := metadata.ResourceDiff.GetChange("storage_capacity_in_tb") + + if sku := GetSkuPropertiesByName(configSku.(string)); sku != nil { + if skuProperties, ok := sku.(SkuProperties); ok { + if configCapacity.(int) < skuProperties.MinumumStorage { + return fmt.Errorf("'storage_capacity_in_tb' field cannot be less than '%d' for the %q sku, got '%d'", skuProperties.MinumumStorage, configSku, configCapacity) + } + + if configCapacity.(int)%skuProperties.MinumumStorage != 0 { + return fmt.Errorf("'storage_capacity_in_tb' field must be defined in increments of '%d' for the %q sku, got '%d'", skuProperties.MinumumStorage, configSku, configCapacity) + } + } + } + return nil }, } From 76e5e372876332747f569056d584c2cd2cbca459 Mon Sep 17 00:00:00 2001 From: Jeffrey Cline <20408400+WodansSon@users.noreply.github.com> Date: Sat, 30 Sep 2023 02:57:09 -0600 Subject: [PATCH 2/4] Update documentation... --- website/docs/r/managed_lustre_file_system.html.markdown | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/website/docs/r/managed_lustre_file_system.html.markdown b/website/docs/r/managed_lustre_file_system.html.markdown index 97944a8d612c..8cb46d78f709 100644 --- a/website/docs/r/managed_lustre_file_system.html.markdown +++ b/website/docs/r/managed_lustre_file_system.html.markdown @@ -62,7 +62,9 @@ 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. Changing this forces a new resource to be created. 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). + +-> **NOTE:** If you are interested in `storage_capacity_in_tb` values larger than what is listed as the maximum `storage_capacity_in_tb` in the product documentation for your organization, please open a Microsoft support ticket. * `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. From 41449d4beef3b950e0b8a1e6f7c2f96494ebaed2 Mon Sep 17 00:00:00 2001 From: Jeffrey Cline <20408400+WodansSon@users.noreply.github.com> Date: Tue, 10 Oct 2023 17:48:31 -0600 Subject: [PATCH 3/4] Address PR comments... --- .../managed_lustre_file_system_resource.go | 47 +++++++++++-------- .../managed_lustre_file_system.html.markdown | 3 +- 2 files changed, 29 insertions(+), 21 deletions(-) diff --git a/internal/services/azuremanagedlustrefilesystem/managed_lustre_file_system_resource.go b/internal/services/azuremanagedlustrefilesystem/managed_lustre_file_system_resource.go index 080d7a886a83..31767f126012 100644 --- a/internal/services/azuremanagedlustrefilesystem/managed_lustre_file_system_resource.go +++ b/internal/services/azuremanagedlustrefilesystem/managed_lustre_file_system_resource.go @@ -52,7 +52,7 @@ type MaintenanceWindow struct { type SkuProperties struct { Name string - MinumumStorage int + MinimumStorage int } type ManagedLustreFileSystemResource struct{} @@ -60,10 +60,10 @@ type ManagedLustreFileSystemResource struct{} var _ sdk.ResourceWithUpdate = ManagedLustreFileSystemResource{} var _ sdk.ResourceWithCustomizeDiff = ManagedLustreFileSystemResource{} -func GetSkuPropertiesByName(skuName string) interface{} { +func GetSkuPropertiesByName(skuName string) *SkuProperties { for _, sku := range PossibleSkuProperties() { if skuName == sku.Name { - return sku + return pointer.To(sku) } } @@ -71,7 +71,7 @@ func GetSkuPropertiesByName(skuName string) interface{} { } func PossibleValuesForSkuName() []string { - var skus []string + skus := make([]string, 0) for _, sku := range PossibleSkuProperties() { skus = append(skus, sku.Name) @@ -82,10 +82,22 @@ func PossibleValuesForSkuName() []string { func PossibleSkuProperties() []SkuProperties { return []SkuProperties{ - {"AMLFS-Durable-Premium-40", 48}, - {"AMLFS-Durable-Premium-125", 16}, - {"AMLFS-Durable-Premium-250", 8}, - {"AMLFS-Durable-Premium-500", 4}, + { + 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, + }, } } @@ -230,19 +242,16 @@ func (r ManagedLustreFileSystemResource) CustomizeDiff() sdk.ResourceFunc { } } - _, configSku := metadata.ResourceDiff.GetChange("sku_name") - _, configCapacity := metadata.ResourceDiff.GetChange("storage_capacity_in_tb") + configSku := metadata.ResourceDiff.Get("sku_name") + configCapacity := metadata.ResourceDiff.Get("storage_capacity_in_tb") + skuProperties := GetSkuPropertiesByName(configSku.(string)) - if sku := GetSkuPropertiesByName(configSku.(string)); sku != nil { - if skuProperties, ok := sku.(SkuProperties); ok { - if configCapacity.(int) < skuProperties.MinumumStorage { - return fmt.Errorf("'storage_capacity_in_tb' field cannot be less than '%d' for the %q sku, got '%d'", skuProperties.MinumumStorage, configSku, configCapacity) - } + 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.MinumumStorage != 0 { - return fmt.Errorf("'storage_capacity_in_tb' field must be defined in increments of '%d' for the %q sku, got '%d'", skuProperties.MinumumStorage, 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 8cb46d78f709..0f9786bcac83 100644 --- a/website/docs/r/managed_lustre_file_system.html.markdown +++ b/website/docs/r/managed_lustre_file_system.html.markdown @@ -62,9 +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. The valid values for this field are dependant on which `sku_name` has been defined in the configuration file. Changing this forces a new resource to be created. 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). +* `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. --> **NOTE:** If you are interested in `storage_capacity_in_tb` values larger than what is listed as the maximum `storage_capacity_in_tb` in the product documentation for your organization, please open a Microsoft support ticket. * `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. From 7867f0afd651d8de7bbe58f54e8f62e80aee429b Mon Sep 17 00:00:00 2001 From: Jeffrey Cline <20408400+WodansSon@users.noreply.github.com> Date: Wed, 11 Oct 2023 14:03:11 -0600 Subject: [PATCH 4/4] Add nil check for skuProperties... --- .../managed_lustre_file_system_resource.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/internal/services/azuremanagedlustrefilesystem/managed_lustre_file_system_resource.go b/internal/services/azuremanagedlustrefilesystem/managed_lustre_file_system_resource.go index 31767f126012..3d88bf7a00e3 100644 --- a/internal/services/azuremanagedlustrefilesystem/managed_lustre_file_system_resource.go +++ b/internal/services/azuremanagedlustrefilesystem/managed_lustre_file_system_resource.go @@ -246,12 +246,14 @@ func (r ManagedLustreFileSystemResource) CustomizeDiff() sdk.ResourceFunc { configCapacity := metadata.ResourceDiff.Get("storage_capacity_in_tb") skuProperties := GetSkuPropertiesByName(configSku.(string)) - 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 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) + 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