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

support binary_logging for replica instances #9428

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/4907.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
sql: add support for `binary_logging` on replica instances for `googe_sql_database_instance`
```
26 changes: 26 additions & 0 deletions google/resource_sql_database_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -839,6 +839,17 @@ func resourceSqlDatabaseInstanceCreate(d *schema.ResourceData, meta interface{})
defer mutexKV.Unlock(instanceMutexKey(project, instance.MasterInstanceName))
}

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}}
}
}

var op *sqladmin.Operation
err = retryTimeDuration(func() (operr error) {
if cloneContext != nil {
Expand Down Expand Up @@ -866,6 +877,21 @@ func resourceSqlDatabaseInstanceCreate(d *schema.ResourceData, meta interface{})
return err
}

// patch any fields that need to be sent postcreation
if patchData != nil {
err = retryTimeDuration(func() (rerr error) {
op, rerr = config.NewSqlAdminClient(userAgent).Instances.Patch(project, instance.Name, patchData).Do()
return rerr
}, d.Timeout(schema.TimeoutUpdate), isSqlOperationInProgressError)
if err != nil {
return fmt.Errorf("Error, failed to update instance settings for %s: %s", instance.Name, err)
}
err = sqlAdminOperationWaitTime(config, op, project, "Patch Instance", userAgent, d.Timeout(schema.TimeoutUpdate))
if err != nil {
return err
}
}

err = resourceSqlDatabaseInstanceRead(d, meta)
if err != nil {
return err
Expand Down
9 changes: 6 additions & 3 deletions google/resource_sql_database_instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1076,7 +1076,7 @@ resource "google_sql_database_instance" "instance" {
var testGoogleSqlDatabaseInstance_replica = `
resource "google_sql_database_instance" "instance_master" {
name = "tf-lw-%d"
database_version = "MYSQL_5_6"
database_version = "MYSQL_5_7"
region = "us-central1"
deletion_protection = false

Expand All @@ -1093,12 +1093,15 @@ resource "google_sql_database_instance" "instance_master" {

resource "google_sql_database_instance" "replica1" {
name = "tf-lw-%d-1"
database_version = "MYSQL_5_6"
database_version = "MYSQL_5_7"
region = "us-central1"
deletion_protection = false

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

master_instance_name = google_sql_database_instance.instance_master.name
Expand All @@ -1115,7 +1118,7 @@ resource "google_sql_database_instance" "replica1" {

resource "google_sql_database_instance" "replica2" {
name = "tf-lw-%d-2"
database_version = "MYSQL_5_6"
database_version = "MYSQL_5_7"
region = "us-central1"
deletion_protection = false

Expand Down