From 98aaa708bff483d99ad8f273fcab3746ebcf109b Mon Sep 17 00:00:00 2001 From: Jeffrey Cline Date: Tue, 17 Jul 2018 17:31:36 -0700 Subject: [PATCH] Fixes for #1597 --- azurerm/resource_arm_mysql_server.go | 2 - azurerm/resource_arm_mysql_server_test.go | 79 +++++++++++++++++- azurerm/resource_arm_postgresql_server.go | 2 - .../resource_arm_postgresql_server_test.go | 81 ++++++++++++++++++- website/docs/r/mysql_server.html.markdown | 4 +- .../docs/r/postgresql_server.html.markdown | 4 +- 6 files changed, 158 insertions(+), 14 deletions(-) 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..d54c972a5650 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 { @@ -295,10 +335,10 @@ 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 { @@ -322,6 +362,39 @@ resource "azurerm_resource_group" "test" { 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 = "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}" 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..7975bf9a1c85 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 @@ -475,10 +517,10 @@ 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 { @@ -502,6 +544,39 @@ resource "azurerm_resource_group" "test" { 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 = "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}" 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. ---