Skip to content

Commit

Permalink
Fix sql_database_instance to include backup_configuration in create r…
Browse files Browse the repository at this point in the history
  • Loading branch information
roaks3 authored and googlerjk committed Nov 25, 2022
1 parent 27a34f4 commit b72d44c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -932,12 +932,12 @@ func resourceSqlDatabaseInstanceCreate(d *schema.ResourceData, meta interface{})
var patchData *sqladmin.DatabaseInstance

// BinaryLogging can be enabled on replica instances but only after creation.
if instance.MasterInstanceName != "" && instance.Settings != nil && instance.Settings.BackupConfiguration != nil {
bc := instance.Settings.BackupConfiguration
instance.Settings.BackupConfiguration = nil
if bc.BinaryLogEnabled {
patchData = &sqladmin.DatabaseInstance{Settings: &sqladmin.Settings{BackupConfiguration: bc}}
}
if instance.MasterInstanceName != "" && instance.Settings != nil && instance.Settings.BackupConfiguration != nil && instance.Settings.BackupConfiguration.BinaryLogEnabled {
settingsCopy := expandSqlDatabaseInstanceSettings(s.([]interface{}))
bc := settingsCopy.BackupConfiguration
patchData = &sqladmin.DatabaseInstance{Settings: &sqladmin.Settings{BackupConfiguration: bc}}

instance.Settings.BackupConfiguration.BinaryLogEnabled = false
}

var op *sqladmin.Operation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,12 @@ func TestAccSqlDatabaseInstance_replica(t *testing.T) {
Steps: []resource.TestStep{
resource.TestStep{
Config: fmt.Sprintf(
testGoogleSqlDatabaseInstance_replica, databaseID, databaseID, databaseID),
testGoogleSqlDatabaseInstance_replica, databaseID, databaseID, databaseID, "true"),
ExpectError: regexp.MustCompile("Error, failed to create instance tf-lw-\\d+-2: googleapi: Error 400: Invalid request: Invalid flag for instance role: Backups cannot be enabled for read replica instance.., invalid"),
},
resource.TestStep{
Config: fmt.Sprintf(
testGoogleSqlDatabaseInstance_replica, databaseID, databaseID, databaseID, "false"),
},
resource.TestStep{
ResourceName: "google_sql_database_instance.instance_master",
Expand Down Expand Up @@ -1989,9 +1994,10 @@ resource "google_sql_database_instance" "replica1" {

settings {
tier = "db-n1-standard-1"
backup_configuration {
backup_configuration {
enabled = false
binary_log_enabled = true
}
}
}

master_instance_name = google_sql_database_instance.instance_master.name
Expand All @@ -2014,6 +2020,9 @@ resource "google_sql_database_instance" "replica2" {

settings {
tier = "db-n1-standard-1"
backup_configuration {
enabled = %s
}
}

master_instance_name = google_sql_database_instance.instance_master.name
Expand Down

0 comments on commit b72d44c

Please sign in to comment.