From 3017b58f76822b3964568a32df0396d1bec73d5a Mon Sep 17 00:00:00 2001 From: The Magician Date: Mon, 8 Apr 2024 13:32:35 -0700 Subject: [PATCH] =?UTF-8?q?Add=20enable=5Fgoogle=5Fml=5Fintegration=20sett?= =?UTF-8?q?ing=20to=20google=5Fsql=5Fdatabase=5Finsta=E2=80=A6=20(#10383)?= =?UTF-8?q?=20(#7208)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit [upstream:df5407f99c91d86116ccdc27e512630c86980b5d] Signed-off-by: Modular Magician --- .changelog/10383.txt | 3 ++ .../sql/resource_sql_database_instance.go | 15 +++++- .../resource_sql_database_instance_test.go | 48 +++++++++++++++++++ .../r/sql_database_instance.html.markdown | 2 + 4 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 .changelog/10383.txt diff --git a/.changelog/10383.txt b/.changelog/10383.txt new file mode 100644 index 0000000000..322ca740b0 --- /dev/null +++ b/.changelog/10383.txt @@ -0,0 +1,3 @@ +```release-note:enhancement +sql: added `enable_google_ml_integration` field to `google_sql_database_instance` resource +``` \ No newline at end of file diff --git a/google-beta/services/sql/resource_sql_database_instance.go b/google-beta/services/sql/resource_sql_database_instance.go index c86d0101c3..29ecf4b7e5 100644 --- a/google-beta/services/sql/resource_sql_database_instance.go +++ b/google-beta/services/sql/resource_sql_database_instance.go @@ -397,6 +397,11 @@ is set to true. Defaults to ZONAL.`, Default: 0, 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.`, }, + "enable_google_ml_integration": { + Type: schema.TypeBool, + Optional: true, + Description: `Enables Vertex AI Integration.`, + }, "disk_size": { Type: schema.TypeInt, Optional: true, @@ -1268,7 +1273,7 @@ func expandSqlDatabaseInstanceSettings(configured []interface{}, databaseVersion Tier: _settings["tier"].(string), Edition: _settings["edition"].(string), AdvancedMachineFeatures: expandSqlServerAdvancedMachineFeatures(_settings["advanced_machine_features"].([]interface{})), - ForceSendFields: []string{"StorageAutoResize"}, + ForceSendFields: []string{"StorageAutoResize", "EnableGoogleMlIntegration"}, ActivationPolicy: _settings["activation_policy"].(string), ActiveDirectoryConfig: expandActiveDirectoryConfig(_settings["active_directory_config"].([]interface{})), DenyMaintenancePeriods: expandDenyMaintenancePeriod(_settings["deny_maintenance_period"].([]interface{})), @@ -1281,6 +1286,7 @@ func expandSqlDatabaseInstanceSettings(configured []interface{}, databaseVersion DataDiskType: _settings["disk_type"].(string), PricingPlan: _settings["pricing_plan"].(string), DeletionProtectionEnabled: _settings["deletion_protection_enabled"].(bool), + EnableGoogleMlIntegration: _settings["enable_google_ml_integration"].(bool), UserLabels: tpgresource.ConvertStringMap(_settings["user_labels"].(map[string]interface{})), BackupConfiguration: expandBackupConfiguration(_settings["backup_configuration"].([]interface{})), DatabaseFlags: expandDatabaseFlags(_settings["database_flags"].(*schema.Set).List()), @@ -1932,6 +1938,11 @@ func resourceSqlDatabaseInstanceUpdate(d *schema.ResourceData, meta interface{}) instance.InstanceType = d.Get("instance_type").(string) } + // Database Version is required for enabling Google ML integration. + if d.HasChange("settings.0.enable_google_ml_integration") { + instance.DatabaseVersion = databaseVersion + } + err = transport_tpg.Retry(transport_tpg.RetryOptions{ RetryFunc: func() (rerr error) { 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[ data["disk_autoresize"] = settings.StorageAutoResize data["disk_autoresize_limit"] = settings.StorageAutoResizeLimit + data["enable_google_ml_integration"] = settings.EnableGoogleMlIntegration + if settings.UserLabels != nil { data["user_labels"] = settings.UserLabels } diff --git a/google-beta/services/sql/resource_sql_database_instance_test.go b/google-beta/services/sql/resource_sql_database_instance_test.go index 571df0424e..c7336bf294 100644 --- a/google-beta/services/sql/resource_sql_database_instance_test.go +++ b/google-beta/services/sql/resource_sql_database_instance_test.go @@ -1355,6 +1355,38 @@ func TestAccSqlDatabaseInstance_PointInTimeRecoveryEnabledForSqlServer(t *testin }) } +func TestAccSqlDatabaseInstance_EnableGoogleMlIntegration(t *testing.T) { + t.Parallel() + + masterID := acctest.RandInt(t) + + acctest.VcrTest(t, resource.TestCase{ + PreCheck: func() { acctest.AccTestPreCheck(t) }, + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t), + CheckDestroy: testAccSqlDatabaseInstanceDestroyProducer(t), + Steps: []resource.TestStep{ + { + Config: testGoogleSqlDatabaseInstance_EnableGoogleMlIntegration(masterID, true, "POSTGRES_14"), + }, + { + ResourceName: "google_sql_database_instance.instance", + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"deletion_protection", "root_password"}, + }, + { + Config: testGoogleSqlDatabaseInstance_EnableGoogleMlIntegration(masterID, false, "POSTGRES_14"), + }, + { + ResourceName: "google_sql_database_instance.instance", + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"deletion_protection", "root_password"}, + }, + }, + }) +} + func TestAccSqlDatabaseInstance_insights(t *testing.T) { t.Parallel() @@ -3859,6 +3891,22 @@ resource "google_sql_database_instance" "instance" { `, masterID, dbVersion, masterID, pointInTimeRecoveryEnabled) } +func testGoogleSqlDatabaseInstance_EnableGoogleMlIntegration(masterID int, enableGoogleMlIntegration bool, dbVersion string) string { + return fmt.Sprintf(` +resource "google_sql_database_instance" "instance" { + name = "tf-test-%d" + region = "us-central1" + database_version = "%s" + deletion_protection = false + root_password = "rand-pwd-%d" + settings { + tier = "db-custom-2-13312" + enable_google_ml_integration = %t + } +} +`, masterID, dbVersion, masterID, enableGoogleMlIntegration) +} + func testGoogleSqlDatabaseInstance_BackupRetention(masterID int) string { return fmt.Sprintf(` resource "google_sql_database_instance" "instance" { diff --git a/website/docs/r/sql_database_instance.html.markdown b/website/docs/r/sql_database_instance.html.markdown index fc057586ed..3bdf7ad727 100644 --- a/website/docs/r/sql_database_instance.html.markdown +++ b/website/docs/r/sql_database_instance.html.markdown @@ -288,6 +288,8 @@ The `settings` block supports: * `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`. +* `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`. + * `disk_autoresize` - (Optional) Enables auto-resizing of the storage size. Defaults to `true`. * `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.