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

google_sql_database_instance - support for secondary_zone #11996

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/6178.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
sql: added `settings.location_preference.secondary_zone` field in `google_sql_database_instance`
```
7 changes: 7 additions & 0 deletions google/resource_sql_database_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,11 @@ is set to true.`,
AtLeastOneOf: []string{"settings.0.location_preference.0.follow_gae_application", "settings.0.location_preference.0.zone"},
Description: `The preferred compute engine zone.`,
},
"secondary_zone": {
Type: schema.TypeString,
Optional: true,
Description: `The preferred Compute Engine zone for the secondary/failover`,
},
},
},
},
Expand Down Expand Up @@ -1052,6 +1057,7 @@ func expandLocationPreference(configured []interface{}) *sqladmin.LocationPrefer
return &sqladmin.LocationPreference{
FollowGaeApplication: _locationPreference["follow_gae_application"].(string),
Zone: _locationPreference["zone"].(string),
SecondaryZone: _locationPreference["secondary_zone"].(string),
}
}

Expand Down Expand Up @@ -1535,6 +1541,7 @@ func flattenLocationPreference(locationPreference *sqladmin.LocationPreference)
data := map[string]interface{}{
"follow_gae_application": locationPreference.FollowGaeApplication,
"zone": locationPreference.Zone,
"secondary_zone": locationPreference.SecondaryZone,
}

return []map[string]interface{}{data}
Expand Down
57 changes: 57 additions & 0 deletions google/resource_sql_database_instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,30 @@ func TestAccSqlDatabaseInstance_settings_basic(t *testing.T) {
})
}

func TestAccSqlDatabaseInstance_settings_secondary(t *testing.T) {
t.Parallel()

databaseName := "tf-test-" + randString(t, 10)

vcrTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccSqlDatabaseInstanceDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: fmt.Sprintf(
testGoogleSqlDatabaseInstance_settings_secondary, databaseName),
},
{
ResourceName: "google_sql_database_instance.instance",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"deletion_protection"},
},
},
})
}

func TestAccSqlDatabaseInstance_settings_deletionProtection(t *testing.T) {
t.Parallel()

Expand Down Expand Up @@ -1505,6 +1529,39 @@ resource "google_sql_database_instance" "instance" {
}
}
`

var testGoogleSqlDatabaseInstance_settings_secondary = `
resource "google_sql_database_instance" "instance" {
name = "%s"
region = "us-central1"
database_version = "MYSQL_5_7"
deletion_protection = false
settings {
tier = "db-f1-micro"
location_preference {
zone = "us-central1-f"
secondary_zone = "us-central1-a"
}

ip_configuration {
ipv4_enabled = "true"
authorized_networks {
value = "108.12.12.12"
name = "misc"
expiration_time = "2037-11-15T16:19:00.094Z"
}
}

backup_configuration {
enabled = "true"
start_time = "19:19"
}

activation_policy = "ALWAYS"
}
}
`

var testGoogleSqlDatabaseInstance_settings_deletionProtection = `
resource "google_sql_database_instance" "instance" {
name = "%s"
Expand Down
2 changes: 2 additions & 0 deletions website/docs/r/sql_database_instance.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,8 @@ The optional `settings.location_preference` subblock supports:
* `zone` - (Optional) The preferred compute engine
[zone](https://cloud.google.com/compute/docs/zones?hl=en).

* `secondary_zone` - (Optional) The preferred Compute Engine zone for the secondary/failover.

The optional `settings.maintenance_window` subblock for instances declares a one-hour
[maintenance window](https://cloud.google.com/sql/docs/instance-settings?hl=en#maintenance-window-2ndgen)
when an Instance can automatically restart to apply updates. The maintenance window is specified in UTC time. It supports:
Expand Down