Skip to content

Commit 29b1124

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

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-beta/services/sql/resource_sql_database_instance.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1464,12 +1464,12 @@ func expandSqlDatabaseInstanceSettings(configured []interface{}, databaseVersion
14641464
UserLabels: tpgresource.ConvertStringMap(_settings["user_labels"].(map[string]interface{})),
14651465
BackupConfiguration: expandBackupConfiguration(_settings["backup_configuration"].([]interface{})),
14661466
DatabaseFlags: expandDatabaseFlags(_settings["database_flags"].(*schema.Set).List()),
1467-
ConnectionPoolConfig: expandConnectionPoolConfig(_settings["connection_pool_config"].(*schema.Set).List()),
14681467
IpConfiguration: expandIpConfiguration(_settings["ip_configuration"].([]interface{}), databaseVersion),
14691468
LocationPreference: expandLocationPreference(_settings["location_preference"].([]interface{})),
14701469
MaintenanceWindow: expandMaintenanceWindow(_settings["maintenance_window"].([]interface{})),
14711470
InsightsConfig: expandInsightsConfig(_settings["insights_config"].([]interface{})),
14721471
PasswordValidationPolicy: expandPasswordValidationPolicy(_settings["password_validation_policy"].([]interface{})),
1472+
ConnectionPoolConfig: expandConnectionPoolConfig(_settings["connection_pool_config"].(*schema.Set).List()),
14731473
}
14741474

14751475
resize := _settings["disk_autoresize"].(bool)
@@ -2203,7 +2203,7 @@ func resourceSqlDatabaseInstanceUpdate(d *schema.ResourceData, meta interface{})
22032203
}
22042204

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

google-beta/services/sql/resource_sql_database_instance_test.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -908,6 +908,37 @@ func TestAccSqlDatabaseInstance_withoutMCPEnabled(t *testing.T) {
908908
})
909909
}
910910

911+
func TestAccSqlDatabaseInstance_updateMCPEnabled(t *testing.T) {
912+
t.Parallel()
913+
914+
instanceName := "tf-test-" + acctest.RandString(t, 10)
915+
resourceName := "google_sql_database_instance.instance"
916+
917+
acctest.VcrTest(t, resource.TestCase{
918+
PreCheck: func() { acctest.AccTestPreCheck(t) },
919+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
920+
CheckDestroy: testAccSqlDatabaseInstanceDestroyProducer(t),
921+
Steps: []resource.TestStep{
922+
{
923+
Config: testAccSqlDatabaseInstance_withoutMCPEnabled(instanceName),
924+
},
925+
{
926+
Config: testAccSqlDatabaseInstance_withMCPEnabled(instanceName),
927+
Check: resource.ComposeTestCheckFunc(
928+
resource.TestCheckResourceAttr(resourceName, "settings.0.connection_pool_config.0.connection_pooling_enabled", "true"),
929+
resource.TestCheckResourceAttr(resourceName, "settings.0.connection_pool_config.0.flags.#", "1"),
930+
),
931+
},
932+
{
933+
ResourceName: resourceName,
934+
ImportState: true,
935+
ImportStateVerify: true,
936+
ImportStateVerifyIgnore: []string{"deletion_protection"},
937+
},
938+
},
939+
})
940+
}
941+
911942
func TestAccSqlDatabaseInstance_withPSCEnabled_withoutAllowedConsumerProjects(t *testing.T) {
912943
t.Parallel()
913944

0 commit comments

Comments
 (0)