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

resource/azurerm_sql_database: Fix requested_service_objective_name updates #1503

Merged
merged 1 commit into from
Jul 6, 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
5 changes: 5 additions & 0 deletions azurerm/resource_arm_sql_database.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,11 @@ func resourceArmSqlDatabaseCreateUpdate(d *schema.ResourceData, meta interface{}
}
}

// The requested Service Objective Name does not match the requested Service Objective Id.
if d.HasChange("requested_service_objective_name") && !d.HasChange("requested_service_objective_id") {
properties.DatabaseProperties.RequestedServiceObjectiveID = nil
}

ctx := meta.(*ArmClient).StopContext
future, err := client.CreateOrUpdate(ctx, resourceGroup, serverName, name, properties)
if err != nil {
Expand Down
59 changes: 59 additions & 0 deletions azurerm/resource_arm_sql_database_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,36 @@ func TestAccAzureRMSqlDatabase_collation(t *testing.T) {
})
}

func TestAccAzureRMSqlDatabase_requestedServiceObjectiveName(t *testing.T) {
resourceName := "azurerm_sql_database.test"
ri := acctest.RandInt()
location := testLocation()
preConfig := testAccAzureRMSqlDatabase_requestedServiceObjectiveName(ri, location, "S0")
postConfig := testAccAzureRMSqlDatabase_requestedServiceObjectiveName(ri, location, "S1")

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMSqlDatabaseDestroy,
Steps: []resource.TestStep{
{
Config: preConfig,
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMSqlDatabaseExists(resourceName),
resource.TestCheckResourceAttr(resourceName, "requested_service_objective_name", "S0"),
),
},
{
Config: postConfig,
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMSqlDatabaseExists(resourceName),
resource.TestCheckResourceAttr(resourceName, "requested_service_objective_name", "S1"),
),
},
},
})
}

func testCheckAzureRMSqlDatabaseExists(name string) resource.TestCheckFunc {
return func(s *terraform.State) error {

Expand Down Expand Up @@ -585,3 +615,32 @@ func testAccAzureRMSqlDatabase_bacpac(rInt int, location string) string {
}
`, rInt, location, rInt, rInt, rInt)
}

func testAccAzureRMSqlDatabase_requestedServiceObjectiveName(rInt int, location, requestedServiceObjectiveName string) string {
return fmt.Sprintf(`
resource "azurerm_resource_group" "test" {
name = "acctestRG-%d"
location = "%s"
}

resource "azurerm_sql_server" "test" {
name = "acctestsqlserver%d"
resource_group_name = "${azurerm_resource_group.test.name}"
location = "${azurerm_resource_group.test.location}"
version = "12.0"
administrator_login = "mradministrator"
administrator_login_password = "thisIsDog11"
}

resource "azurerm_sql_database" "test" {
name = "acctestdb%d"
resource_group_name = "${azurerm_resource_group.test.name}"
server_name = "${azurerm_sql_server.test.name}"
location = "${azurerm_resource_group.test.location}"
edition = "Standard"
collation = "SQL_Latin1_General_CP1_CI_AS"
max_size_bytes = "1073741824"
requested_service_objective_name = %q
}
`, rInt, location, rInt, rInt, requestedServiceObjectiveName)
}