|
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", |
@@ -444,6 +449,28 @@ is set to true. Defaults to ZONAL.`, |
444 | 449 | Computed: true, |
445 | 450 | Description: `Provisioned throughput measured in MiB per second for the data disk. This field is only used for HYPERDISK_BALANCED disk types.`, |
446 | 451 | }, |
| 452 | + "connection_pool_config": { |
| 453 | + Type: schema.TypeSet, |
| 454 | + Optional: true, |
| 455 | + Computed: true, |
| 456 | + Description: `The managed connection pool setting for a Cloud SQL instance.`, |
| 457 | + Elem: &schema.Resource{ |
| 458 | + Schema: map[string]*schema.Schema{ |
| 459 | + "connection_pooling_enabled": { |
| 460 | + Type: schema.TypeBool, |
| 461 | + Optional: true, |
| 462 | + Description: `Whether Managed Connection Pool is enabled for this instance.`, |
| 463 | + }, |
| 464 | + "flags": { |
| 465 | + Type: schema.TypeSet, |
| 466 | + Optional: true, |
| 467 | + Set: schema.HashResource(sqlDatabaseFlagSchemaElem), |
| 468 | + Elem: sqlDatabaseFlagSchemaElem, |
| 469 | + Description: `List of connection pool configuration flags`, |
| 470 | + }, |
| 471 | + }, |
| 472 | + }, |
| 473 | + }, |
447 | 474 | "ip_configuration": { |
448 | 475 | Type: schema.TypeList, |
449 | 476 | Optional: true, |
@@ -1423,6 +1450,7 @@ func expandSqlDatabaseInstanceSettings(configured []interface{}, databaseVersion |
1423 | 1450 | UserLabels: tpgresource.ConvertStringMap(_settings["user_labels"].(map[string]interface{})), |
1424 | 1451 | BackupConfiguration: expandBackupConfiguration(_settings["backup_configuration"].([]interface{})), |
1425 | 1452 | DatabaseFlags: expandDatabaseFlags(_settings["database_flags"].(*schema.Set).List()), |
| 1453 | + ConnectionPoolConfig: expandConnectionPoolConfig(_settings["connection_pool_config"].(*schema.Set).List()), |
1426 | 1454 | IpConfiguration: expandIpConfiguration(_settings["ip_configuration"].([]interface{}), databaseVersion), |
1427 | 1455 | LocationPreference: expandLocationPreference(_settings["location_preference"].([]interface{})), |
1428 | 1456 | MaintenanceWindow: expandMaintenanceWindow(_settings["maintenance_window"].([]interface{})), |
@@ -1572,6 +1600,35 @@ func expandPscConfig(configured []interface{}) *sqladmin.PscConfig { |
1572 | 1600 | return nil |
1573 | 1601 | } |
1574 | 1602 |
|
| 1603 | +func expandFlags(configured []interface{}) []*sqladmin.ConnectionPoolFlags { |
| 1604 | + connectionPoolFlags := make([]*sqladmin.ConnectionPoolFlags, 0, len(configured)) |
| 1605 | + for _, _flag := range configured { |
| 1606 | + if _flag == nil { |
| 1607 | + continue |
| 1608 | + } |
| 1609 | + _entry := _flag.(map[string]interface{}) |
| 1610 | + |
| 1611 | + connectionPoolFlags = append(connectionPoolFlags, &sqladmin.ConnectionPoolFlags{ |
| 1612 | + Name: _entry["name"].(string), |
| 1613 | + Value: _entry["value"].(string), |
| 1614 | + }) |
| 1615 | + } |
| 1616 | + return connectionPoolFlags |
| 1617 | +} |
| 1618 | + |
| 1619 | +func expandConnectionPoolConfig(configured []interface{}) *sqladmin.ConnectionPoolConfig { |
| 1620 | + if len(configured) == 0 || configured[0] == nil { |
| 1621 | + return nil |
| 1622 | + } |
| 1623 | + |
| 1624 | + _connectionPoolConfig := configured[0].(map[string]interface{}) |
| 1625 | + |
| 1626 | + return &sqladmin.ConnectionPoolConfig{ |
| 1627 | + ConnectionPoolingEnabled: _connectionPoolConfig["connection_pooling_enabled"].(bool), |
| 1628 | + Flags: expandFlags(_connectionPoolConfig["flags"].(*schema.Set).List()), |
| 1629 | + } |
| 1630 | +} |
| 1631 | + |
1575 | 1632 | func expandAuthorizedNetworks(configured []interface{}) []*sqladmin.AclEntry { |
1576 | 1633 | an := make([]*sqladmin.AclEntry, 0, len(configured)) |
1577 | 1634 | for _, _acl := range configured { |
@@ -2331,6 +2388,10 @@ func flattenSettings(settings *sqladmin.Settings, d *schema.ResourceData) []map[ |
2331 | 2388 | data["database_flags"] = flattenDatabaseFlags(settings.DatabaseFlags) |
2332 | 2389 | } |
2333 | 2390 |
|
| 2391 | + if settings.ConnectionPoolConfig != nil { |
| 2392 | + data["connection_pool_config"] = flattenConnectionPoolConfig(settings.ConnectionPoolConfig) |
| 2393 | + } |
| 2394 | + |
2334 | 2395 | if settings.IpConfiguration != nil { |
2335 | 2396 | data["ip_configuration"] = flattenIpConfiguration(settings.IpConfiguration, d) |
2336 | 2397 | } |
@@ -2501,6 +2562,38 @@ func flattenReplicationCluster(replicationCluster *sqladmin.ReplicationCluster, |
2501 | 2562 | return []map[string]interface{}{data} |
2502 | 2563 | } |
2503 | 2564 |
|
| 2565 | +func flattenConnectionPoolFlags(connectionPoolFlags []*sqladmin.ConnectionPoolFlags) []interface{} { |
| 2566 | + if len(connectionPoolFlags) == 0 { // Handles nil or empty slice |
| 2567 | + return make([]interface{}, 0) // Explicitly return empty slice |
| 2568 | + } |
| 2569 | + |
| 2570 | + mcpflags := make([]interface{}, len(connectionPoolFlags)) // Pre-allocate for efficiency |
| 2571 | + for i, mcpflag := range connectionPoolFlags { |
| 2572 | + data := map[string]interface{}{ |
| 2573 | + "name": mcpflag.Name, |
| 2574 | + "value": mcpflag.Value, |
| 2575 | + } |
| 2576 | + mcpflags[i] = data |
| 2577 | + } |
| 2578 | + return mcpflags |
| 2579 | +} |
| 2580 | + |
| 2581 | +func flattenConnectionPoolConfig(connectionPoolConfig *sqladmin.ConnectionPoolConfig) []interface{} { |
| 2582 | + if connectionPoolConfig == nil { |
| 2583 | + return []interface{}{ |
| 2584 | + map[string]interface{}{ |
| 2585 | + "connection_pooling_enabled": false, |
| 2586 | + "flags": make([]interface{}, 0), // Default to empty flags |
| 2587 | + }, |
| 2588 | + } |
| 2589 | + } |
| 2590 | + data := map[string]interface{}{ |
| 2591 | + "connection_pooling_enabled": connectionPoolConfig.ConnectionPoolingEnabled, // Corrected key |
| 2592 | + "flags": flattenConnectionPoolFlags(connectionPoolConfig.Flags), // Corrected key |
| 2593 | + } |
| 2594 | + return []interface{}{data} |
| 2595 | +} |
| 2596 | + |
2504 | 2597 | func flattenIpConfiguration(ipConfiguration *sqladmin.IpConfiguration, d *schema.ResourceData) interface{} { |
2505 | 2598 | data := map[string]interface{}{ |
2506 | 2599 | "ipv4_enabled": ipConfiguration.Ipv4Enabled, |
|
0 commit comments