Skip to content

Commit

Permalink
Fix for azurerm_mysql_database resource wants to re-create on every a…
Browse files Browse the repository at this point in the history
…pply (#1281)

* Fix for azurerm_mysql_database resource wants to re-create on apply

* Added test cases for charset casing issue
  • Loading branch information
WodansSon authored and tombuildsstuff committed May 24, 2018
1 parent 3e835ee commit 90d7ed5
Show file tree
Hide file tree
Showing 2 changed files with 128 additions and 3 deletions.
7 changes: 4 additions & 3 deletions azurerm/resource_arm_mysql_database.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,10 @@ func resourceArmMySqlDatabase() *schema.Resource {
},

"charset": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
Type: schema.TypeString,
Required: true,
DiffSuppressFunc: ignoreCaseDiffSuppressFunc,
ForceNew: true,
},

"collation": {
Expand Down
124 changes: 124 additions & 0 deletions azurerm/resource_arm_mysql_database_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,48 @@ func TestAccAzureRMMySQLDatabase_basic(t *testing.T) {
})
}

func TestAccAzureRMMySQLDatabase_charsetUppercase(t *testing.T) {
resourceName := "azurerm_mysql_database.test"
ri := acctest.RandInt()
config := testAccAzureRMMySQLDatabase_charsetUppercase(ri, testLocation())

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMMySQLDatabaseDestroy,
Steps: []resource.TestStep{
{
Config: config,
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMMySQLDatabaseExists(resourceName),
resource.TestCheckResourceAttr(resourceName, "charset", "utf8"),
),
},
},
})
}

func TestAccAzureRMMySQLDatabase_charsetMixedcase(t *testing.T) {
resourceName := "azurerm_mysql_database.test"
ri := acctest.RandInt()
config := testAccAzureRMMySQLDatabase_charsetMixedcase(ri, testLocation())

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMMySQLDatabaseDestroy,
Steps: []resource.TestStep{
{
Config: config,
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMMySQLDatabaseExists(resourceName),
resource.TestCheckResourceAttr(resourceName, "charset", "utf8"),
),
},
},
})
}

func testCheckAzureRMMySQLDatabaseExists(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 @@ -126,3 +168,85 @@ resource "azurerm_mysql_database" "test" {
}
`, rInt, location, rInt, rInt)
}

func testAccAzureRMMySQLDatabase_charsetUppercase(rInt int, location string) string {
return fmt.Sprintf(`
resource "azurerm_resource_group" "test" {
name = "acctestRG-%d"
location = "%s"
}
resource "azurerm_mysql_server" "test" {
name = "acctestpsqlsvr-%d"
location = "${azurerm_resource_group.test.location}"
resource_group_name = "${azurerm_resource_group.test.name}"
sku {
name = "B_Gen4_2"
capacity = 2
tier = "Basic"
family = "Gen4"
}
storage_profile {
storage_mb = 51200
backup_retention_days = 7
geo_redundant_backup = "Disabled"
}
administrator_login = "acctestun"
administrator_login_password = "H@Sh1CoR3!"
version = "5.6"
ssl_enforcement = "Enabled"
}
resource "azurerm_mysql_database" "test" {
name = "acctestdb_%d"
resource_group_name = "${azurerm_resource_group.test.name}"
server_name = "${azurerm_mysql_server.test.name}"
charset = "UTF8"
collation = "utf8_unicode_ci"
}
`, rInt, location, rInt, rInt)
}

func testAccAzureRMMySQLDatabase_charsetMixedcase(rInt int, location string) string {
return fmt.Sprintf(`
resource "azurerm_resource_group" "test" {
name = "acctestRG-%d"
location = "%s"
}
resource "azurerm_mysql_server" "test" {
name = "acctestpsqlsvr-%d"
location = "${azurerm_resource_group.test.location}"
resource_group_name = "${azurerm_resource_group.test.name}"
sku {
name = "B_Gen4_2"
capacity = 2
tier = "Basic"
family = "Gen4"
}
storage_profile {
storage_mb = 51200
backup_retention_days = 7
geo_redundant_backup = "Disabled"
}
administrator_login = "acctestun"
administrator_login_password = "H@Sh1CoR3!"
version = "5.6"
ssl_enforcement = "Enabled"
}
resource "azurerm_mysql_database" "test" {
name = "acctestdb_%d"
resource_group_name = "${azurerm_resource_group.test.name}"
server_name = "${azurerm_mysql_server.test.name}"
charset = "Utf8"
collation = "utf8_unicode_ci"
}
`, rInt, location, rInt, rInt)
}

0 comments on commit 90d7ed5

Please sign in to comment.