From 3e19afc771f4febb6737790090e159df7d2a4049 Mon Sep 17 00:00:00 2001 From: The Magician Date: Tue, 16 Apr 2024 15:48:43 -0700 Subject: [PATCH] Fix Terraform updates for instances with Google ML Integration enabled (#10411) (#7249) [upstream:2faba8433361d680285cc3282f8ce9a62f883000] Signed-off-by: Modular Magician --- .changelog/10411.txt | 3 +++ .../sql/resource_sql_database_instance.go | 4 ++-- .../resource_sql_database_instance_test.go | 20 ++++++++++++++----- 3 files changed, 20 insertions(+), 7 deletions(-) create mode 100644 .changelog/10411.txt diff --git a/.changelog/10411.txt b/.changelog/10411.txt new file mode 100644 index 0000000000..2b8044ab43 --- /dev/null +++ b/.changelog/10411.txt @@ -0,0 +1,3 @@ +```release-note:bug +sql: fixed issues with updating the `enable_google_ml_integration` field in `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 29ecf4b7e5..1a9487b541 100644 --- a/google-beta/services/sql/resource_sql_database_instance.go +++ b/google-beta/services/sql/resource_sql_database_instance.go @@ -1938,8 +1938,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/google-beta/services/sql/resource_sql_database_instance_test.go b/google-beta/services/sql/resource_sql_database_instance_test.go index c7336bf294..aa67228918 100644 --- a/google-beta/services/sql/resource_sql_database_instance_test.go +++ b/google-beta/services/sql/resource_sql_database_instance_test.go @@ -1366,7 +1366,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", @@ -1374,8 +1374,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", @@ -3891,7 +3901,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" @@ -3900,11 +3910,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 {