Skip to content

Commit a2a4065

Browse files
authored
feat: Managed Connection Pooling support for AlloyDB (#15330)
1 parent 5cbcc92 commit a2a4065

File tree

3 files changed

+443
-0
lines changed

3 files changed

+443
-0
lines changed

mmv1/products/alloydb/Instance.yaml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,3 +474,31 @@ properties:
474474
output: true
475475
item_type:
476476
type: String
477+
- name: 'connectionPoolConfig'
478+
type: NestedObject
479+
description: |
480+
Configuration for Managed Connection Pool.
481+
custom_flatten: 'templates/terraform/custom_flatten/alloydb_instance_connectionpoolconfig_flatten.go.tmpl'
482+
properties:
483+
- name: 'enabled'
484+
type: Boolean
485+
description: |
486+
Whether to enabled Managed Connection Pool.
487+
required: true
488+
- name: 'poolerCount'
489+
type: Integer
490+
output: true
491+
description: |
492+
The number of running poolers per instance.
493+
- name: 'flags'
494+
type: KeyValuePairs
495+
description: |
496+
Flags for configuring managed connection pooling when it is enabled.
497+
These flags will only be set if `connection_pool_config.enabled` is
498+
true.
499+
Please see
500+
https://cloud.google.com/alloydb/docs/configure-managed-connection-pooling#configuration-options
501+
for a comprehensive list of flags that can be set. To specify the flags
502+
in Terraform, please remove the "connection-pooling-" prefix and use
503+
underscores instead of dashes in the name. For example,
504+
"connection-pooling-pool-mode" would be "pool_mode".
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
{{/*
2+
The license inside this block applies to this file
3+
Copyright 2024 Google Inc.
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
7+
Unless required by applicable law or agreed to in writing, software
8+
distributed under the License is distributed on an "AS IS" BASIS,
9+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
See the License for the specific language governing permissions and
11+
limitations under the License.
12+
*/ -}}
13+
func flatten{{$.GetPrefix}}{{$.TitlelizeProperty}}(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
14+
if v == nil {
15+
return nil
16+
}
17+
original := v.(map[string]interface{})
18+
if len(original) == 0 {
19+
return flattenAlloyDBInstanceEmptyConnectionPoolConfig(v, d, config)
20+
}
21+
transformed := make(map[string]interface{})
22+
transformed["enabled"] =
23+
flattenAlloydbInstanceConnectionPoolConfigEnabled(original["enabled"], d, config)
24+
transformed["pooler_count"] =
25+
flattenAlloydbInstanceConnectionPoolConfigPoolerCount(original["poolerCount"], d, config)
26+
transformed["flags"] =
27+
flattenAlloydbInstanceConnectionPoolConfigFlags(original["flags"], d, config)
28+
return []interface{}{transformed}
29+
}
30+
31+
func flattenAlloyDBInstanceEmptyConnectionPoolConfig(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
32+
// The API returns an nil/empty value for connectionPoolConfig.enabled when
33+
// it's set to false. So keep the user's value to avoid a permadiff.
34+
return []interface{}{
35+
map[string]interface{}{
36+
"enabled": d.Get("connection_pool_config.0.enabled"),
37+
},
38+
}
39+
}
40+
41+
func flattenAlloydbInstanceConnectionPoolConfigEnabled(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
42+
return v
43+
}
44+
45+
func flattenAlloydbInstanceConnectionPoolConfigPoolerCount(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
46+
// Handles the string fixed64 format
47+
if strVal, ok := v.(string); ok {
48+
if intVal, err := tpgresource.StringToFixed64(strVal); err == nil {
49+
return intVal
50+
}
51+
}
52+
53+
// number values are represented as float64
54+
if floatVal, ok := v.(float64); ok {
55+
intVal := int(floatVal)
56+
return intVal
57+
}
58+
59+
return v // let terraform core handle it otherwise
60+
}
61+
62+
func flattenAlloydbInstanceConnectionPoolConfigFlags(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
63+
return v
64+
}

0 commit comments

Comments
 (0)