Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Terraform updates for instances with Google ML Integration enabled #7249

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/10411.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
sql: fixed issues with updating the `enable_google_ml_integration` field in `google_sql_database_instance` resource
```
4 changes: 2 additions & 2 deletions google-beta/services/sql/resource_sql_database_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
20 changes: 15 additions & 5 deletions google-beta/services/sql/resource_sql_database_instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1366,16 +1366,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 @@ -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"
Expand All @@ -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 {
Expand Down