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 in Point in time recovery for SQLServer #13555

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/7152.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
google_sql_database_instance: adding point_in_time_recovery_enabled for SQLServer DB versions
```
21 changes: 16 additions & 5 deletions google/resource_sql_database_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func resourceSqlDatabaseInstance() *schema.Resource {
CustomizeDiff: customdiff.All(
customdiff.ForceNewIfChange("settings.0.disk_size", isDiskShrinkage),
privateNetworkCustomizeDiff,
pitrPostgresOnlyCustomizeDiff,
pitrSupportDbCustomizeDiff,
),

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

// helper function to see if string within list contains a particular substring
func stringContainsSlice(arr []string, str string) bool {
for _, i := range arr {
if strings.Contains(str, i) {
return true
}
}
return false
}

// Point in time recovery for MySQL database instances needs binary_log_enabled set to true and
// not point_in_time_recovery_enabled, which is confusing to users. This checks for
// point_in_time_recovery_enabled being set to a non-PostgreSQL database instance and suggests
// point_in_time_recovery_enabled being set to a non-PostgreSQL and non-SQLServer database instances and suggests
// binary_log_enabled.
func pitrPostgresOnlyCustomizeDiff(_ context.Context, diff *schema.ResourceDiff, v interface{}) error {
func pitrSupportDbCustomizeDiff(_ 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") && !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.")
dbVersionPitrValid := []string{"POSTGRES", "SQLSERVER"}
if pitr && !stringContainsSlice(dbVersionPitrValid, dbVersion) {
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)
}
return nil
}
Expand Down