Skip to content

Commit 09d3ef5

Browse files
Fix Terraform updates for instances with Google ML Integration enabled (#10411) (#17878)
[upstream:2faba8433361d680285cc3282f8ce9a62f883000] Signed-off-by: Modular Magician <magic-modules@google.com>
1 parent a092786 commit 09d3ef5

File tree

3 files changed

+20
-7
lines changed

3 files changed

+20
-7
lines changed

.changelog/10411.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:bug
2+
sql: fixed issues with updating the `enable_google_ml_integration` field in `google_sql_database_instance` resource
3+
```

google/services/sql/resource_sql_database_instance.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1938,8 +1938,8 @@ func resourceSqlDatabaseInstanceUpdate(d *schema.ResourceData, meta interface{})
19381938
instance.InstanceType = d.Get("instance_type").(string)
19391939
}
19401940

1941-
// Database Version is required for enabling Google ML integration.
1942-
if d.HasChange("settings.0.enable_google_ml_integration") {
1941+
// Database Version is required for all calls with Google ML integration enabled or it will be rejected by the API.
1942+
if d.Get("settings.0.enable_google_ml_integration").(bool) {
19431943
instance.DatabaseVersion = databaseVersion
19441944
}
19451945

google/services/sql/resource_sql_database_instance_test.go

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1366,16 +1366,26 @@ func TestAccSqlDatabaseInstance_EnableGoogleMlIntegration(t *testing.T) {
13661366
CheckDestroy: testAccSqlDatabaseInstanceDestroyProducer(t),
13671367
Steps: []resource.TestStep{
13681368
{
1369-
Config: testGoogleSqlDatabaseInstance_EnableGoogleMlIntegration(masterID, true, "POSTGRES_14"),
1369+
Config: testGoogleSqlDatabaseInstance_EnableGoogleMlIntegration(masterID, true, "POSTGRES_14", "db-custom-2-13312"),
13701370
},
13711371
{
13721372
ResourceName: "google_sql_database_instance.instance",
13731373
ImportState: true,
13741374
ImportStateVerify: true,
13751375
ImportStateVerifyIgnore: []string{"deletion_protection", "root_password"},
13761376
},
1377+
// Test that updates to other settings work after google-ml-integration is enabled
13771378
{
1378-
Config: testGoogleSqlDatabaseInstance_EnableGoogleMlIntegration(masterID, false, "POSTGRES_14"),
1379+
Config: testGoogleSqlDatabaseInstance_EnableGoogleMlIntegration(masterID, true, "POSTGRES_14", "db-custom-2-10240"),
1380+
},
1381+
{
1382+
ResourceName: "google_sql_database_instance.instance",
1383+
ImportState: true,
1384+
ImportStateVerify: true,
1385+
ImportStateVerifyIgnore: []string{"deletion_protection", "root_password"},
1386+
},
1387+
{
1388+
Config: testGoogleSqlDatabaseInstance_EnableGoogleMlIntegration(masterID, false, "POSTGRES_14", "db-custom-2-10240"),
13791389
},
13801390
{
13811391
ResourceName: "google_sql_database_instance.instance",
@@ -3891,7 +3901,7 @@ resource "google_sql_database_instance" "instance" {
38913901
`, masterID, dbVersion, masterID, pointInTimeRecoveryEnabled)
38923902
}
38933903

3894-
func testGoogleSqlDatabaseInstance_EnableGoogleMlIntegration(masterID int, enableGoogleMlIntegration bool, dbVersion string) string {
3904+
func testGoogleSqlDatabaseInstance_EnableGoogleMlIntegration(masterID int, enableGoogleMlIntegration bool, dbVersion string, tier string) string {
38953905
return fmt.Sprintf(`
38963906
resource "google_sql_database_instance" "instance" {
38973907
name = "tf-test-%d"
@@ -3900,11 +3910,11 @@ resource "google_sql_database_instance" "instance" {
39003910
deletion_protection = false
39013911
root_password = "rand-pwd-%d"
39023912
settings {
3903-
tier = "db-custom-2-13312"
3913+
tier = "%s"
39043914
enable_google_ml_integration = %t
39053915
}
39063916
}
3907-
`, masterID, dbVersion, masterID, enableGoogleMlIntegration)
3917+
`, masterID, dbVersion, masterID, tier, enableGoogleMlIntegration)
39083918
}
39093919

39103920
func testGoogleSqlDatabaseInstance_BackupRetention(masterID int) string {

0 commit comments

Comments
 (0)