Skip to content

Commit d52c3c8

Browse files
Adding in Point in time recovery for SQLServer (#7152) (#13555)
Signed-off-by: Modular Magician <[email protected]> Signed-off-by: Modular Magician <[email protected]>
1 parent 158fd69 commit d52c3c8

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

.changelog/7152.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
google_sql_database_instance: adding point_in_time_recovery_enabled for SQLServer DB versions
3+
```

google/resource_sql_database_instance.go

+16-5
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ func resourceSqlDatabaseInstance() *schema.Resource {
110110
CustomizeDiff: customdiff.All(
111111
customdiff.ForceNewIfChange("settings.0.disk_size", isDiskShrinkage),
112112
privateNetworkCustomizeDiff,
113-
pitrPostgresOnlyCustomizeDiff,
113+
pitrSupportDbCustomizeDiff,
114114
),
115115

116116
Schema: map[string]*schema.Schema{
@@ -885,15 +885,26 @@ func privateNetworkCustomizeDiff(_ context.Context, d *schema.ResourceDiff, meta
885885
return nil
886886
}
887887

888+
// helper function to see if string within list contains a particular substring
889+
func stringContainsSlice(arr []string, str string) bool {
890+
for _, i := range arr {
891+
if strings.Contains(str, i) {
892+
return true
893+
}
894+
}
895+
return false
896+
}
897+
888898
// Point in time recovery for MySQL database instances needs binary_log_enabled set to true and
889899
// not point_in_time_recovery_enabled, which is confusing to users. This checks for
890-
// point_in_time_recovery_enabled being set to a non-PostgreSQL database instance and suggests
900+
// point_in_time_recovery_enabled being set to a non-PostgreSQL and non-SQLServer database instances and suggests
891901
// binary_log_enabled.
892-
func pitrPostgresOnlyCustomizeDiff(_ context.Context, diff *schema.ResourceDiff, v interface{}) error {
902+
func pitrSupportDbCustomizeDiff(_ context.Context, diff *schema.ResourceDiff, v interface{}) error {
893903
pitr := diff.Get("settings.0.backup_configuration.0.point_in_time_recovery_enabled").(bool)
894904
dbVersion := diff.Get("database_version").(string)
895-
if pitr && (!strings.Contains(dbVersion, "POSTGRES") && !strings.Contains(dbVersion, "SQLSERVER")) {
896-
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.")
905+
dbVersionPitrValid := []string{"POSTGRES", "SQLSERVER"}
906+
if pitr && !stringContainsSlice(dbVersionPitrValid, dbVersion) {
907+
return fmt.Errorf("point_in_time_recovery_enabled is only available for the following %v. You may want to consider using binary_log_enabled instead and remove point_in_time_recovery_enabled (removing point_in_time_recovery_enabled and adding binary_log_enabled will enable pitr for MYSQL)", dbVersionPitrValid)
897908
}
898909
return nil
899910
}

0 commit comments

Comments
 (0)