From 3badb6127dd912c1c7b65e64d1a50944ec3fbf55 Mon Sep 17 00:00:00 2001 From: rsm3171990 Date: Tue, 16 Apr 2024 15:44:04 -0700 Subject: [PATCH] Fix Terraform updates for instances with Google ML Integration enabled (#10411) --- .../sql/resource_sql_database_instance.go.erb | 4 ++-- .../resource_sql_database_instance_test.go | 20 ++++++++++++++----- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/mmv1/third_party/terraform/services/sql/resource_sql_database_instance.go.erb b/mmv1/third_party/terraform/services/sql/resource_sql_database_instance.go.erb index eea792b5136a..93614f156d62 100644 --- a/mmv1/third_party/terraform/services/sql/resource_sql_database_instance.go.erb +++ b/mmv1/third_party/terraform/services/sql/resource_sql_database_instance.go.erb @@ -1939,8 +1939,8 @@ 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") { + // Database Version is required for all calls with Google ML integration enabled or it will be rejected by the API. + if d.Get("settings.0.enable_google_ml_integration").(bool) { instance.DatabaseVersion = databaseVersion } diff --git a/mmv1/third_party/terraform/services/sql/resource_sql_database_instance_test.go b/mmv1/third_party/terraform/services/sql/resource_sql_database_instance_test.go index a9ee4ecfd70d..8308b4ae7e28 100644 --- a/mmv1/third_party/terraform/services/sql/resource_sql_database_instance_test.go +++ b/mmv1/third_party/terraform/services/sql/resource_sql_database_instance_test.go @@ -1364,7 +1364,7 @@ func TestAccSqlDatabaseInstance_EnableGoogleMlIntegration(t *testing.T) { CheckDestroy: testAccSqlDatabaseInstanceDestroyProducer(t), Steps: []resource.TestStep{ { - Config: testGoogleSqlDatabaseInstance_EnableGoogleMlIntegration(masterID, true, "POSTGRES_14"), + Config: testGoogleSqlDatabaseInstance_EnableGoogleMlIntegration(masterID, true, "POSTGRES_14", "db-custom-2-13312"), }, { ResourceName: "google_sql_database_instance.instance", @@ -1372,8 +1372,18 @@ func TestAccSqlDatabaseInstance_EnableGoogleMlIntegration(t *testing.T) { ImportStateVerify: true, ImportStateVerifyIgnore: []string{"deletion_protection", "root_password"}, }, + // Test that updates to other settings work after google-ml-integration is enabled { - Config: testGoogleSqlDatabaseInstance_EnableGoogleMlIntegration(masterID, false, "POSTGRES_14"), + Config: testGoogleSqlDatabaseInstance_EnableGoogleMlIntegration(masterID, true, "POSTGRES_14", "db-custom-2-10240"), + }, + { + ResourceName: "google_sql_database_instance.instance", + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"deletion_protection", "root_password"}, + }, + { + Config: testGoogleSqlDatabaseInstance_EnableGoogleMlIntegration(masterID, false, "POSTGRES_14", "db-custom-2-10240"), }, { ResourceName: "google_sql_database_instance.instance", @@ -3889,7 +3899,7 @@ resource "google_sql_database_instance" "instance" { `, masterID, dbVersion, masterID, pointInTimeRecoveryEnabled) } -func testGoogleSqlDatabaseInstance_EnableGoogleMlIntegration(masterID int, enableGoogleMlIntegration bool, dbVersion string) string { +func testGoogleSqlDatabaseInstance_EnableGoogleMlIntegration(masterID int, enableGoogleMlIntegration bool, dbVersion string, tier string) string { return fmt.Sprintf(` resource "google_sql_database_instance" "instance" { name = "tf-test-%d" @@ -3898,11 +3908,11 @@ resource "google_sql_database_instance" "instance" { deletion_protection = false root_password = "rand-pwd-%d" settings { - tier = "db-custom-2-13312" + tier = "%s" enable_google_ml_integration = %t } } -`, masterID, dbVersion, masterID, enableGoogleMlIntegration) +`, masterID, dbVersion, masterID, tier, enableGoogleMlIntegration) } func testGoogleSqlDatabaseInstance_BackupRetention(masterID int) string {