Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug:] azurerm_managed_lustre_file_system - correct validation for storage_capacity_in_tb minimum per sku_name and remove hardcoded maximum storage_capacity_in_tb #23428

Merged
merged 4 commits into from
Oct 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand Down Expand Up @@ -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),
katbyte marked this conversation as resolved.
Show resolved Hide resolved
),
Type: pluginsdk.TypeInt,
Required: true,
ForceNew: true,
ValidateFunc: validation.IntAtLeast(4),
},

"subnet_id": {
Expand Down Expand Up @@ -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
},
}
Expand Down
3 changes: 2 additions & 1 deletion website/docs/r/managed_lustre_file_system.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
Loading