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

Fix to allow MySQL and PostgreSQL to upgrade SKU without destroying existing resource #1598

Merged
merged 2 commits into from
Jul 18, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions azurerm/resource_arm_mysql_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -92,7 +91,6 @@ func resourceArmMySqlServer() *schema.Resource {
"family": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: validation.StringInSlice([]string{
"Gen4",
"Gen5",
Expand Down
99 changes: 86 additions & 13 deletions azurerm/resource_arm_mysql_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) },
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand All @@ -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"
Expand Down Expand Up @@ -335,9 +375,42 @@ resource "azurerm_mysql_server" "test" {
}

storage_profile {
Copy link
Collaborator

Choose a reason for hiding this comment

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

It would be nice if these were aligned

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"
Expand Down
2 changes: 0 additions & 2 deletions azurerm/resource_arm_postgresql_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -93,7 +92,6 @@ func resourceArmPostgreSQLServer() *schema.Resource {
"family": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: validation.StringInSlice([]string{
"Gen4",
"Gen5",
Expand Down
113 changes: 94 additions & 19 deletions azurerm/resource_arm_postgresql_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) },
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand All @@ -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"
Expand Down Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions website/docs/r/mysql_server.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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.

---

Expand Down
Loading