Skip to content

Commit 8207edf

Browse files
sql: add switch_transaction_logs_to_cloud_storage_enabled to google_sql_database_instance (#18173) (#12686)
[upstream:cc9d0faa24b9ed6a9679dddaa95a17bbdbb9e2f0] Signed-off-by: Modular Magician <magic-modules@google.com>
1 parent f27f60a commit 8207edf

5 files changed

Lines changed: 88 additions & 0 deletions

File tree

.changelog/18173.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
sql: added `switch_transaction_logs_to_cloud_storage_enabled` field to `google_sql_database_instance`
3+
```

google-beta/services/sql/resource_sql_database_instance.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1189,6 +1189,11 @@ API (for read pools, effective_availability_type may differ from availability_ty
11891189
Description: `The MySQL, PostgreSQL or SQL Server version to use. Supported values include MYSQL_5_6, MYSQL_5_7, MYSQL_8_0, MYSQL_8_4, POSTGRES_9_6, POSTGRES_10, POSTGRES_11, POSTGRES_12, POSTGRES_13, POSTGRES_14, POSTGRES_15, POSTGRES_16, POSTGRES_17, POSTGRES_18, SQLSERVER_2022_STANDARD, SQLSERVER_2022_ENTERPRISE, SQLSERVER_2022_EXPRESS, SQLSERVER_2022_WEB, SQLSERVER_2025_STANDARD, SQLSERVER_2025_ENTERPRISE, SQLSERVER_2025_EXPRESS, SQLSERVER_2025_WEB. Database Version Policies includes an up-to-date reference of supported versions.`,
11901190
DiffSuppressFunc: databaseVersionDiffSuppress,
11911191
},
1192+
"switch_transaction_logs_to_cloud_storage_enabled": {
1193+
Type: schema.TypeBool,
1194+
Optional: true,
1195+
Description: `When set to true, Cloud SQL instances can switch storing point-in-time recovery transaction logs from a data disk to Cloud Storage, freeing up data disk space and enabling longer retention windows. This is an input-only field that is not persisted in the API.`,
1196+
},
11921197
"encryption_key_name": {
11931198
Type: schema.TypeString,
11941199
Optional: true,
@@ -1799,6 +1804,9 @@ func resourceSqlDatabaseInstanceCreate(d *schema.ResourceData, meta interface{})
17991804
if _, ok := d.GetOk("node_count"); ok {
18001805
instance.NodeCount = int64(d.Get("node_count").(int))
18011806
}
1807+
if v, ok := d.GetOk("switch_transaction_logs_to_cloud_storage_enabled"); ok {
1808+
instance.SwitchTransactionLogsToCloudStorageEnabled = v.(bool)
1809+
}
18021810
if _, ok := d.GetOk("root_password_wo_version"); ok {
18031811
instance.RootPassword = tpgresource.GetRawConfigAttributeAsString(d, "root_password_wo")
18041812
} else if _, ok := d.GetOk("root_password"); ok {
@@ -3019,6 +3027,11 @@ func resourceSqlDatabaseInstanceUpdate(d *schema.ResourceData, meta interface{})
30193027
}
30203028
}
30213029

3030+
// switch_transaction_logs_to_cloud_storage_enabled is input-only; send it only when toggled.
3031+
if d.HasChange("switch_transaction_logs_to_cloud_storage_enabled") {
3032+
instance.SwitchTransactionLogsToCloudStorageEnabled = d.Get("switch_transaction_logs_to_cloud_storage_enabled").(bool)
3033+
}
3034+
30223035
err = transport_tpg.Retry(transport_tpg.RetryOptions{
30233036
RetryFunc: func() (rerr error) {
30243037
op, rerr = NewClient(config, userAgent).Instances.Update(project, d.Get("name").(string), instance).Do()

google-beta/services/sql/resource_sql_database_instance_meta.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ fields:
9696
- api_field: 'serverCaCert.expirationTime'
9797
- api_field: 'serverCaCert.sha1Fingerprint'
9898
- api_field: 'serviceAccountEmailAddress'
99+
- api_field: 'switchTransactionLogsToCloudStorageEnabled'
99100
- api_field: 'settings.activationPolicy'
100101
- api_field: 'settings.activeDirectoryConfig.adminCredentialSecretName'
101102
- api_field: 'settings.activeDirectoryConfig.dnsServers'

google-beta/services/sql/resource_sql_database_instance_test.go

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2606,6 +2606,75 @@ func TestAccSqlDatabaseInstance_AutoUpgradeEnabled(t *testing.T) {
26062606
})
26072607
}
26082608

2609+
func TestAccSqlDatabaseInstance_switchTransactionLogsToCloudStorage(t *testing.T) {
2610+
t.Parallel()
2611+
2612+
databaseName := "tf-test-" + acctest.RandString(t, 10)
2613+
testId := "sql-instance-txlog-switch-1"
2614+
addressName := tpgcompute.BootstrapSharedTestGlobalAddress(t, testId)
2615+
networkName := servicenetworking.BootstrapSharedServiceNetworkingConnection(t, testId)
2616+
2617+
acctest.VcrTest(t, resource.TestCase{
2618+
PreCheck: func() { acctest.AccTestPreCheck(t) },
2619+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
2620+
CheckDestroy: testAccSqlDatabaseInstanceDestroyProducer(t),
2621+
Steps: []resource.TestStep{
2622+
{
2623+
Config: testGoogleSqlDatabaseInstance_switchTransactionLogsToCloudStorage(databaseName, networkName, addressName, false),
2624+
},
2625+
{
2626+
ResourceName: "google_sql_database_instance.instance",
2627+
ImportState: true,
2628+
ImportStateVerify: true,
2629+
ImportStateVerifyIgnore: []string{"deletion_protection", "root_password", "switch_transaction_logs_to_cloud_storage_enabled", "settings.0.version"},
2630+
},
2631+
{
2632+
// Flip the flag on an existing instance: PITR transaction logs move to Cloud Storage.
2633+
Config: testGoogleSqlDatabaseInstance_switchTransactionLogsToCloudStorage(databaseName, networkName, addressName, true),
2634+
},
2635+
{
2636+
ResourceName: "google_sql_database_instance.instance",
2637+
ImportState: true,
2638+
ImportStateVerify: true,
2639+
ImportStateVerifyIgnore: []string{"deletion_protection", "root_password", "switch_transaction_logs_to_cloud_storage_enabled", "settings.0.version"},
2640+
},
2641+
},
2642+
})
2643+
}
2644+
2645+
func testGoogleSqlDatabaseInstance_switchTransactionLogsToCloudStorage(databaseName, networkName, addressRangeName string, switchEnabled bool) string {
2646+
return fmt.Sprintf(`
2647+
data "google_compute_network" "servicenet" {
2648+
name = "%s"
2649+
}
2650+
2651+
resource "google_sql_database_instance" "instance" {
2652+
name = "%s"
2653+
region = "us-central1"
2654+
database_version = "MYSQL_8_0"
2655+
deletion_protection = false
2656+
root_password = "rand-pwd-%s"
2657+
2658+
switch_transaction_logs_to_cloud_storage_enabled = %t
2659+
2660+
settings {
2661+
tier = "db-g1-small"
2662+
availability_type = "ZONAL"
2663+
ip_configuration {
2664+
ipv4_enabled = "false"
2665+
private_network = data.google_compute_network.servicenet.self_link
2666+
allocated_ip_range = "%s"
2667+
}
2668+
backup_configuration {
2669+
enabled = true
2670+
start_time = "00:00"
2671+
binary_log_enabled = true
2672+
}
2673+
}
2674+
}
2675+
`, networkName, databaseName, databaseName, switchEnabled, addressRangeName)
2676+
}
2677+
26092678
func TestAccSqlDatabaseInstance_EnableGoogleDataplexIntegration(t *testing.T) {
26102679
t.Parallel()
26112680

website/docs/r/sql_database_instance.html.markdown

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,8 @@ SQL Server version to use. Supported values include `MYSQL_5_6`,
369369
[Database Version Policies](https://cloud.google.com/sql/docs/db-versions)
370370
includes an up-to-date reference of supported versions.
371371

372+
* `switch_transaction_logs_to_cloud_storage_enabled` - (Optional) When set to `true`, Cloud SQL instances can switch storing point-in-time recovery transaction logs from a data disk to Cloud Storage, freeing up data disk space and enabling longer retention windows. This is an input-only field that is not persisted in the API.
373+
372374
* `name` - (Optional, Computed) The name of the instance. If the name is left
373375
blank, Terraform will randomly generate one when the instance is first
374376
created. This is done because after a name is used, it cannot be reused for

0 commit comments

Comments
 (0)