Skip to content

Commit 66971a0

Browse files
Edit Cluster fix for Connection Pooling (#131)
1 parent d25af38 commit 66971a0

File tree

2 files changed

+18
-9
lines changed

2 files changed

+18
-9
lines changed

managed/fflags/feature_flags.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,14 @@ const (
1616
GOOGLECLOUD_INTEGRATION_ENABLED FeatureFlag = "GOOGLECLOUD_INTEGRATION_ENABLED"
1717
DB_AUDIT_LOGGING FeatureFlag = "DB_AUDIT_LOGGING"
1818
DB_QUERY_LOGGING FeatureFlag = "DB_QUERY_LOGGING"
19+
CONNECTION_POOLING FeatureFlag = "CONNECTION_POOLING"
1920
)
2021

2122
var flagEnabled = map[FeatureFlag]bool{
2223
GOOGLECLOUD_INTEGRATION_ENABLED: false,
2324
DB_AUDIT_LOGGING: false,
2425
DB_QUERY_LOGGING: false,
26+
CONNECTION_POOLING: false,
2527
}
2628

2729
func (f FeatureFlag) String() string {

managed/resource_cluster.go

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
"github.com/hashicorp/terraform-plugin-framework/types"
2626
"github.com/hashicorp/terraform-plugin-log/tflog"
2727
retry "github.com/sethvargo/go-retry"
28+
"github.com/yugabyte/terraform-provider-ybm/managed/fflags"
2829
"github.com/yugabyte/terraform-provider-ybm/managed/util"
2930
openapiclient "github.com/yugabyte/yugabytedb-managed-go-client-internal"
3031
)
@@ -1271,7 +1272,7 @@ func (r resourceCluster) Create(ctx context.Context, req tfsdk.CreateResourceReq
12711272
cluster.DesiredState.Value = plan.DesiredState.Value
12721273
}
12731274

1274-
if strings.EqualFold(plan.DesiredConnectionPoolingState.Value, "Enabled") || strings.EqualFold(plan.DesiredConnectionPoolingState.Value, "Disabled") {
1275+
if fflags.IsFeatureFlagEnabled(fflags.CONNECTION_POOLING) && (strings.EqualFold(plan.DesiredConnectionPoolingState.Value, "Enabled") || strings.EqualFold(plan.DesiredConnectionPoolingState.Value, "Disabled")) {
12751276
cluster.DesiredConnectionPoolingState.Value = plan.DesiredConnectionPoolingState.Value
12761277
}
12771278

@@ -1709,11 +1710,14 @@ func resourceClusterRead(ctx context.Context, accountId string, projectId string
17091710
cluster.ClusterID.Value = clusterId
17101711
cluster.ClusterName.Value = clusterResp.Data.Spec.Name
17111712
cluster.DesiredState.Value = string(clusterResp.Data.Info.GetState())
1712-
if clusterResp.Data.Info.GetIsConnectionPoolingEnabled() {
1713-
cluster.DesiredConnectionPoolingState.Value = "Enabled"
1714-
} else {
1715-
cluster.DesiredConnectionPoolingState.Value = "Disabled"
1713+
if fflags.IsFeatureFlagEnabled(fflags.CONNECTION_POOLING) {
1714+
if clusterResp.Data.Info.GetIsConnectionPoolingEnabled() {
1715+
cluster.DesiredConnectionPoolingState.Value = "Enabled"
1716+
} else {
1717+
cluster.DesiredConnectionPoolingState.Value = "Disabled"
1718+
}
17161719
}
1720+
17171721
cluster.ClusterType.Value = string(*clusterResp.Data.Spec.ClusterInfo.ClusterType)
17181722
cluster.ClusterTier.Value = string(clusterResp.Data.Spec.ClusterInfo.ClusterTier)
17191723
cluster.ClusterVersion.Value = strconv.Itoa(int(clusterResp.Data.Spec.ClusterInfo.GetVersion()))
@@ -1953,9 +1957,12 @@ func (r resourceCluster) Update(ctx context.Context, req tfsdk.UpdateResourceReq
19531957
}
19541958
}
19551959

1956-
// Disable Connection Pooling if the desired state is set to 'Disabled and it is enabeld currently
1957-
if plan.DesiredConnectionPoolingState.Unknown || strings.EqualFold(plan.DesiredConnectionPoolingState.Value, "Disabled") {
1960+
tflog.Info(ctx, fmt.Sprintf("Existing Desired Connection Pooling State in State is %v", state.DesiredConnectionPoolingState.Value))
1961+
1962+
// Disable Connection Pooling if the desired state is set to 'Disabled' and it is enabled currently
1963+
if fflags.IsFeatureFlagEnabled(fflags.CONNECTION_POOLING) && !state.DesiredConnectionPoolingState.Unknown && strings.EqualFold(state.DesiredConnectionPoolingState.Value, "Enabled") && (plan.DesiredConnectionPoolingState.Unknown || strings.EqualFold(plan.DesiredConnectionPoolingState.Value, "Disabled")) {
19581964
// Disable Connection Pooling
1965+
tflog.Info(ctx, fmt.Sprintf("Existing Desired Connection Pooling State in State is %v", state.DesiredConnectionPoolingState.Value))
19591966
err := disableConnectionPooling(ctx, apiClient, accountId, projectId, clusterId)
19601967
if err != nil {
19611968
resp.Diagnostics.AddError("Disable connection pooling failed: ", err.Error())
@@ -2199,7 +2206,7 @@ func (r resourceCluster) Update(ctx context.Context, req tfsdk.UpdateResourceReq
21992206
}
22002207

22012208
// Enable connection pooling if the desired state is set to 'Enabled'
2202-
if !plan.DesiredConnectionPoolingState.Unknown && strings.EqualFold(plan.DesiredConnectionPoolingState.Value, "Enabled") {
2209+
if fflags.IsFeatureFlagEnabled(fflags.CONNECTION_POOLING) && !plan.DesiredConnectionPoolingState.Unknown && strings.EqualFold(plan.DesiredConnectionPoolingState.Value, "Enabled") {
22032210
err := enableConnectionPooling(ctx, apiClient, accountId, projectId, clusterId)
22042211
if err != nil {
22052212
resp.Diagnostics.AddError("Enabling connection pooling Failed: ", err.Error())
@@ -2248,7 +2255,7 @@ func (r resourceCluster) Update(ctx context.Context, req tfsdk.UpdateResourceReq
22482255
cluster.DesiredState.Value = plan.DesiredState.Value
22492256
}
22502257

2251-
if strings.EqualFold(plan.DesiredConnectionPoolingState.Value, "Enabled") || strings.EqualFold(plan.DesiredConnectionPoolingState.Value, "Enabled") {
2258+
if fflags.IsFeatureFlagEnabled(fflags.CONNECTION_POOLING) && (strings.EqualFold(plan.DesiredConnectionPoolingState.Value, "Enabled") || strings.EqualFold(plan.DesiredConnectionPoolingState.Value, "Enabled")) {
22522259
cluster.DesiredConnectionPoolingState.Value = plan.DesiredConnectionPoolingState.Value
22532260
}
22542261

0 commit comments

Comments
 (0)