diff --git a/azurerm/resource_arm_mysql_server.go b/azurerm/resource_arm_mysql_server.go index 4cac674c7075..8b08f364fa2c 100644 --- a/azurerm/resource_arm_mysql_server.go +++ b/azurerm/resource_arm_mysql_server.go @@ -80,7 +80,6 @@ func resourceArmMySqlServer() *schema.Resource { "tier": { Type: schema.TypeString, Required: true, - ForceNew: true, ValidateFunc: validation.StringInSlice([]string{ string(mysql.Basic), string(mysql.GeneralPurpose), @@ -92,7 +91,6 @@ func resourceArmMySqlServer() *schema.Resource { "family": { Type: schema.TypeString, Required: true, - ForceNew: true, ValidateFunc: validation.StringInSlice([]string{ "Gen4", "Gen5", diff --git a/azurerm/resource_arm_mysql_server_test.go b/azurerm/resource_arm_mysql_server_test.go index dbafd19ba65d..3fcaf8653ae1 100644 --- a/azurerm/resource_arm_mysql_server_test.go +++ b/azurerm/resource_arm_mysql_server_test.go @@ -73,7 +73,7 @@ func TestAccAzureRMMySqlServer_generalPurpose(t *testing.T) { func TestAccAzureRMMySqlServer_memoryOptimized(t *testing.T) { resourceName := "azurerm_mysql_server.test" ri := acctest.RandInt() - config := testAccAzureRMMySQLServer_memoryOptimized(ri, testLocation()) + config := testAccAzureRMMySQLServer_memoryOptimizedGeoRedundant(ri, testLocation()) resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -126,6 +126,46 @@ func TestAccAzureRMMySQLServer_basicFiveSevenUpdated(t *testing.T) { }) } +func TestAccAzureRMMySQLServer_updateSKU(t *testing.T) { + resourceName := "azurerm_mysql_server.test" + ri := acctest.RandInt() + location := testLocation() + config := testAccAzureRMMySQLServer_generalPurpose(ri, location) + updatedConfig := testAccAzureRMMySQLServer_memoryOptimized(ri, location) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureRMMySQLServerDestroy, + Steps: []resource.TestStep{ + { + Config: config, + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMMySQLServerExists(resourceName), + resource.TestCheckResourceAttr(resourceName, "sku.0.name", "GP_Gen4_32"), + resource.TestCheckResourceAttr(resourceName, "sku.0.capacity", "32"), + resource.TestCheckResourceAttr(resourceName, "sku.0.tier", "GeneralPurpose"), + resource.TestCheckResourceAttr(resourceName, "sku.0.family", "Gen4"), + resource.TestCheckResourceAttr(resourceName, "storage_profile.0.storage_mb", "640000"), + resource.TestCheckResourceAttr(resourceName, "administrator_login", "acctestun"), + ), + }, + { + Config: updatedConfig, + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMMySQLServerExists(resourceName), + resource.TestCheckResourceAttr(resourceName, "sku.0.name", "MO_Gen5_16"), + resource.TestCheckResourceAttr(resourceName, "sku.0.capacity", "16"), + resource.TestCheckResourceAttr(resourceName, "sku.0.tier", "MemoryOptimized"), + resource.TestCheckResourceAttr(resourceName, "sku.0.family", "Gen5"), + resource.TestCheckResourceAttr(resourceName, "storage_profile.0.storage_mb", "4194304"), + resource.TestCheckResourceAttr(resourceName, "administrator_login", "acctestun"), + ), + }, + }, + }) +} + // func testCheckAzureRMMySQLServerExists(name string) resource.TestCheckFunc { @@ -203,9 +243,9 @@ resource "azurerm_mysql_server" "test" { } storage_profile { - storage_mb = 51200 + storage_mb = 51200 backup_retention_days = 7 - geo_redundant_backup = "Disabled" + geo_redundant_backup = "Disabled" } administrator_login = "acctestun" @@ -236,9 +276,9 @@ resource "azurerm_mysql_server" "test" { } storage_profile { - storage_mb = 51200 + storage_mb = 51200 backup_retention_days = 7 - geo_redundant_backup = "Disabled" + geo_redundant_backup = "Disabled" } administrator_login = "acctestun" @@ -269,9 +309,9 @@ resource "azurerm_mysql_server" "test" { } storage_profile { - storage_mb = 640000 + storage_mb = 640000 backup_retention_days = 7 - geo_redundant_backup = "Disabled" + geo_redundant_backup = "Disabled" } administrator_login = "acctestun" @@ -295,16 +335,16 @@ resource "azurerm_mysql_server" "test" { resource_group_name = "${azurerm_resource_group.test.name}" sku { - name = "GP_Gen5_32" + name = "GP_Gen4_32" capacity = 32 tier = "GeneralPurpose" - family = "Gen5" + family = "Gen4" } storage_profile { - storage_mb = 640000 + storage_mb = 640000 backup_retention_days = 7 - geo_redundant_backup = "Disabled" + geo_redundant_backup = "Disabled" } administrator_login = "acctestun" @@ -335,9 +375,42 @@ resource "azurerm_mysql_server" "test" { } storage_profile { - storage_mb = 4194304, + storage_mb = 4194304, + backup_retention_days = 7 + geo_redundant_backup = "Disabled" + } + + administrator_login = "acctestun" + administrator_login_password = "H@Sh1CoR3!" + version = "5.7" + ssl_enforcement = "Enabled" +} +`, rInt, location, rInt) +} + +func testAccAzureRMMySQLServer_memoryOptimizedGeoRedundant(rInt int, location string) string { + return fmt.Sprintf(` +resource "azurerm_resource_group" "test" { + name = "acctestRG-%d" + location = "%s" +} + +resource "azurerm_mysql_server" "test" { + name = "acctestmysqlsvr-%d" + location = "${azurerm_resource_group.test.location}" + resource_group_name = "${azurerm_resource_group.test.name}" + + sku { + name = "MO_Gen5_16" + capacity = 16 + tier = "MemoryOptimized" + family = "Gen5" + } + + storage_profile { + storage_mb = 4194304, backup_retention_days = 7 - geo_redundant_backup = "Enabled" + geo_redundant_backup = "Enabled" } administrator_login = "acctestun" diff --git a/azurerm/resource_arm_postgresql_server.go b/azurerm/resource_arm_postgresql_server.go index fdc6deb11dd3..50ec62ba12ea 100644 --- a/azurerm/resource_arm_postgresql_server.go +++ b/azurerm/resource_arm_postgresql_server.go @@ -81,7 +81,6 @@ func resourceArmPostgreSQLServer() *schema.Resource { "tier": { Type: schema.TypeString, Required: true, - ForceNew: true, ValidateFunc: validation.StringInSlice([]string{ string(postgresql.Basic), string(postgresql.GeneralPurpose), @@ -93,7 +92,6 @@ func resourceArmPostgreSQLServer() *schema.Resource { "family": { Type: schema.TypeString, Required: true, - ForceNew: true, ValidateFunc: validation.StringInSlice([]string{ "Gen4", "Gen5", diff --git a/azurerm/resource_arm_postgresql_server_test.go b/azurerm/resource_arm_postgresql_server_test.go index b1c56f02c181..678ab110f6cd 100644 --- a/azurerm/resource_arm_postgresql_server_test.go +++ b/azurerm/resource_arm_postgresql_server_test.go @@ -124,7 +124,7 @@ func TestAccAzureRMPostgreSQLServer_generalPurpose(t *testing.T) { func TestAccAzureRMPostgreSQLServer_memoryOptimized(t *testing.T) { resourceName := "azurerm_postgresql_server.test" ri := acctest.RandInt() - config := testAccAzureRMPostgreSQLServer_memoryOptimized(ri, testLocation()) + config := testAccAzureRMPostgreSQLServer_memoryOptimizedGeoRedundant(ri, testLocation()) resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -205,6 +205,48 @@ func TestAccAzureRMPostgreSQLServer_updated(t *testing.T) { }) } +func TestAccAzureRMPostgreSQLServer_updateSKU(t *testing.T) { + resourceName := "azurerm_postgresql_server.test" + ri := acctest.RandInt() + location := testLocation() + config := testAccAzureRMPostgreSQLServer_generalPurpose(ri, location) + updatedConfig := testAccAzureRMPostgreSQLServer_memoryOptimized(ri, location) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureRMPostgreSQLServerDestroy, + Steps: []resource.TestStep{ + { + Config: config, + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMPostgreSQLServerExists(resourceName), + resource.TestCheckResourceAttr(resourceName, "sku.0.name", "GP_Gen4_32"), + resource.TestCheckResourceAttr(resourceName, "sku.0.capacity", "32"), + resource.TestCheckResourceAttr(resourceName, "sku.0.tier", "GeneralPurpose"), + resource.TestCheckResourceAttr(resourceName, "sku.0.family", "Gen4"), + resource.TestCheckResourceAttr(resourceName, "storage_profile.0.storage_mb", "640000"), + resource.TestCheckResourceAttr(resourceName, "administrator_login", "acctestun"), + ), + }, + { + Config: updatedConfig, + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMPostgreSQLServerExists(resourceName), + resource.TestCheckResourceAttr(resourceName, "sku.0.name", "MO_Gen5_16"), + resource.TestCheckResourceAttr(resourceName, "sku.0.capacity", "16"), + resource.TestCheckResourceAttr(resourceName, "sku.0.tier", "MemoryOptimized"), + resource.TestCheckResourceAttr(resourceName, "sku.0.family", "Gen5"), + resource.TestCheckResourceAttr(resourceName, "storage_profile.0.storage_mb", "4194304"), + resource.TestCheckResourceAttr(resourceName, "administrator_login", "acctestun"), + ), + }, + }, + }) +} + +// + func testCheckAzureRMPostgreSQLServerExists(name string) resource.TestCheckFunc { return func(s *terraform.State) error { // Ensure we have enough information in state to look up in API @@ -283,9 +325,9 @@ resource "azurerm_postgresql_server" "test" { } storage_profile { - storage_mb = 51200 + storage_mb = 51200 backup_retention_days = 7 - geo_redundant_backup = "Disabled" + geo_redundant_backup = "Disabled" } administrator_login = "acctestun" @@ -316,9 +358,9 @@ resource "azurerm_postgresql_server" "test" { } storage_profile { - storage_mb = 51200 + storage_mb = 51200 backup_retention_days = 7 - geo_redundant_backup = "Disabled" + geo_redundant_backup = "Disabled" } administrator_login = "acctestun" @@ -349,9 +391,9 @@ resource "azurerm_postgresql_server" "test" { } storage_profile { - storage_mb = 51200 + storage_mb = 51200 backup_retention_days = 7 - geo_redundant_backup = "Disabled" + geo_redundant_backup = "Disabled" } administrator_login = "acctestun" @@ -382,9 +424,9 @@ resource "azurerm_postgresql_server" "test" { } storage_profile { - storage_mb = 51200 + storage_mb = 51200 backup_retention_days = 7 - geo_redundant_backup = "Disabled" + geo_redundant_backup = "Disabled" } administrator_login = "acctestun" @@ -416,9 +458,9 @@ resource "azurerm_postgresql_server" "test" { } storage_profile { - storage_mb = 640000 + storage_mb = 640000 backup_retention_days = 7 - geo_redundant_backup = "Disabled" + geo_redundant_backup = "Disabled" } administrator_login = "acctestun" @@ -449,9 +491,9 @@ resource "azurerm_postgresql_server" "test" { } storage_profile { - storage_mb = 947200 + storage_mb = 947200 backup_retention_days = 7 - geo_redundant_backup = "Disabled" + geo_redundant_backup = "Disabled" } administrator_login = "acctestun" @@ -475,16 +517,16 @@ resource "azurerm_postgresql_server" "test" { resource_group_name = "${azurerm_resource_group.test.name}" sku { - name = "GP_Gen5_32" + name = "GP_Gen4_32" capacity = 32 tier = "GeneralPurpose" - family = "Gen5" + family = "Gen4" } storage_profile { - storage_mb = 640000 + storage_mb = 640000 backup_retention_days = 7 - geo_redundant_backup = "Disabled" + geo_redundant_backup = "Disabled" } administrator_login = "acctestun" @@ -515,9 +557,42 @@ resource "azurerm_postgresql_server" "test" { } storage_profile { - storage_mb = 4194304 + storage_mb = 4194304 + backup_retention_days = 7 + geo_redundant_backup = "Disabled" + } + + administrator_login = "acctestun" + administrator_login_password = "H@Sh1CoR3!" + version = "9.6" + ssl_enforcement = "Enabled" +} +`, rInt, location, rInt) +} + +func testAccAzureRMPostgreSQLServer_memoryOptimizedGeoRedundant(rInt int, location string) string { + return fmt.Sprintf(` +resource "azurerm_resource_group" "test" { + name = "acctestRG-%d" + location = "%s" +} + +resource "azurerm_postgresql_server" "test" { + name = "acctestpsqlsvr-%d" + location = "${azurerm_resource_group.test.location}" + resource_group_name = "${azurerm_resource_group.test.name}" + + sku { + name = "MO_Gen5_16" + capacity = 16 + tier = "MemoryOptimized" + family = "Gen5" + } + + storage_profile { + storage_mb = 4194304 backup_retention_days = 7 - geo_redundant_backup = "Enabled" + geo_redundant_backup = "Enabled" } administrator_login = "acctestun" diff --git a/website/docs/r/mysql_server.html.markdown b/website/docs/r/mysql_server.html.markdown index a042301c8569..7c50a3c7aeaf 100644 --- a/website/docs/r/mysql_server.html.markdown +++ b/website/docs/r/mysql_server.html.markdown @@ -76,9 +76,9 @@ The following arguments are supported: * `capacity` - (Required) The scale up/out capacity, representing server's compute units. -* `tier` - (Required) The tier of the particular SKU. Possible values are `Basic`, `GeneralPurpose`, and `MemoryOptimized`. For more information see the [product documentation](https://docs.microsoft.com/en-us/azure/mysql/concepts-pricing-tiers). Changing this forces a new resource to be created. +* `tier` - (Required) The tier of the particular SKU. Possible values are `Basic`, `GeneralPurpose`, and `MemoryOptimized`. For more information see the [product documentation](https://docs.microsoft.com/en-us/azure/mysql/concepts-pricing-tiers). -* `family` - (Required) The `family` of hardware `Gen4` or `Gen5`, before selecting your `family` check the [product documentation](https://docs.microsoft.com/en-us/azure/mysql/concepts-pricing-tiers#compute-generations-vcores-and-memory) for availability in your region. Changing this forces a new resource to be created. +* `family` - (Required) The `family` of hardware `Gen4` or `Gen5`, before selecting your `family` check the [product documentation](https://docs.microsoft.com/en-us/azure/mysql/concepts-pricing-tiers#compute-generations-vcores-and-memory) for availability in your region. --- diff --git a/website/docs/r/postgresql_server.html.markdown b/website/docs/r/postgresql_server.html.markdown index 9fc04224de36..24315529dfb5 100644 --- a/website/docs/r/postgresql_server.html.markdown +++ b/website/docs/r/postgresql_server.html.markdown @@ -75,9 +75,9 @@ The following arguments are supported: * `capacity` - (Required) The scale up/out capacity, representing server's compute units. -* `tier` - (Required) The tier of the particular SKU. Possible values are `Basic`, `GeneralPurpose`, and `MemoryOptimized`. For more information see the [product documentation](https://docs.microsoft.com/en-us/azure/postgresql/concepts-pricing-tiers). Changing this forces a new resource to be created. +* `tier` - (Required) The tier of the particular SKU. Possible values are `Basic`, `GeneralPurpose`, and `MemoryOptimized`. For more information see the [product documentation](https://docs.microsoft.com/en-us/azure/postgresql/concepts-pricing-tiers). -* `family` - (Required) The `family` of hardware `Gen4` or `Gen5`, before selecting your `family` check the [product documentation](https://docs.microsoft.com/en-us/azure/postgresql/concepts-pricing-tiers#compute-generations-vcores-and-memory) for availability in your region. Changing this forces a new resource to be created. +* `family` - (Required) The `family` of hardware `Gen4` or `Gen5`, before selecting your `family` check the [product documentation](https://docs.microsoft.com/en-us/azure/postgresql/concepts-pricing-tiers#compute-generations-vcores-and-memory) for availability in your region. ---