Skip to content

Commit 3017b58

Browse files
Add enable_google_ml_integration setting to google_sql_database_insta… (#10383) (#7208)
[upstream:df5407f99c91d86116ccdc27e512630c86980b5d] Signed-off-by: Modular Magician <[email protected]>
1 parent 83b3e7d commit 3017b58

File tree

4 files changed

+67
-1
lines changed

4 files changed

+67
-1
lines changed

.changelog/10383.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 `enable_google_ml_integration` field to `google_sql_database_instance` resource
3+
```

google-beta/services/sql/resource_sql_database_instance.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,11 @@ is set to true. Defaults to ZONAL.`,
397397
Default: 0,
398398
Description: `The maximum size, in GB, to which storage capacity can be automatically increased. The default value is 0, which specifies that there is no limit.`,
399399
},
400+
"enable_google_ml_integration": {
401+
Type: schema.TypeBool,
402+
Optional: true,
403+
Description: `Enables Vertex AI Integration.`,
404+
},
400405
"disk_size": {
401406
Type: schema.TypeInt,
402407
Optional: true,
@@ -1268,7 +1273,7 @@ func expandSqlDatabaseInstanceSettings(configured []interface{}, databaseVersion
12681273
Tier: _settings["tier"].(string),
12691274
Edition: _settings["edition"].(string),
12701275
AdvancedMachineFeatures: expandSqlServerAdvancedMachineFeatures(_settings["advanced_machine_features"].([]interface{})),
1271-
ForceSendFields: []string{"StorageAutoResize"},
1276+
ForceSendFields: []string{"StorageAutoResize", "EnableGoogleMlIntegration"},
12721277
ActivationPolicy: _settings["activation_policy"].(string),
12731278
ActiveDirectoryConfig: expandActiveDirectoryConfig(_settings["active_directory_config"].([]interface{})),
12741279
DenyMaintenancePeriods: expandDenyMaintenancePeriod(_settings["deny_maintenance_period"].([]interface{})),
@@ -1281,6 +1286,7 @@ func expandSqlDatabaseInstanceSettings(configured []interface{}, databaseVersion
12811286
DataDiskType: _settings["disk_type"].(string),
12821287
PricingPlan: _settings["pricing_plan"].(string),
12831288
DeletionProtectionEnabled: _settings["deletion_protection_enabled"].(bool),
1289+
EnableGoogleMlIntegration: _settings["enable_google_ml_integration"].(bool),
12841290
UserLabels: tpgresource.ConvertStringMap(_settings["user_labels"].(map[string]interface{})),
12851291
BackupConfiguration: expandBackupConfiguration(_settings["backup_configuration"].([]interface{})),
12861292
DatabaseFlags: expandDatabaseFlags(_settings["database_flags"].(*schema.Set).List()),
@@ -1932,6 +1938,11 @@ func resourceSqlDatabaseInstanceUpdate(d *schema.ResourceData, meta interface{})
19321938
instance.InstanceType = d.Get("instance_type").(string)
19331939
}
19341940

1941+
// Database Version is required for enabling Google ML integration.
1942+
if d.HasChange("settings.0.enable_google_ml_integration") {
1943+
instance.DatabaseVersion = databaseVersion
1944+
}
1945+
19351946
err = transport_tpg.Retry(transport_tpg.RetryOptions{
19361947
RetryFunc: func() (rerr error) {
19371948
op, rerr = config.NewSqlAdminClient(userAgent).Instances.Update(project, d.Get("name").(string), instance).Do()
@@ -2099,6 +2110,8 @@ func flattenSettings(settings *sqladmin.Settings, d *schema.ResourceData) []map[
20992110
data["disk_autoresize"] = settings.StorageAutoResize
21002111
data["disk_autoresize_limit"] = settings.StorageAutoResizeLimit
21012112

2113+
data["enable_google_ml_integration"] = settings.EnableGoogleMlIntegration
2114+
21022115
if settings.UserLabels != nil {
21032116
data["user_labels"] = settings.UserLabels
21042117
}

google-beta/services/sql/resource_sql_database_instance_test.go

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1355,6 +1355,38 @@ func TestAccSqlDatabaseInstance_PointInTimeRecoveryEnabledForSqlServer(t *testin
13551355
})
13561356
}
13571357

1358+
func TestAccSqlDatabaseInstance_EnableGoogleMlIntegration(t *testing.T) {
1359+
t.Parallel()
1360+
1361+
masterID := acctest.RandInt(t)
1362+
1363+
acctest.VcrTest(t, resource.TestCase{
1364+
PreCheck: func() { acctest.AccTestPreCheck(t) },
1365+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
1366+
CheckDestroy: testAccSqlDatabaseInstanceDestroyProducer(t),
1367+
Steps: []resource.TestStep{
1368+
{
1369+
Config: testGoogleSqlDatabaseInstance_EnableGoogleMlIntegration(masterID, true, "POSTGRES_14"),
1370+
},
1371+
{
1372+
ResourceName: "google_sql_database_instance.instance",
1373+
ImportState: true,
1374+
ImportStateVerify: true,
1375+
ImportStateVerifyIgnore: []string{"deletion_protection", "root_password"},
1376+
},
1377+
{
1378+
Config: testGoogleSqlDatabaseInstance_EnableGoogleMlIntegration(masterID, false, "POSTGRES_14"),
1379+
},
1380+
{
1381+
ResourceName: "google_sql_database_instance.instance",
1382+
ImportState: true,
1383+
ImportStateVerify: true,
1384+
ImportStateVerifyIgnore: []string{"deletion_protection", "root_password"},
1385+
},
1386+
},
1387+
})
1388+
}
1389+
13581390
func TestAccSqlDatabaseInstance_insights(t *testing.T) {
13591391
t.Parallel()
13601392

@@ -3859,6 +3891,22 @@ resource "google_sql_database_instance" "instance" {
38593891
`, masterID, dbVersion, masterID, pointInTimeRecoveryEnabled)
38603892
}
38613893

3894+
func testGoogleSqlDatabaseInstance_EnableGoogleMlIntegration(masterID int, enableGoogleMlIntegration bool, dbVersion string) string {
3895+
return fmt.Sprintf(`
3896+
resource "google_sql_database_instance" "instance" {
3897+
name = "tf-test-%d"
3898+
region = "us-central1"
3899+
database_version = "%s"
3900+
deletion_protection = false
3901+
root_password = "rand-pwd-%d"
3902+
settings {
3903+
tier = "db-custom-2-13312"
3904+
enable_google_ml_integration = %t
3905+
}
3906+
}
3907+
`, masterID, dbVersion, masterID, enableGoogleMlIntegration)
3908+
}
3909+
38623910
func testGoogleSqlDatabaseInstance_BackupRetention(masterID int) string {
38633911
return fmt.Sprintf(`
38643912
resource "google_sql_database_instance" "instance" {

website/docs/r/sql_database_instance.html.markdown

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,8 @@ The `settings` block supports:
288288

289289
* `deletion_protection_enabled` - (Optional) Enables deletion protection of an instance at the GCP level. Enabling this protection will guard against accidental deletion across all surfaces (API, gcloud, Cloud Console and Terraform) by enabling the [GCP Cloud SQL instance deletion protection](https://cloud.google.com/sql/docs/postgres/deletion-protection). Terraform provider support was introduced in version 4.48.0. Defaults to `false`.
290290

291+
* `enable_google_ml_integration` - (Optional) Enables [Cloud SQL instances to connect to Vertex AI](https://cloud.google.com/sql/docs/postgres/integrate-cloud-sql-with-vertex-ai) and pass requests for real-time predictions and insights. Defaults to `false`.
292+
291293
* `disk_autoresize` - (Optional) Enables auto-resizing of the storage size. Defaults to `true`.
292294

293295
* `disk_autoresize_limit` - (Optional) The maximum size to which storage capacity can be automatically increased. The default value is 0, which specifies that there is no limit.

0 commit comments

Comments
 (0)