Skip to content

Commit

Permalink
Merge pull request #28 from hashicorp/main
Browse files Browse the repository at this point in the history
Fork Sync: Update from parent repository
  • Loading branch information
mbialon authored Sep 27, 2023
2 parents f54eef5 + 9de2c5d commit 6deafd6
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 17 deletions.
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
27 changes: 23 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,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)
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
},
}
}
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

0 comments on commit 6deafd6

Please sign in to comment.