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