Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: allowed ip range description fix for PGD #610

Merged
merged 5 commits into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 0 additions & 47 deletions pkg/plan_modifier/data_group_custom_diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"strings"

"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"
Expand Down Expand Up @@ -80,30 +79,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 {
Expand Down Expand Up @@ -156,28 +131,6 @@ func (m CustomDataGroupDiffModifier) PlanModifyList(ctx context.Context, req pla
pDg.WalStorage.Throughput = sDg.WalStorage.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()
Expand Down
11 changes: 10 additions & 1 deletion pkg/provider/resource_analytics_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -518,9 +518,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),
})
}
}
Expand Down
11 changes: 10 additions & 1 deletion pkg/provider/resource_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -919,9 +919,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),
})
}
}
Expand Down
11 changes: 10 additions & 1 deletion pkg/provider/resource_fareplica.go
Original file line number Diff line number Diff line change
Expand Up @@ -668,9 +668,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),
})
}
}
Expand Down
14 changes: 13 additions & 1 deletion pkg/provider/resource_pgd.go
Original file line number Diff line number Diff line change
Expand Up @@ -1400,14 +1400,26 @@ 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 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 = ""
}

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)
}
}
Expand Down