From a14002ff92cd564b434dee434aef31eefd585a04 Mon Sep 17 00:00:00 2001 From: "PC-2NR0VQ3\\wai.wong" Date: Thu, 14 Nov 2024 09:51:18 +0000 Subject: [PATCH 1/4] fix: allowed ip range description fix for PGD --- pkg/plan_modifier/data_group_custom_diff.go | 24 --------------------- 1 file changed, 24 deletions(-) diff --git a/pkg/plan_modifier/data_group_custom_diff.go b/pkg/plan_modifier/data_group_custom_diff.go index 0df65780..8da0e977 100644 --- a/pkg/plan_modifier/data_group_custom_diff.go +++ b/pkg/plan_modifier/data_group_custom_diff.go @@ -41,30 +41,6 @@ func (m CustomDataGroupDiffModifier) PlanModifyList(ctx context.Context, req pla return } - for _, pDg := range planDgsObs { - // fix to set the correct allowed ip ranges to allow all if a PGD data group has private networking set as true - if pDg.PrivateNetworking != nil && *pDg.PrivateNetworking { - pDg.AllowedIpRanges = types.SetValueMust(pDg.AllowedIpRanges.ElementType(ctx), []attr.Value{ - types.ObjectValueMust( - pDg.AllowedIpRanges.ElementType(ctx).(types.ObjectType).AttributeTypes(), - map[string]attr.Value{ - "cidr_block": types.StringValue("0.0.0.0/0"), - "description": types.StringValue("To allow all access"), - }), - }) - // fix to set the correct allowed ip ranges for PGD data group if allowed ip ranges length is 0 - } else if pDg.AllowedIpRanges.IsNull() || len(pDg.AllowedIpRanges.Elements()) == 0 { - pDg.AllowedIpRanges = types.SetValueMust(pDg.AllowedIpRanges.ElementType(ctx), []attr.Value{ - types.ObjectValueMust( - pDg.AllowedIpRanges.ElementType(ctx).(types.ObjectType).AttributeTypes(), - map[string]attr.Value{ - "cidr_block": types.StringValue("0.0.0.0/0"), - "description": types.StringValue(""), - }), - }) - } - } - mapState := tfsdk.State{Schema: req.Plan.Schema, Raw: req.Plan.Raw} diag = mapState.SetAttribute(ctx, path.Root("data_groups"), planDgsObs) if diag.ErrorsCount() > 0 { From 81f7e1256899c9bc8af2af22a89e1380248aeb3a Mon Sep 17 00:00:00 2001 From: "PC-2NR0VQ3\\wai.wong" Date: Tue, 26 Nov 2024 11:44:19 +0000 Subject: [PATCH 2/4] fix: if allow all ip ranges, force description to be empty for consistency --- pkg/provider/resource_pgd.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/pkg/provider/resource_pgd.go b/pkg/provider/resource_pgd.go index cc1792c7..a100af0a 100644 --- a/pkg/provider/resource_pgd.go +++ b/pkg/provider/resource_pgd.go @@ -1376,14 +1376,21 @@ func buildTFGroupsAs(ctx context.Context, diags *diag.Diagnostics, state tfsdk.S if apiRespDgModel.AllowedIpRanges != nil && len(*apiRespDgModel.AllowedIpRanges) > 0 { for _, v := range *apiRespDgModel.AllowedIpRanges { v := v + + description := v.Description + if v.CidrBlock == "0.0.0.0/0" { + description = "" + } + ob, diag := types.ObjectValue(allwdIpRngsElemTFType.AttrTypes, map[string]attr.Value{ "cidr_block": types.StringValue(v.CidrBlock), - "description": types.StringValue(v.Description), + "description": types.StringValue(description), }) if diag.HasError() { diags.Append(diag...) return } + allowedIpRanges = append(allowedIpRanges, ob) } } From ea27bf0698ad2be91bdcfebb56cc9e062e6934be Mon Sep 17 00:00:00 2001 From: "PC-2NR0VQ3\\wai.wong" Date: Tue, 26 Nov 2024 12:22:22 +0000 Subject: [PATCH 3/4] fix: ip description remove --- pkg/plan_modifier/data_group_custom_diff.go | 23 --------------------- 1 file changed, 23 deletions(-) diff --git a/pkg/plan_modifier/data_group_custom_diff.go b/pkg/plan_modifier/data_group_custom_diff.go index 8da0e977..bd175f31 100644 --- a/pkg/plan_modifier/data_group_custom_diff.go +++ b/pkg/plan_modifier/data_group_custom_diff.go @@ -6,7 +6,6 @@ import ( "reflect" "github.com/EnterpriseDB/terraform-provider-biganimal/pkg/models/pgd/terraform" - "github.com/hashicorp/terraform-plugin-framework/attr" "github.com/hashicorp/terraform-plugin-framework/path" "github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier" "github.com/hashicorp/terraform-plugin-framework/tfsdk" @@ -102,28 +101,6 @@ func (m CustomDataGroupDiffModifier) PlanModifyList(ctx context.Context, req pla pDg.Storage.Iops = sDg.Storage.Iops pDg.Storage.Throughput = sDg.Storage.Throughput - // fix to set the correct allowed ip ranges to allow all if a PGD data group has private networking set as true - if pDg.PrivateNetworking != nil && *pDg.PrivateNetworking { - pDg.AllowedIpRanges = types.SetValueMust(pDg.AllowedIpRanges.ElementType(ctx), []attr.Value{ - types.ObjectValueMust( - pDg.AllowedIpRanges.ElementType(ctx).(types.ObjectType).AttributeTypes(), - map[string]attr.Value{ - "cidr_block": types.StringValue("0.0.0.0/0"), - "description": types.StringValue("To allow all access"), - }), - }) - // fix to set the correct allowed ip ranges for PGD data group if allowed ip ranges length is 0 - } else if pDg.AllowedIpRanges.IsNull() || len(pDg.AllowedIpRanges.Elements()) == 0 { - pDg.AllowedIpRanges = types.SetValueMust(pDg.AllowedIpRanges.ElementType(ctx), []attr.Value{ - types.ObjectValueMust( - pDg.AllowedIpRanges.ElementType(ctx).(types.ObjectType).AttributeTypes(), - map[string]attr.Value{ - "cidr_block": types.StringValue("0.0.0.0/0"), - "description": types.StringValue(""), - }), - }) - } - // if private networking has change then connection string will change if sDg.PrivateNetworking != pDg.PrivateNetworking { pDg.Connection = types.StringUnknown() From 7c3b9860d03fde350a342319900704d12b61add7 Mon Sep 17 00:00:00 2001 From: "PC-2NR0VQ3\\wai.wong" Date: Wed, 27 Nov 2024 19:21:33 +0000 Subject: [PATCH 4/4] fix: code comments and allow ip ranges response description set to "" if cidrblock is 0.0.0.0/0 --- pkg/provider/resource_analytics_cluster.go | 11 ++++++++++- pkg/provider/resource_cluster.go | 11 ++++++++++- pkg/provider/resource_fareplica.go | 11 ++++++++++- pkg/provider/resource_pgd.go | 5 +++++ 4 files changed, 35 insertions(+), 3 deletions(-) diff --git a/pkg/provider/resource_analytics_cluster.go b/pkg/provider/resource_analytics_cluster.go index 51ec7a29..647c1d02 100644 --- a/pkg/provider/resource_analytics_cluster.go +++ b/pkg/provider/resource_analytics_cluster.go @@ -517,9 +517,18 @@ func readAnalyticsCluster(ctx context.Context, client *api.ClusterClient, tfClus tfClusterResource.AllowedIpRanges = []AllowedIpRangesResourceModel{} if allowedIpRanges := responseCluster.AllowedIpRanges; allowedIpRanges != nil { for _, ipRange := range *allowedIpRanges { + description := ipRange.Description + + // if cidr block is 0.0.0.0/0 then set description to empty string + // setting private networking and leaving allowed ip ranges as empty will return + // cidr block as 0.0.0.0/0 and description as "To allow all access" + // so we need to set description to empty string to keep it consistent with the tf resource + if ipRange.CidrBlock == "0.0.0.0/0" { + description = "" + } tfClusterResource.AllowedIpRanges = append(tfClusterResource.AllowedIpRanges, AllowedIpRangesResourceModel{ CidrBlock: ipRange.CidrBlock, - Description: types.StringValue(ipRange.Description), + Description: types.StringValue(description), }) } } diff --git a/pkg/provider/resource_cluster.go b/pkg/provider/resource_cluster.go index 83023578..842bea2e 100644 --- a/pkg/provider/resource_cluster.go +++ b/pkg/provider/resource_cluster.go @@ -909,9 +909,18 @@ func readCluster(ctx context.Context, client *api.ClusterClient, tfClusterResour tfClusterResource.AllowedIpRanges = []AllowedIpRangesResourceModel{} if allowedIpRanges := responseCluster.AllowedIpRanges; allowedIpRanges != nil { for _, ipRange := range *allowedIpRanges { + description := ipRange.Description + + // if cidr block is 0.0.0.0/0 then set description to empty string + // setting private networking and leaving allowed ip ranges as empty will return + // cidr block as 0.0.0.0/0 and description as "To allow all access" + // so we need to set description to empty string to keep it consistent with the tf resource + if ipRange.CidrBlock == "0.0.0.0/0" { + description = "" + } tfClusterResource.AllowedIpRanges = append(tfClusterResource.AllowedIpRanges, AllowedIpRangesResourceModel{ CidrBlock: ipRange.CidrBlock, - Description: types.StringValue(ipRange.Description), + Description: types.StringValue(description), }) } } diff --git a/pkg/provider/resource_fareplica.go b/pkg/provider/resource_fareplica.go index 25012d6b..ee173e49 100644 --- a/pkg/provider/resource_fareplica.go +++ b/pkg/provider/resource_fareplica.go @@ -659,9 +659,18 @@ func readFAReplica(ctx context.Context, client *api.ClusterClient, fAReplicaReso fAReplicaResourceModel.AllowedIpRanges = []AllowedIpRangesResourceModel{} if allowedIpRanges := responseCluster.AllowedIpRanges; allowedIpRanges != nil { for _, ipRange := range *allowedIpRanges { + description := ipRange.Description + + // if cidr block is 0.0.0.0/0 then set description to empty string + // setting private networking and leaving allowed ip ranges as empty will return + // cidr block as 0.0.0.0/0 and description as "To allow all access" + // so we need to set description to empty string to keep it consistent with the tf resource + if ipRange.CidrBlock == "0.0.0.0/0" { + description = "" + } fAReplicaResourceModel.AllowedIpRanges = append(fAReplicaResourceModel.AllowedIpRanges, AllowedIpRangesResourceModel{ CidrBlock: ipRange.CidrBlock, - Description: types.StringValue(ipRange.Description), + Description: types.StringValue(description), }) } } diff --git a/pkg/provider/resource_pgd.go b/pkg/provider/resource_pgd.go index a100af0a..587b0521 100644 --- a/pkg/provider/resource_pgd.go +++ b/pkg/provider/resource_pgd.go @@ -1378,6 +1378,11 @@ func buildTFGroupsAs(ctx context.Context, diags *diag.Diagnostics, state tfsdk.S v := v description := v.Description + + // if cidr block is 0.0.0.0/0 then set description to empty string + // setting private networking and leaving allowed ip ranges as empty will return + // cidr block as 0.0.0.0/0 and description as "To allow all access" + // so we need to set description to empty string to keep it consistent with the tf resource if v.CidrBlock == "0.0.0.0/0" { description = "" }