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 #4907

Merged
merged 4 commits into from
Jun 24, 2021
Merged
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
Expand Up @@ -857,6 +857,19 @@ func resourceSqlDatabaseInstanceCreate(d *schema.ResourceData, meta interface{})
}
<% end -%>

patchCalls := []func(opts ...googleapi.CallOption) (*sqladmin.Operation, error){}
ScottSuarez marked this conversation as resolved.
Show resolved Hide resolved

// 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 {
bcPatchData := &sqladmin.DatabaseInstance{Settings: &sqladmin.Settings{BackupConfiguration: bc}}
bcPatch := config.NewSqlAdminClient(userAgent).Instances.Patch(project, instance.Name, bcPatchData).Do
patchCalls = append(patchCalls, bcPatch)
}
}

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

// patch any fields that need to be sent postcreation
for _, call := range patchCalls {
err = retryTimeDuration(func() (rerr error) {
op, rerr = call()
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
Original file line number Diff line number Diff line change
Expand Up @@ -1142,7 +1142,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 @@ -1159,12 +1159,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 @@ -1181,7 +1184,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