From 9de2c5d7757732faace75904aea086b7449ea51e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Theis=20Ferr=C3=A9=20Hjortkj=C3=A6r?= Date: Wed, 27 Sep 2023 08:52:05 +0200 Subject: [PATCH] Mysql flexible server iops scaling (#23329) * add support for iops scaling * add validation to create function * add documentation for io_scaling_enabled * add test with io_scaling enabled * formatted test string * Changed iops to upper case for documentation * added test config with no iops * set deault of io_scaling_enabled to false * run terrafmt to format config strings * change default value to 'false' --- .../mysql_flexible_server_data_source.go | 11 ++-- .../mysql/mysql_flexible_server_resource.go | 27 ++++++++-- .../mysql_flexible_server_resource_test.go | 53 +++++++++++++++---- .../d/mysql_flexible_server.html.markdown | 2 + .../r/mysql_flexible_server.html.markdown | 2 + 5 files changed, 78 insertions(+), 17 deletions(-) diff --git a/internal/services/mysql/mysql_flexible_server_data_source.go b/internal/services/mysql/mysql_flexible_server_data_source.go index 871b84757e2d..2bbeb2e7eec1 100644 --- a/internal/services/mysql/mysql_flexible_server_data_source.go +++ b/internal/services/mysql/mysql_flexible_server_data_source.go @@ -139,6 +139,10 @@ func dataSourceMysqlFlexibleServer() *pluginsdk.Resource { Type: pluginsdk.TypeInt, Computed: true, }, + "io_scaling_enabled": { + Type: pluginsdk.TypeBool, + Computed: true, + }, }, }, }, @@ -252,9 +256,10 @@ func flattenDataSourceArmServerStorage(storage *servers.Storage) []interface{} { return []interface{}{ map[string]interface{}{ - "size_gb": size, - "iops": iops, - "auto_grow_enabled": *storage.AutoGrow == servers.EnableStatusEnumEnabled, + "size_gb": size, + "iops": iops, + "auto_grow_enabled": *storage.AutoGrow == servers.EnableStatusEnumEnabled, + "io_scaling_enabled": *storage.AutoIoScaling == servers.EnableStatusEnumEnabled, }, } } diff --git a/internal/services/mysql/mysql_flexible_server_resource.go b/internal/services/mysql/mysql_flexible_server_resource.go index 99464198f07a..a0c9af745980 100644 --- a/internal/services/mysql/mysql_flexible_server_resource.go +++ b/internal/services/mysql/mysql_flexible_server_resource.go @@ -267,6 +267,11 @@ func resourceMysqlFlexibleServer() *pluginsdk.Resource { Computed: true, ValidateFunc: validation.IntBetween(20, 16384), }, + "io_scaling_enabled": { + Type: pluginsdk.TypeBool, + Optional: true, + Default: false, + }, }, }, }, @@ -355,6 +360,13 @@ func resourceMysqlFlexibleServerCreate(d *pluginsdk.ResourceData, meta interface } } + storageSettings := expandArmServerStorage(d.Get("storage").([]interface{})) + if storageSettings != nil { + if storageSettings.Iops != nil && *storageSettings.AutoIoScaling == servers.EnableStatusEnumEnabled { + return fmt.Errorf("`iops` can not be set if `io_scaling_enabled` is set to true") + } + } + sku, err := expandFlexibleServerSku(d.Get("sku_name").(string)) if err != nil { return fmt.Errorf("expanding `sku_name` for %s: %+v", id, err) @@ -764,8 +776,14 @@ func expandArmServerStorage(inputs []interface{}) *servers.Storage { autoGrow = servers.EnableStatusEnumEnabled } + autoIoScaling := servers.EnableStatusEnumDisabled + if v := input["io_scaling_enabled"].(bool); v { + autoIoScaling = servers.EnableStatusEnumEnabled + } + storage := servers.Storage{ - AutoGrow: &autoGrow, + AutoGrow: &autoGrow, + AutoIoScaling: &autoIoScaling, } if v := input["size_gb"].(int); v != 0 { @@ -795,9 +813,10 @@ func flattenArmServerStorage(storage *servers.Storage) []interface{} { return []interface{}{ map[string]interface{}{ - "size_gb": size, - "iops": iops, - "auto_grow_enabled": *storage.AutoGrow == servers.EnableStatusEnumEnabled, + "size_gb": size, + "iops": iops, + "auto_grow_enabled": *storage.AutoGrow == servers.EnableStatusEnumEnabled, + "io_scaling_enabled": *storage.AutoIoScaling == servers.EnableStatusEnumEnabled, }, } } diff --git a/internal/services/mysql/mysql_flexible_server_resource_test.go b/internal/services/mysql/mysql_flexible_server_resource_test.go index a563427a9590..39b96a9ee3aa 100644 --- a/internal/services/mysql/mysql_flexible_server_resource_test.go +++ b/internal/services/mysql/mysql_flexible_server_resource_test.go @@ -361,14 +361,21 @@ func TestAccMySqlFlexibleServer_updateStorage(t *testing.T) { data.ResourceTest(t, r, []acceptance.TestStep{ { - Config: r.updateStorage(data, 20, 360, true), + Config: r.updateStorage(data, 20, 360, true, false), Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), ), }, data.ImportStep("administrator_password"), { - Config: r.updateStorage(data, 34, 402, false), + Config: r.updateStorage(data, 34, 402, false, false), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.ImportStep("administrator_password"), + { + Config: r.updateStorageNoIOPS(data, 34, false, true), Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), ), @@ -701,9 +708,10 @@ resource "azurerm_mysql_flexible_server" "test" { geo_redundant_backup_enabled = false storage { - size_gb = 32 - iops = 400 - auto_grow_enabled = false + size_gb = 32 + iops = 400 + auto_grow_enabled = false + io_scaling_enabled = false } delegated_subnet_id = azurerm_subnet.test.id @@ -970,7 +978,32 @@ resource "azurerm_mysql_flexible_server" "geo_restore" { `, r.geoRestoreSource(data), data.RandomInteger, os.Getenv("ARM_GEO_RESTORE_LOCATION")) } -func (r MySqlFlexibleServerResource) updateStorage(data acceptance.TestData, sizeGB int, iops int, enabled bool) string { +func (r MySqlFlexibleServerResource) updateStorage(data acceptance.TestData, sizeGB int, iops int, autoGrowEnabled bool, ioScalingEnabled bool) string { + return fmt.Sprintf(` +%s + +resource "azurerm_mysql_flexible_server" "test" { + name = "acctest-fs-%d" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location + administrator_login = "adminTerraform" + administrator_password = "QAZwsx123" + sku_name = "GP_Standard_D4ds_v4" + geo_redundant_backup_enabled = true + version = "8.0.21" + zone = "1" + + storage { + size_gb = %d + iops = %d + auto_grow_enabled = %t + io_scaling_enabled = %t + } +} +`, r.template(data), data.RandomInteger, sizeGB, iops, autoGrowEnabled, ioScalingEnabled) +} + +func (r MySqlFlexibleServerResource) updateStorageNoIOPS(data acceptance.TestData, sizeGB int, autoGrowEnabled bool, ioScalingEnabled bool) string { return fmt.Sprintf(` %s @@ -986,12 +1019,12 @@ resource "azurerm_mysql_flexible_server" "test" { zone = "1" storage { - size_gb = %d - iops = %d - auto_grow_enabled = %t + size_gb = %d + auto_grow_enabled = %t + io_scaling_enabled = %t } } -`, r.template(data), data.RandomInteger, sizeGB, iops, enabled) +`, r.template(data), data.RandomInteger, sizeGB, autoGrowEnabled, ioScalingEnabled) } func (r MySqlFlexibleServerResource) failover(data acceptance.TestData, primaryZone string, standbyZone string) string { diff --git a/website/docs/d/mysql_flexible_server.html.markdown b/website/docs/d/mysql_flexible_server.html.markdown index 4290c328aa1f..1391b5c19df0 100644 --- a/website/docs/d/mysql_flexible_server.html.markdown +++ b/website/docs/d/mysql_flexible_server.html.markdown @@ -93,6 +93,8 @@ A `storage` block exports the following: * `auto_grow_enabled` - Is Storage Auto Grow enabled? +* `io_scaling_enabled` - Should IOPS be scaled automatically? + * `iops` - The storage IOPS of the MySQL Flexible Server. * `size_gb` - The max storage allowed for the MySQL Flexible Server. diff --git a/website/docs/r/mysql_flexible_server.html.markdown b/website/docs/r/mysql_flexible_server.html.markdown index 6d098f1c8a23..17365dcc6dcd 100644 --- a/website/docs/r/mysql_flexible_server.html.markdown +++ b/website/docs/r/mysql_flexible_server.html.markdown @@ -189,6 +189,8 @@ A `storage` block supports the following: * `auto_grow_enabled` - (Optional) Should Storage Auto Grow be enabled? Defaults to `true`. +* `io_scaling_enabled` - (Optional) Should IOPS be scaled automatically? If `true`, `iops` can not be set. Defaults to `false`. + * `iops` - (Optional) The storage IOPS for the MySQL Flexible Server. Possible values are between `360` and `20000`. * `size_gb` - (Optional) The max storage allowed for the MySQL Flexible Server. Possible values are between `20` and `16384`.