Skip to content

Commit

Permalink
Merge pull request #197 from ouzklcn/resource_arm_sql_database
Browse files Browse the repository at this point in the history
Fix #196 creating a database with create_mode PointInTimeRestore fails
  • Loading branch information
tombuildsstuff authored Jul 31, 2017
2 parents 7ca6701 + 7cf9cde commit 6669b4b
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 0 deletions.
4 changes: 4 additions & 0 deletions azurerm/resource_arm_sql_database.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,10 @@ func resourceArmSqlDatabaseCreate(d *schema.ResourceData, meta interface{}) erro
command.RequestedServiceObjectiveName = azure.String(v.(string))
}

if v, ok := d.GetOk("restore_point_in_time"); ok {
command.RestorePointInTime = azure.String(v.(string))
}

createRequest := rivieraClient.NewRequest()
createRequest.Command = command

Expand Down
67 changes: 67 additions & 0 deletions azurerm/resource_arm_sql_database_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package azurerm
import (
"fmt"
"testing"
"time"

"github.com/hashicorp/terraform/helper/acctest"
"github.com/hashicorp/terraform/helper/resource"
Expand Down Expand Up @@ -134,6 +135,36 @@ func TestAccAzureRMSqlDatabase_datawarehouse(t *testing.T) {
})
}

func TestAccAzureRMSqlDatabase_restorePointInTime(t *testing.T) {
ri := acctest.RandInt()
preConfig := fmt.Sprintf(testAccAzureRMSqlDatabase_basic, ri, ri, ri)
timeToRestore := time.Now().Add(15 * time.Minute)
postCongif := fmt.Sprintf(testAccAzureRMSqlDatabase_restorePointInTime, ri, ri, ri, ri, string(timeToRestore.UTC().Format(time.RFC3339)))

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMSqlDatabaseDestroy,
Steps: []resource.TestStep{
{
Config: preConfig,
PreventPostDestroyRefresh: true,
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMSqlDatabaseExists("azurerm_sql_database.test"),
),
},
{
PreConfig: func() { time.Sleep(timeToRestore.Sub(time.Now().Add(-1 * time.Minute))) },
Config: postCongif,
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMSqlDatabaseExists("azurerm_sql_database.test"),
testCheckAzureRMSqlDatabaseExists("azurerm_sql_database.test_restore"),
),
},
},
})
}

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

Expand Down Expand Up @@ -332,3 +363,39 @@ resource "azurerm_sql_database" "test" {
requested_service_objective_name = "DW400"
}
`

var testAccAzureRMSqlDatabase_restorePointInTime = `
resource "azurerm_resource_group" "test" {
name = "acctestRG_%d"
location = "West US"
}
resource "azurerm_sql_server" "test" {
name = "acctestsqlserver%d"
resource_group_name = "${azurerm_resource_group.test.name}"
location = "West US"
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 = "West US"
edition = "Standard"
collation = "SQL_Latin1_General_CP1_CI_AS"
max_size_bytes = "1073741824"
requested_service_objective_name = "S0"
}
resource "azurerm_sql_database" "test_restore" {
name = "acctestdb_restore%d"
resource_group_name = "${azurerm_resource_group.test.name}"
server_name = "${azurerm_sql_server.test.name}"
location = "West US"
create_mode = "PointInTimeRestore"
source_database_id = "${azurerm_sql_database.test.id}"
restore_point_in_time = "%s"
}
`

0 comments on commit 6669b4b

Please sign in to comment.