Skip to content

Commit

Permalink
Add enable_google_ml_integration setting to google_sql_database_insta… (
Browse files Browse the repository at this point in the history
#10383) (#17798)

[upstream:df5407f99c91d86116ccdc27e512630c86980b5d]

Signed-off-by: Modular Magician <magic-modules@google.com>
  • Loading branch information
modular-magician committed Apr 8, 2024
1 parent 07d44c7 commit ef13bca
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .changelog/10383.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
sql: added `enable_google_ml_integration` field to `google_sql_database_instance` resource
```
15 changes: 14 additions & 1 deletion google/services/sql/resource_sql_database_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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{})),
Expand All @@ -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()),
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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
}
Expand Down
48 changes: 48 additions & 0 deletions google/services/sql/resource_sql_database_instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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" {
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 @@ -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.
Expand Down

0 comments on commit ef13bca

Please sign in to comment.