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

Mysql flexible server iops scaling #23329

Merged
11 changes: 8 additions & 3 deletions internal/services/mysql/mysql_flexible_server_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,10 @@ func dataSourceMysqlFlexibleServer() *pluginsdk.Resource {
Type: pluginsdk.TypeInt,
Computed: true,
},
"io_scaling_enabled": {
Type: pluginsdk.TypeBool,
Computed: true,
},
},
},
},
Expand Down Expand Up @@ -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,
},
}
}
Expand Down
25 changes: 21 additions & 4 deletions internal/services/mysql/mysql_flexible_server_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
},
},
},
Expand Down Expand Up @@ -355,6 +360,11 @@ func resourceMysqlFlexibleServerCreate(d *pluginsdk.ResourceData, meta interface
}
}

storageSettings := expandArmServerStorage(d.Get("storage").([]interface{}))
if storageSettings.Iops != nil && *storageSettings.AutoIoScaling == servers.EnableStatusEnumEnabled {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests are failing at this point, this probably wants to be checked differently

Test ended in panic.
------- Stdout: -------
=== RUN   TestAccDataSourceMySqlFlexibleServer_basic
=== PAUSE TestAccDataSourceMySqlFlexibleServer_basic
=== CONT  TestAccDataSourceMySqlFlexibleServer_basic
------- Stderr: -------
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x10 pc=0x4a64c28]
goroutine 391 [running]:
github.com/hashicorp/terraform-provider-azurerm/internal/services/mysql.resourceMysqlFlexibleServerCreate(0x0?, {0x66bcc80?, 0xc001d7c000?})
  /opt/teamcity-agent/work/3337027aeff310bf/internal/services/mysql/mysql_flexible_server_resource.go:364 +0x6e8
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).create(0x7d06a00?, {0x7d06a00?, 0xc000fe5ef0?}, 0xd?, {0x66bcc80?, 0xc001d7c000?})
  /opt/teamcity-agent/work/3337027aeff310bf/vendor/github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema/resource.go:766 +0x178
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).Apply(0xc00225bce0, {0x7d06a00, 0xc000fe5ef0}, 0xc001f8b450, 0xc000dc9800, {0x66bcc80, 0xc001d7c000})
  /opt/teamcity-agent/work/3337027aeff310bf/vendor/github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema/resource.go:909 +0xa7e
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*GRPCProviderServer).ApplyResourceChange(0xc0044a00d8, {0x7d06a00?, 0xc000fe5e30?}, 0xc0003b3db0)
  /opt/teamcity-agent/work/3337027aeff310bf/vendor/github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema/grpc_provider.go:1060 +0xe8d
github.com/hashicorp/terraform-plugin-go/tfprotov5/tf5server.(*server).ApplyResourceChange(0xc003a09c20, {0x7d06a00?, 0xc000fe5620?}, 0xc000fe9810)
  /opt/teamcity-agent/work/3337027aeff310bf/vendor/github.com/hashicorp/terraform-plugin-go/tfprotov5/tf5server/server.go:859 +0x574
github.com/hashicorp/terraform-plugin-go/tfprotov5/internal/tfplugin5._Provider_ApplyResourceChange_Handler({0x710d960?, 0xc003a09c20}, {0x7d06a00, 0xc000fe5620}, 0xc000fe97a0, 0x0)
  /opt/teamcity-agent/work/3337027aeff310bf/vendor/github.com/hashicorp/terraform-plugin-go/tfprotov5/internal/tfplugin5/tfplugin5_grpc.pb.go:467 +0x170
google.golang.org/grpc.(*Server).processUnaryRPC(0xc0052e25a0, {0x7d17cc0, 0xc005d804e0}, 0xc000fe3c20, 0xc002ee5650, 0xc8723f8, 0x0)
  /opt/teamcity-agent/work/3337027aeff310bf/vendor/google.golang.org/grpc/server.go:1376 +0xdd2
google.golang.org/grpc.(*Server).handleStream(0xc0052e25a0, {0x7d17cc0, 0xc005d804e0}, 0xc000fe3c20, 0x0)
  /opt/teamcity-agent/work/3337027aeff310bf/vendor/google.golang.org/grpc/server.go:1753 +0xa36
google.golang.org/grpc.(*Server).serveStreams.func1.1()
  /opt/teamcity-agent/work/3337027aeff310bf/vendor/google.golang.org/grpc/server.go:998 +0x98
created by google.golang.org/grpc.(*Server).serveStreams.func1
  /opt/teamcity-agent/work/3337027aeff310bf/vendor/google.golang.org/grpc/server.go:996 +0x18c

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed - forgot to check whether the Storage block was even set.

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)
Expand Down Expand Up @@ -764,8 +774,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 {
Expand Down Expand Up @@ -795,9 +811,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,
},
}
}
Expand Down
53 changes: 43 additions & 10 deletions internal/services/mysql/mysql_flexible_server_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
),
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand All @@ -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 {
Expand Down
2 changes: 2 additions & 0 deletions website/docs/d/mysql_flexible_server.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions website/docs/r/mysql_flexible_server.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down
Loading