From de0b1279236a5a0c4033738a9c5ee97e3e0b6ebd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Theis=20Ferr=C3=A9=20Hjortkj=C3=A6r?= Date: Tue, 19 Sep 2023 11:55:16 +0200 Subject: [PATCH 01/10] add support for iops scaling --- .../mysql_flexible_server_data_source.go | 11 +++++++--- .../mysql/mysql_flexible_server_resource.go | 20 +++++++++++++---- .../mysql_flexible_server_resource_test.go | 22 ++++++++++--------- 3 files changed, 36 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..e806efd129f9 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, + }, }, }, }, @@ -764,8 +769,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 +806,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.EnableStatusEnumDisabled, }, } } diff --git a/internal/services/mysql/mysql_flexible_server_resource_test.go b/internal/services/mysql/mysql_flexible_server_resource_test.go index a563427a9590..5388e5226961 100644 --- a/internal/services/mysql/mysql_flexible_server_resource_test.go +++ b/internal/services/mysql/mysql_flexible_server_resource_test.go @@ -361,14 +361,14 @@ 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), ), @@ -701,9 +701,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 + auto_io_scaling_enabled = false } delegated_subnet_id = azurerm_subnet.test.id @@ -970,7 +971,7 @@ 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 @@ -986,12 +987,13 @@ resource "azurerm_mysql_flexible_server" "test" { zone = "1" storage { - size_gb = %d - iops = %d - auto_grow_enabled = %t + size_gb = %d + iops = %d + auto_grow_enabled = %t + auto_io_scaling_enabled = %t } } -`, r.template(data), data.RandomInteger, sizeGB, iops, enabled) +`, r.template(data), data.RandomInteger, sizeGB, iops, autoGrowEnabled, ioScalingEnabled) } func (r MySqlFlexibleServerResource) failover(data acceptance.TestData, primaryZone string, standbyZone string) string { From f04171a2009cfbf0f7bb593f2de259243ae97142 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Theis=20Ferr=C3=A9=20Hjortkj=C3=A6r?= Date: Tue, 19 Sep 2023 22:21:22 +0200 Subject: [PATCH 02/10] add validation to create function --- .../services/mysql/mysql_flexible_server_resource.go | 9 +++++++-- .../mysql/mysql_flexible_server_resource_test.go | 4 ++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/internal/services/mysql/mysql_flexible_server_resource.go b/internal/services/mysql/mysql_flexible_server_resource.go index e806efd129f9..56085c0026c8 100644 --- a/internal/services/mysql/mysql_flexible_server_resource.go +++ b/internal/services/mysql/mysql_flexible_server_resource.go @@ -270,7 +270,7 @@ func resourceMysqlFlexibleServer() *pluginsdk.Resource { "io_scaling_enabled": { Type: pluginsdk.TypeBool, Optional: true, - Default: false, + Default: true, }, }, }, @@ -360,6 +360,11 @@ func resourceMysqlFlexibleServerCreate(d *pluginsdk.ResourceData, meta interface } } + storageSettings := expandArmServerStorage(d.Get("storage").([]interface{})) + 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) @@ -809,7 +814,7 @@ func flattenArmServerStorage(storage *servers.Storage) []interface{} { "size_gb": size, "iops": iops, "auto_grow_enabled": *storage.AutoGrow == servers.EnableStatusEnumEnabled, - "io_scaling_enabled": *storage.AutoIoScaling == servers.EnableStatusEnumDisabled, + "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 5388e5226961..e28bfe504d1a 100644 --- a/internal/services/mysql/mysql_flexible_server_resource_test.go +++ b/internal/services/mysql/mysql_flexible_server_resource_test.go @@ -704,7 +704,7 @@ resource "azurerm_mysql_flexible_server" "test" { size_gb = 32 iops = 400 auto_grow_enabled = false - auto_io_scaling_enabled = false + io_scaling_enabled = false } delegated_subnet_id = azurerm_subnet.test.id @@ -990,7 +990,7 @@ resource "azurerm_mysql_flexible_server" "test" { size_gb = %d iops = %d auto_grow_enabled = %t - auto_io_scaling_enabled = %t + io_scaling_enabled = %t } } `, r.template(data), data.RandomInteger, sizeGB, iops, autoGrowEnabled, ioScalingEnabled) From 88bb2a9233964de3ba0579d50706679ae051ae1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Theis=20Ferr=C3=A9=20Hjortkj=C3=A6r?= Date: Tue, 19 Sep 2023 22:21:45 +0200 Subject: [PATCH 03/10] add documentation for io_scaling_enabled --- website/docs/d/mysql_flexible_server.html.markdown | 2 ++ website/docs/r/mysql_flexible_server.html.markdown | 2 ++ 2 files changed, 4 insertions(+) diff --git a/website/docs/d/mysql_flexible_server.html.markdown b/website/docs/d/mysql_flexible_server.html.markdown index 4290c328aa1f..01fed8891692 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..4b534c01ead5 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 `true`. + * `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`. From 9c293a81b7f97d94924bf5edc386afa700146192 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Theis=20Ferr=C3=A9=20Hjortkj=C3=A6r?= Date: Tue, 19 Sep 2023 22:25:29 +0200 Subject: [PATCH 04/10] add test with io_scaling enabled --- .../services/mysql/mysql_flexible_server_resource_test.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/internal/services/mysql/mysql_flexible_server_resource_test.go b/internal/services/mysql/mysql_flexible_server_resource_test.go index e28bfe504d1a..1d1955bc8792 100644 --- a/internal/services/mysql/mysql_flexible_server_resource_test.go +++ b/internal/services/mysql/mysql_flexible_server_resource_test.go @@ -374,6 +374,13 @@ func TestAccMySqlFlexibleServer_updateStorage(t *testing.T) { ), }, data.ImportStep("administrator_password"), + { + Config: r.updateStorage(data, 34, nil, false, true), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.ImportStep("administrator_password"), }) } From ebcb277de449f48c23e9b8c770c0ae012611153f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Theis=20Ferr=C3=A9=20Hjortkj=C3=A6r?= Date: Tue, 19 Sep 2023 22:34:03 +0200 Subject: [PATCH 05/10] formatted test string --- .../mysql/mysql_flexible_server_resource_test.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/internal/services/mysql/mysql_flexible_server_resource_test.go b/internal/services/mysql/mysql_flexible_server_resource_test.go index 1d1955bc8792..cf2c06259274 100644 --- a/internal/services/mysql/mysql_flexible_server_resource_test.go +++ b/internal/services/mysql/mysql_flexible_server_resource_test.go @@ -708,10 +708,10 @@ resource "azurerm_mysql_flexible_server" "test" { geo_redundant_backup_enabled = false storage { - size_gb = 32 - iops = 400 - auto_grow_enabled = false - io_scaling_enabled = false + size_gb = 32 + iops = 400 + auto_grow_enabled = false + io_scaling_enabled = false } delegated_subnet_id = azurerm_subnet.test.id @@ -994,10 +994,10 @@ resource "azurerm_mysql_flexible_server" "test" { zone = "1" storage { - size_gb = %d - iops = %d - auto_grow_enabled = %t - io_scaling_enabled = %t + size_gb = %d + iops = %d + auto_grow_enabled = %t + io_scaling_enabled = %t } } `, r.template(data), data.RandomInteger, sizeGB, iops, autoGrowEnabled, ioScalingEnabled) From af61abc6e8158cdec47572d7f33ab47b2072597d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Theis=20Ferr=C3=A9=20Hjortkj=C3=A6r?= Date: Wed, 20 Sep 2023 09:46:22 +0200 Subject: [PATCH 06/10] Changed iops to upper case for documentation --- website/docs/d/mysql_flexible_server.html.markdown | 2 +- website/docs/r/mysql_flexible_server.html.markdown | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/website/docs/d/mysql_flexible_server.html.markdown b/website/docs/d/mysql_flexible_server.html.markdown index 01fed8891692..1391b5c19df0 100644 --- a/website/docs/d/mysql_flexible_server.html.markdown +++ b/website/docs/d/mysql_flexible_server.html.markdown @@ -93,7 +93,7 @@ A `storage` block exports the following: * `auto_grow_enabled` - Is Storage Auto Grow enabled? -* `io_scaling_enabled` - Should iops be scaled automatically? +* `io_scaling_enabled` - Should IOPS be scaled automatically? * `iops` - The storage IOPS of 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 4b534c01ead5..07d4eaff346b 100644 --- a/website/docs/r/mysql_flexible_server.html.markdown +++ b/website/docs/r/mysql_flexible_server.html.markdown @@ -189,7 +189,7 @@ 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 `true`. +* `io_scaling_enabled` - (Optional) Should IOPS be scaled automatically? If `true`, `iops` can not be set. Defaults to `true`. * `iops` - (Optional) The storage IOPS for the MySQL Flexible Server. Possible values are between `360` and `20000`. From ecfb8f4a05fdd3c8af8d389d419917d33e74ddfe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Theis=20Ferr=C3=A9=20Hjortkj=C3=A6r?= Date: Wed, 20 Sep 2023 10:15:51 +0200 Subject: [PATCH 07/10] added test config with no iops --- .../mysql_flexible_server_resource_test.go | 26 ++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/internal/services/mysql/mysql_flexible_server_resource_test.go b/internal/services/mysql/mysql_flexible_server_resource_test.go index cf2c06259274..810551ce316f 100644 --- a/internal/services/mysql/mysql_flexible_server_resource_test.go +++ b/internal/services/mysql/mysql_flexible_server_resource_test.go @@ -375,7 +375,7 @@ func TestAccMySqlFlexibleServer_updateStorage(t *testing.T) { }, data.ImportStep("administrator_password"), { - Config: r.updateStorage(data, 34, nil, false, true), + Config: r.updateStorageNoIOPS(data, 34, false, true), Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), ), @@ -1003,6 +1003,30 @@ resource "azurerm_mysql_flexible_server" "test" { `, 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 + +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 + auto_grow_enabled = %t + io_scaling_enabled = %t + } +} +`, r.template(data), data.RandomInteger, sizeGB, autoGrowEnabled, ioScalingEnabled) +} + func (r MySqlFlexibleServerResource) failover(data acceptance.TestData, primaryZone string, standbyZone string) string { return fmt.Sprintf(` %s From 50bd5db26e2c192062190338e5fa4cfbb55fcd13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Theis=20Ferr=C3=A9=20Hjortkj=C3=A6r?= Date: Thu, 21 Sep 2023 22:26:03 +0200 Subject: [PATCH 08/10] set deault of io_scaling_enabled to false --- internal/services/mysql/mysql_flexible_server_resource.go | 2 +- website/docs/r/mysql_flexible_server.html.markdown | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/services/mysql/mysql_flexible_server_resource.go b/internal/services/mysql/mysql_flexible_server_resource.go index 56085c0026c8..575801916da9 100644 --- a/internal/services/mysql/mysql_flexible_server_resource.go +++ b/internal/services/mysql/mysql_flexible_server_resource.go @@ -270,7 +270,7 @@ func resourceMysqlFlexibleServer() *pluginsdk.Resource { "io_scaling_enabled": { Type: pluginsdk.TypeBool, Optional: true, - Default: true, + Default: false, }, }, }, diff --git a/website/docs/r/mysql_flexible_server.html.markdown b/website/docs/r/mysql_flexible_server.html.markdown index 07d4eaff346b..17365dcc6dcd 100644 --- a/website/docs/r/mysql_flexible_server.html.markdown +++ b/website/docs/r/mysql_flexible_server.html.markdown @@ -189,7 +189,7 @@ 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 `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`. From 1e211cd99ef0d0de4c6cdef5f1f879640a9ea4f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Theis=20Ferr=C3=A9=20Hjortkj=C3=A6r?= Date: Fri, 22 Sep 2023 11:46:44 +0200 Subject: [PATCH 09/10] run terrafmt to format config strings --- .../services/mysql/mysql_flexible_server_resource_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/internal/services/mysql/mysql_flexible_server_resource_test.go b/internal/services/mysql/mysql_flexible_server_resource_test.go index 810551ce316f..39b96a9ee3aa 100644 --- a/internal/services/mysql/mysql_flexible_server_resource_test.go +++ b/internal/services/mysql/mysql_flexible_server_resource_test.go @@ -711,7 +711,7 @@ resource "azurerm_mysql_flexible_server" "test" { size_gb = 32 iops = 400 auto_grow_enabled = false - io_scaling_enabled = false + io_scaling_enabled = false } delegated_subnet_id = azurerm_subnet.test.id @@ -997,7 +997,7 @@ resource "azurerm_mysql_flexible_server" "test" { size_gb = %d iops = %d auto_grow_enabled = %t - io_scaling_enabled = %t + io_scaling_enabled = %t } } `, r.template(data), data.RandomInteger, sizeGB, iops, autoGrowEnabled, ioScalingEnabled) @@ -1021,7 +1021,7 @@ resource "azurerm_mysql_flexible_server" "test" { storage { size_gb = %d auto_grow_enabled = %t - io_scaling_enabled = %t + io_scaling_enabled = %t } } `, r.template(data), data.RandomInteger, sizeGB, autoGrowEnabled, ioScalingEnabled) From d29122c97de099bf239ca0b1ebce1783d8a5b69e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Theis=20Ferr=C3=A9=20Hjortkj=C3=A6r?= Date: Fri, 22 Sep 2023 11:47:10 +0200 Subject: [PATCH 10/10] change default value to 'false' --- internal/services/mysql/mysql_flexible_server_resource.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/internal/services/mysql/mysql_flexible_server_resource.go b/internal/services/mysql/mysql_flexible_server_resource.go index 575801916da9..a0c9af745980 100644 --- a/internal/services/mysql/mysql_flexible_server_resource.go +++ b/internal/services/mysql/mysql_flexible_server_resource.go @@ -361,8 +361,10 @@ func resourceMysqlFlexibleServerCreate(d *pluginsdk.ResourceData, meta interface } storageSettings := expandArmServerStorage(d.Get("storage").([]interface{})) - if storageSettings.Iops != nil && *storageSettings.AutoIoScaling == servers.EnableStatusEnumEnabled { - return fmt.Errorf("`iops` can not be set if `io_scaling_enabled` is set to true") + 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))