Skip to content

Commit 5a049d1

Browse files
Adding support for point_in_time_recovery_enabled flag in mssql instances (#7096) (#13454)
* Added validation for "type" in cloud_sql_user_resource for preventing user from setting "password" or "host" for CLOUD_IAM_USER and CLOUD_IAM_SERVICE_ACCOUNT user types. * Removed validation and added documentation to prevent setting of host or password field for CLOUD_IAM_USER and CLOUD_IAM_SERVICE_ACCOUNT * Updated the validation function to allow the setting of flag for mssql instance, since the API supports it now. Updated documntation as well. * Updated the validation function to allow the setting of flag for mssql instance, since the API supports it now. Updated documntation as well. * Added test function for checking support for point_in_time_recovery_enabled flag in Sql Server. Signed-off-by: Modular Magician <[email protected]> Signed-off-by: Modular Magician <[email protected]>
1 parent 2954557 commit 5a049d1

File tree

4 files changed

+48
-12
lines changed

4 files changed

+48
-12
lines changed

.changelog/7096.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
sql: Updated the ability to set `point_in_time_recovery_enabled` flag for `SQLSERVER` instance, since the API supports it now.
3+
```

google/resource_sql_database_instance.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -891,8 +891,8 @@ func privateNetworkCustomizeDiff(_ context.Context, d *schema.ResourceDiff, meta
891891
func pitrPostgresOnlyCustomizeDiff(_ context.Context, diff *schema.ResourceDiff, v interface{}) error {
892892
pitr := diff.Get("settings.0.backup_configuration.0.point_in_time_recovery_enabled").(bool)
893893
dbVersion := diff.Get("database_version").(string)
894-
if pitr && !strings.Contains(dbVersion, "POSTGRES") {
895-
return fmt.Errorf("point_in_time_recovery_enabled is only available for Postgres. You may want to consider using binary_log_enabled instead.")
894+
if pitr && (!strings.Contains(dbVersion, "POSTGRES") && !strings.Contains(dbVersion, "SQLSERVER")) {
895+
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.")
896896
}
897897
return nil
898898
}

google/resource_sql_database_instance_test.go

+41-8
Original file line numberDiff line numberDiff line change
@@ -1085,22 +1085,54 @@ func TestAccSqlDatabaseInstance_PointInTimeRecoveryEnabled(t *testing.T) {
10851085
CheckDestroy: testAccSqlDatabaseInstanceDestroyProducer(t),
10861086
Steps: []resource.TestStep{
10871087
{
1088-
Config: testGoogleSqlDatabaseInstance_PointInTimeRecoveryEnabled(masterID, true),
1088+
Config: testGoogleSqlDatabaseInstance_PointInTimeRecoveryEnabled(masterID, true, "POSTGRES_9_6"),
10891089
},
10901090
{
10911091
ResourceName: "google_sql_database_instance.instance",
10921092
ImportState: true,
10931093
ImportStateVerify: true,
1094-
ImportStateVerifyIgnore: []string{"deletion_protection"},
1094+
ImportStateVerifyIgnore: []string{"deletion_protection", "root_password"},
10951095
},
10961096
{
1097-
Config: testGoogleSqlDatabaseInstance_PointInTimeRecoveryEnabled(masterID, false),
1097+
Config: testGoogleSqlDatabaseInstance_PointInTimeRecoveryEnabled(masterID, false, "POSTGRES_9_6"),
10981098
},
10991099
{
11001100
ResourceName: "google_sql_database_instance.instance",
11011101
ImportState: true,
11021102
ImportStateVerify: true,
1103-
ImportStateVerifyIgnore: []string{"deletion_protection"},
1103+
ImportStateVerifyIgnore: []string{"deletion_protection", "root_password"},
1104+
},
1105+
},
1106+
})
1107+
}
1108+
1109+
func TestAccSqlDatabaseInstance_PointInTimeRecoveryEnabledForSqlServer(t *testing.T) {
1110+
t.Parallel()
1111+
1112+
masterID := randInt(t)
1113+
1114+
vcrTest(t, resource.TestCase{
1115+
PreCheck: func() { testAccPreCheck(t) },
1116+
Providers: testAccProviders,
1117+
CheckDestroy: testAccSqlDatabaseInstanceDestroyProducer(t),
1118+
Steps: []resource.TestStep{
1119+
{
1120+
Config: testGoogleSqlDatabaseInstance_PointInTimeRecoveryEnabled(masterID, true, "SQLSERVER_2017_STANDARD"),
1121+
},
1122+
{
1123+
ResourceName: "google_sql_database_instance.instance",
1124+
ImportState: true,
1125+
ImportStateVerify: true,
1126+
ImportStateVerifyIgnore: []string{"deletion_protection", "root_password"},
1127+
},
1128+
{
1129+
Config: testGoogleSqlDatabaseInstance_PointInTimeRecoveryEnabled(masterID, false, "SQLSERVER_2017_STANDARD"),
1130+
},
1131+
{
1132+
ResourceName: "google_sql_database_instance.instance",
1133+
ImportState: true,
1134+
ImportStateVerify: true,
1135+
ImportStateVerifyIgnore: []string{"deletion_protection", "root_password"},
11041136
},
11051137
},
11061138
})
@@ -2547,23 +2579,24 @@ resource "google_sql_database_instance" "replica" {
25472579
}
25482580
`
25492581

2550-
func testGoogleSqlDatabaseInstance_PointInTimeRecoveryEnabled(masterID int, pointInTimeRecoveryEnabled bool) string {
2582+
func testGoogleSqlDatabaseInstance_PointInTimeRecoveryEnabled(masterID int, pointInTimeRecoveryEnabled bool, dbVersion string) string {
25512583
return fmt.Sprintf(`
25522584
resource "google_sql_database_instance" "instance" {
25532585
name = "tf-test-%d"
25542586
region = "us-central1"
2555-
database_version = "POSTGRES_9_6"
2587+
database_version = "%s"
25562588
deletion_protection = false
2589+
root_password = "rand-pwd-%d"
25572590
settings {
2558-
tier = "db-f1-micro"
2591+
tier = "db-custom-2-13312"
25592592
backup_configuration {
25602593
enabled = true
25612594
start_time = "00:00"
25622595
point_in_time_recovery_enabled = %t
25632596
}
25642597
}
25652598
}
2566-
`, masterID, pointInTimeRecoveryEnabled)
2599+
`, masterID, dbVersion, masterID, pointInTimeRecoveryEnabled)
25672600
}
25682601

25692602
func testGoogleSqlDatabaseInstance_BackupRetention(masterID int) string {

website/docs/r/sql_database_instance.html.markdown

+2-2
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ The `settings` block supports:
235235
instance, high availability (`REGIONAL`) or single zone (`ZONAL`).' For all instances, ensure that
236236
`settings.backup_configuration.enabled` is set to `true`.
237237
For MySQL instances, ensure that `settings.backup_configuration.binary_log_enabled` is set to `true`.
238-
For Postgres instances, ensure that `settings.backup_configuration.point_in_time_recovery_enabled`
238+
For Postgres and SQL Server instances, ensure that `settings.backup_configuration.point_in_time_recovery_enabled`
239239
is set to `true`. Defaults to `ZONAL`.
240240

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

295295
* `start_time` - (Optional) `HH:MM` format time indicating when backup
296296
configuration starts.
297-
* `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.
297+
* `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.
298298

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

0 commit comments

Comments
 (0)