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

Adding support for point_in_time_recovery_enabled flag in mssql instances #5079

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
3 changes: 3 additions & 0 deletions .changelog/7096.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
sql: Updated the ability to set `point_in_time_recovery_enabled` flag for `SQLSERVER` instance, since the API supports it now.
```
4 changes: 2 additions & 2 deletions google-beta/resource_sql_database_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -891,8 +891,8 @@ func privateNetworkCustomizeDiff(_ context.Context, d *schema.ResourceDiff, meta
func pitrPostgresOnlyCustomizeDiff(_ context.Context, diff *schema.ResourceDiff, v interface{}) error {
pitr := diff.Get("settings.0.backup_configuration.0.point_in_time_recovery_enabled").(bool)
dbVersion := diff.Get("database_version").(string)
if pitr && !strings.Contains(dbVersion, "POSTGRES") {
return fmt.Errorf("point_in_time_recovery_enabled is only available for Postgres. You may want to consider using binary_log_enabled instead.")
if pitr && (!strings.Contains(dbVersion, "POSTGRES") && !strings.Contains(dbVersion, "SQLSERVER")) {
return fmt.Errorf("point_in_time_recovery_enabled is only available for Postgres and SQL Server. You may want to consider using binary_log_enabled instead.")
}
return nil
}
Expand Down
49 changes: 41 additions & 8 deletions google-beta/resource_sql_database_instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1085,22 +1085,54 @@ func TestAccSqlDatabaseInstance_PointInTimeRecoveryEnabled(t *testing.T) {
CheckDestroy: testAccSqlDatabaseInstanceDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testGoogleSqlDatabaseInstance_PointInTimeRecoveryEnabled(masterID, true),
Config: testGoogleSqlDatabaseInstance_PointInTimeRecoveryEnabled(masterID, true, "POSTGRES_9_6"),
},
{
ResourceName: "google_sql_database_instance.instance",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"deletion_protection"},
ImportStateVerifyIgnore: []string{"deletion_protection", "root_password"},
},
{
Config: testGoogleSqlDatabaseInstance_PointInTimeRecoveryEnabled(masterID, false),
Config: testGoogleSqlDatabaseInstance_PointInTimeRecoveryEnabled(masterID, false, "POSTGRES_9_6"),
},
{
ResourceName: "google_sql_database_instance.instance",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"deletion_protection"},
ImportStateVerifyIgnore: []string{"deletion_protection", "root_password"},
},
},
})
}

func TestAccSqlDatabaseInstance_PointInTimeRecoveryEnabledForSqlServer(t *testing.T) {
t.Parallel()

masterID := randInt(t)

vcrTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccSqlDatabaseInstanceDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testGoogleSqlDatabaseInstance_PointInTimeRecoveryEnabled(masterID, true, "SQLSERVER_2017_STANDARD"),
},
{
ResourceName: "google_sql_database_instance.instance",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"deletion_protection", "root_password"},
},
{
Config: testGoogleSqlDatabaseInstance_PointInTimeRecoveryEnabled(masterID, false, "SQLSERVER_2017_STANDARD"),
},
{
ResourceName: "google_sql_database_instance.instance",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"deletion_protection", "root_password"},
},
},
})
Expand Down Expand Up @@ -2547,23 +2579,24 @@ resource "google_sql_database_instance" "replica" {
}
`

func testGoogleSqlDatabaseInstance_PointInTimeRecoveryEnabled(masterID int, pointInTimeRecoveryEnabled bool) string {
func testGoogleSqlDatabaseInstance_PointInTimeRecoveryEnabled(masterID int, pointInTimeRecoveryEnabled bool, dbVersion string) string {
return fmt.Sprintf(`
resource "google_sql_database_instance" "instance" {
name = "tf-test-%d"
region = "us-central1"
database_version = "POSTGRES_9_6"
database_version = "%s"
deletion_protection = false
root_password = "rand-pwd-%d"
settings {
tier = "db-f1-micro"
tier = "db-custom-2-13312"
backup_configuration {
enabled = true
start_time = "00:00"
point_in_time_recovery_enabled = %t
}
}
}
`, masterID, pointInTimeRecoveryEnabled)
`, masterID, dbVersion, masterID, pointInTimeRecoveryEnabled)
}

func testGoogleSqlDatabaseInstance_BackupRetention(masterID int) string {
Expand Down
4 changes: 2 additions & 2 deletions website/docs/r/sql_database_instance.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ The `settings` block supports:
instance, high availability (`REGIONAL`) or single zone (`ZONAL`).' For all instances, ensure that
`settings.backup_configuration.enabled` is set to `true`.
For MySQL instances, ensure that `settings.backup_configuration.binary_log_enabled` is set to `true`.
For Postgres instances, ensure that `settings.backup_configuration.point_in_time_recovery_enabled`
For Postgres and SQL Server instances, ensure that `settings.backup_configuration.point_in_time_recovery_enabled`
is set to `true`. Defaults to `ZONAL`.

* `collation` - (Optional) The name of server instance collation.
Expand Down Expand Up @@ -294,7 +294,7 @@ The optional `settings.backup_configuration` subblock supports:

* `start_time` - (Optional) `HH:MM` format time indicating when backup
configuration starts.
* `point_in_time_recovery_enabled` - (Optional) True if Point-in-time recovery is enabled. Will restart database if enabled after instance creation. Valid only for PostgreSQL instances.
* `point_in_time_recovery_enabled` - (Optional) True if Point-in-time recovery is enabled. Will restart database if enabled after instance creation. Valid only for PostgreSQL and SQL Server instances.

* `location` - (Optional) The region where the backup will be stored

Expand Down