|
75 | 75 | "settings.0.backup_configuration.0.transaction_log_retention_days",
|
76 | 76 | }
|
77 | 77 |
|
| 78 | + connectionPoolConfigKeys = []string{ |
| 79 | + "settings.0.connection_pool_config.0.connection_pooling_enabled", |
| 80 | + "settings.0.connection_pool_config.0.flags", |
| 81 | + } |
| 82 | + |
78 | 83 | ipConfigurationKeys = []string{
|
79 | 84 | "settings.0.ip_configuration.0.authorized_networks",
|
80 | 85 | "settings.0.ip_configuration.0.ipv4_enabled",
|
@@ -432,6 +437,28 @@ is set to true. Defaults to ZONAL.`,
|
432 | 437 | DiffSuppressFunc: caseDiffDashSuppress,
|
433 | 438 | Description: `The type of supported data disk is tier dependent and can be PD_SSD or PD_HDD or HYPERDISK_BALANCED.`,
|
434 | 439 | },
|
| 440 | + "connection_pool_config": { |
| 441 | + Type: schema.TypeSet, |
| 442 | + Optional: true, |
| 443 | + Computed: true, |
| 444 | + Description: `The managed connection pool setting for a Cloud SQL instance.`, |
| 445 | + Elem: &schema.Resource{ |
| 446 | + Schema: map[string]*schema.Schema{ |
| 447 | + "connection_pooling_enabled": { |
| 448 | + Type: schema.TypeBool, |
| 449 | + Optional: true, |
| 450 | + Description: `Whether Managed Connection Pool is enabled for this instance.`, |
| 451 | + }, |
| 452 | + "flags": { |
| 453 | + Type: schema.TypeSet, |
| 454 | + Optional: true, |
| 455 | + Set: schema.HashResource(sqlDatabaseFlagSchemaElem), |
| 456 | + Elem: sqlDatabaseFlagSchemaElem, |
| 457 | + Description: `List of connection pool configuration flags`, |
| 458 | + }, |
| 459 | + }, |
| 460 | + }, |
| 461 | + }, |
435 | 462 | "ip_configuration": {
|
436 | 463 | Type: schema.TypeList,
|
437 | 464 | Optional: true,
|
@@ -1409,6 +1436,7 @@ func expandSqlDatabaseInstanceSettings(configured []interface{}, databaseVersion
|
1409 | 1436 | UserLabels: tpgresource.ConvertStringMap(_settings["user_labels"].(map[string]interface{})),
|
1410 | 1437 | BackupConfiguration: expandBackupConfiguration(_settings["backup_configuration"].([]interface{})),
|
1411 | 1438 | DatabaseFlags: expandDatabaseFlags(_settings["database_flags"].(*schema.Set).List()),
|
| 1439 | + ConnectionPoolConfig: expandConnectionPoolConfig(_settings["connection_pool_config"].(*schema.Set).List()), |
1412 | 1440 | IpConfiguration: expandIpConfiguration(_settings["ip_configuration"].([]interface{}), databaseVersion),
|
1413 | 1441 | LocationPreference: expandLocationPreference(_settings["location_preference"].([]interface{})),
|
1414 | 1442 | MaintenanceWindow: expandMaintenanceWindow(_settings["maintenance_window"].([]interface{})),
|
@@ -1558,6 +1586,35 @@ func expandPscConfig(configured []interface{}) *sqladmin.PscConfig {
|
1558 | 1586 | return nil
|
1559 | 1587 | }
|
1560 | 1588 |
|
| 1589 | +func expandFlags(configured []interface{}) []*sqladmin.ConnectionPoolFlags { |
| 1590 | + connectionPoolFlags := make([]*sqladmin.ConnectionPoolFlags, 0, len(configured)) |
| 1591 | + for _, _flag := range configured { |
| 1592 | + if _flag == nil { |
| 1593 | + continue |
| 1594 | + } |
| 1595 | + _entry := _flag.(map[string]interface{}) |
| 1596 | + |
| 1597 | + connectionPoolFlags = append(connectionPoolFlags, &sqladmin.ConnectionPoolFlags{ |
| 1598 | + Name: _entry["name"].(string), |
| 1599 | + Value: _entry["value"].(string), |
| 1600 | + }) |
| 1601 | + } |
| 1602 | + return connectionPoolFlags |
| 1603 | +} |
| 1604 | + |
| 1605 | +func expandConnectionPoolConfig(configured []interface{}) *sqladmin.ConnectionPoolConfig { |
| 1606 | + if len(configured) == 0 || configured[0] == nil { |
| 1607 | + return nil |
| 1608 | + } |
| 1609 | + |
| 1610 | + _connectionPoolConfig := configured[0].(map[string]interface{}) |
| 1611 | + |
| 1612 | + return &sqladmin.ConnectionPoolConfig{ |
| 1613 | + ConnectionPoolingEnabled: _connectionPoolConfig["connection_pooling_enabled"].(bool), |
| 1614 | + Flags: expandFlags(_connectionPoolConfig["flags"].(*schema.Set).List()), |
| 1615 | + } |
| 1616 | +} |
| 1617 | + |
1561 | 1618 | func expandAuthorizedNetworks(configured []interface{}) []*sqladmin.AclEntry {
|
1562 | 1619 | an := make([]*sqladmin.AclEntry, 0, len(configured))
|
1563 | 1620 | for _, _acl := range configured {
|
@@ -2315,6 +2372,10 @@ func flattenSettings(settings *sqladmin.Settings, d *schema.ResourceData) []map[
|
2315 | 2372 | data["database_flags"] = flattenDatabaseFlags(settings.DatabaseFlags)
|
2316 | 2373 | }
|
2317 | 2374 |
|
| 2375 | + if settings.ConnectionPoolConfig != nil { |
| 2376 | + data["connection_pool_config"] = flattenConnectionPoolConfig(settings.ConnectionPoolConfig) |
| 2377 | + } |
| 2378 | + |
2318 | 2379 | if settings.IpConfiguration != nil {
|
2319 | 2380 | data["ip_configuration"] = flattenIpConfiguration(settings.IpConfiguration, d)
|
2320 | 2381 | }
|
@@ -2485,6 +2546,38 @@ func flattenReplicationCluster(replicationCluster *sqladmin.ReplicationCluster,
|
2485 | 2546 | return []map[string]interface{}{data}
|
2486 | 2547 | }
|
2487 | 2548 |
|
| 2549 | +func flattenConnectionPoolFlags(connectionPoolFlags []*sqladmin.ConnectionPoolFlags) []interface{} { |
| 2550 | + if len(connectionPoolFlags) == 0 { // Handles nil or empty slice |
| 2551 | + return make([]interface{}, 0) // Explicitly return empty slice |
| 2552 | + } |
| 2553 | + |
| 2554 | + mcpflags := make([]interface{}, len(connectionPoolFlags)) // Pre-allocate for efficiency |
| 2555 | + for i, mcpflag := range connectionPoolFlags { |
| 2556 | + data := map[string]interface{}{ |
| 2557 | + "name": mcpflag.Name, |
| 2558 | + "value": mcpflag.Value, |
| 2559 | + } |
| 2560 | + mcpflags[i] = data |
| 2561 | + } |
| 2562 | + return mcpflags |
| 2563 | +} |
| 2564 | + |
| 2565 | +func flattenConnectionPoolConfig(connectionPoolConfig *sqladmin.ConnectionPoolConfig) []interface{} { |
| 2566 | + if connectionPoolConfig == nil { |
| 2567 | + return []interface{}{ |
| 2568 | + map[string]interface{}{ |
| 2569 | + "connection_pooling_enabled": false, |
| 2570 | + "flags": make([]interface{}, 0), // Default to empty flags |
| 2571 | + }, |
| 2572 | + } |
| 2573 | + } |
| 2574 | + data := map[string]interface{}{ |
| 2575 | + "connection_pooling_enabled": connectionPoolConfig.ConnectionPoolingEnabled, // Corrected key |
| 2576 | + "flags": flattenConnectionPoolFlags(connectionPoolConfig.Flags), // Corrected key |
| 2577 | + } |
| 2578 | + return []interface{}{data} |
| 2579 | +} |
| 2580 | + |
2488 | 2581 | func flattenIpConfiguration(ipConfiguration *sqladmin.IpConfiguration, d *schema.ResourceData) interface{} {
|
2489 | 2582 | data := map[string]interface{}{
|
2490 | 2583 | "ipv4_enabled": ipConfiguration.Ipv4Enabled,
|
|
0 commit comments