Skip to content

Commit

Permalink
Fix Terraform updates for instances with Google ML Integration enabled (
Browse files Browse the repository at this point in the history
  • Loading branch information
rsm3171990 authored and pawelJas committed May 16, 2024
1 parent 0538c83 commit 6a37748
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1364,16 +1364,26 @@ 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",
ImportState: true,
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",
Expand Down Expand Up @@ -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"
Expand All @@ -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 {
Expand Down

0 comments on commit 6a37748

Please sign in to comment.