From 450c99fe8c4aa31fba0fd21eb2b0c5205d9f74e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?O=C4=9Fuz=20K=C4=B1lcan?= Date: Wed, 26 Jul 2017 14:14:01 +0200 Subject: [PATCH 1/3] Fix #196 creating a database with create_mode PointInTimeRestore fails --- azurerm/resource_arm_sql_database.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/azurerm/resource_arm_sql_database.go b/azurerm/resource_arm_sql_database.go index 6959586b57ef..0c2d10ce9d9c 100644 --- a/azurerm/resource_arm_sql_database.go +++ b/azurerm/resource_arm_sql_database.go @@ -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 From 9cf37a65215e0e54345fc579dac3a8036d900791 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?O=C4=9Fuz=20K=C4=B1lcan?= Date: Fri, 28 Jul 2017 17:50:24 +0200 Subject: [PATCH 2/3] Added a test --- azurerm/resource_arm_sql_database_test.go | 67 +++++++++++++++++++++++ 1 file changed, 67 insertions(+) diff --git a/azurerm/resource_arm_sql_database_test.go b/azurerm/resource_arm_sql_database_test.go index fb306e04aa9d..f17de9fc85a5 100644 --- a/azurerm/resource_arm_sql_database_test.go +++ b/azurerm/resource_arm_sql_database_test.go @@ -2,6 +2,7 @@ package azurerm import ( "fmt" + "time" "testing" "github.com/hashicorp/terraform/helper/acctest" @@ -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 { @@ -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" +} +` \ No newline at end of file From 7cf9cded5e4840f5e63a16c4c94a1dcb13071fb9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?O=C4=9Fuz=20K=C4=B1lcan?= Date: Fri, 28 Jul 2017 18:02:04 +0200 Subject: [PATCH 3/3] Formatted the code --- azurerm/resource_arm_sql_database_test.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/azurerm/resource_arm_sql_database_test.go b/azurerm/resource_arm_sql_database_test.go index f17de9fc85a5..a485e8f55a2b 100644 --- a/azurerm/resource_arm_sql_database_test.go +++ b/azurerm/resource_arm_sql_database_test.go @@ -2,8 +2,8 @@ package azurerm import ( "fmt" - "time" "testing" + "time" "github.com/hashicorp/terraform/helper/acctest" "github.com/hashicorp/terraform/helper/resource" @@ -148,14 +148,14 @@ func TestAccAzureRMSqlDatabase_restorePointInTime(t *testing.T) { Steps: []resource.TestStep{ { Config: preConfig, - PreventPostDestroyRefresh : true, + PreventPostDestroyRefresh: true, Check: resource.ComposeTestCheckFunc( testCheckAzureRMSqlDatabaseExists("azurerm_sql_database.test"), ), }, { - PreConfig: func() {time.Sleep(timeToRestore.Sub(time.Now().Add(-1 * time.Minute)))}, - Config: postCongif, + 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"), @@ -398,4 +398,4 @@ resource "azurerm_sql_database" "test_restore" { source_database_id = "${azurerm_sql_database.test.id}" restore_point_in_time = "%s" } -` \ No newline at end of file +`