Skip to content

Commit

Permalink
Fix Terraform updates for instances with Google ML Integration enable…
Browse files Browse the repository at this point in the history
…d (#10411) (hashicorp#7249)

[upstream:2faba8433361d680285cc3282f8ce9a62f883000]

Signed-off-by: Modular Magician <[email protected]>
  • Loading branch information
modular-magician authored Apr 16, 2024
1 parent bf90594 commit 3e19afc
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
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

0 comments on commit 3e19afc

Please sign in to comment.