Skip to content

Commit 5c0065b

Browse files
Fix the bug that sql instance can not enable mcp (#14263) (#23332)
[upstream:9a5b2259ad11291ce2cc04229205a184afa7f1c6] Signed-off-by: Modular Magician <[email protected]>
1 parent 2943125 commit 5c0065b

File tree

3 files changed

+36
-2
lines changed

3 files changed

+36
-2
lines changed

.changelog/14263.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 an error in updating `connection_pool_config` in `google_sql_database_instance`
3+
```

google/services/sql/resource_sql_database_instance.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1450,12 +1450,12 @@ func expandSqlDatabaseInstanceSettings(configured []interface{}, databaseVersion
14501450
UserLabels: tpgresource.ConvertStringMap(_settings["user_labels"].(map[string]interface{})),
14511451
BackupConfiguration: expandBackupConfiguration(_settings["backup_configuration"].([]interface{})),
14521452
DatabaseFlags: expandDatabaseFlags(_settings["database_flags"].(*schema.Set).List()),
1453-
ConnectionPoolConfig: expandConnectionPoolConfig(_settings["connection_pool_config"].(*schema.Set).List()),
14541453
IpConfiguration: expandIpConfiguration(_settings["ip_configuration"].([]interface{}), databaseVersion),
14551454
LocationPreference: expandLocationPreference(_settings["location_preference"].([]interface{})),
14561455
MaintenanceWindow: expandMaintenanceWindow(_settings["maintenance_window"].([]interface{})),
14571456
InsightsConfig: expandInsightsConfig(_settings["insights_config"].([]interface{})),
14581457
PasswordValidationPolicy: expandPasswordValidationPolicy(_settings["password_validation_policy"].([]interface{})),
1458+
ConnectionPoolConfig: expandConnectionPoolConfig(_settings["connection_pool_config"].(*schema.Set).List()),
14591459
}
14601460

14611461
resize := _settings["disk_autoresize"].(bool)
@@ -2189,7 +2189,7 @@ func resourceSqlDatabaseInstanceUpdate(d *schema.ResourceData, meta interface{})
21892189
}
21902190

21912191
// Database Version is required for all calls with Google ML integration enabled or it will be rejected by the API.
2192-
if d.Get("settings.0.enable_google_ml_integration").(bool) {
2192+
if d.Get("settings.0.enable_google_ml_integration").(bool) || len(_settings["connection_pool_config"].(*schema.Set).List()) > 0 {
21932193
instance.DatabaseVersion = databaseVersion
21942194
}
21952195

google/services/sql/resource_sql_database_instance_test.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -873,6 +873,37 @@ func TestAccSqlDatabaseInstance_withoutMCPEnabled(t *testing.T) {
873873
})
874874
}
875875

876+
func TestAccSqlDatabaseInstance_updateMCPEnabled(t *testing.T) {
877+
t.Parallel()
878+
879+
instanceName := "tf-test-" + acctest.RandString(t, 10)
880+
resourceName := "google_sql_database_instance.instance"
881+
882+
acctest.VcrTest(t, resource.TestCase{
883+
PreCheck: func() { acctest.AccTestPreCheck(t) },
884+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
885+
CheckDestroy: testAccSqlDatabaseInstanceDestroyProducer(t),
886+
Steps: []resource.TestStep{
887+
{
888+
Config: testAccSqlDatabaseInstance_withoutMCPEnabled(instanceName),
889+
},
890+
{
891+
Config: testAccSqlDatabaseInstance_withMCPEnabled(instanceName),
892+
Check: resource.ComposeTestCheckFunc(
893+
resource.TestCheckResourceAttr(resourceName, "settings.0.connection_pool_config.0.connection_pooling_enabled", "true"),
894+
resource.TestCheckResourceAttr(resourceName, "settings.0.connection_pool_config.0.flags.#", "1"),
895+
),
896+
},
897+
{
898+
ResourceName: resourceName,
899+
ImportState: true,
900+
ImportStateVerify: true,
901+
ImportStateVerifyIgnore: []string{"deletion_protection"},
902+
},
903+
},
904+
})
905+
}
906+
876907
func TestAccSqlDatabaseInstance_withPSCEnabled_withoutAllowedConsumerProjects(t *testing.T) {
877908
t.Parallel()
878909

0 commit comments

Comments
 (0)