From 91e3957fe7c26957158f904dc458d2a54b5125c5 Mon Sep 17 00:00:00 2001 From: Priyanshu Krishnan <118425422+Krishnan-Priyanshu@users.noreply.github.com> Date: Thu, 21 Nov 2024 12:27:30 +0530 Subject: [PATCH] added validation for network pool/rule ds (#262) Co-authored-by: Akash Shendge <60608990+shenda1@users.noreply.github.com> --- powerscale/helper/network_pool_helper.go | 3 +++ powerscale/provider/network_pool_datasource.go | 18 ++++++++++++++++++ powerscale/provider/network_rule_datasource.go | 15 +++++++++++++++ 3 files changed, 36 insertions(+) diff --git a/powerscale/helper/network_pool_helper.go b/powerscale/helper/network_pool_helper.go index fd99d52..7205d7c 100644 --- a/powerscale/helper/network_pool_helper.go +++ b/powerscale/helper/network_pool_helper.go @@ -42,6 +42,9 @@ func GetNetworkPools(ctx context.Context, client *client.Client, state models.Ne } networkPools, _, err := networkPoolParams.Execute() + if err != nil { + return nil, err + } //pagination for networkPools.Resume != nil && state.NetworkPoolFilter != nil { networkPoolParams = networkPoolParams.Resume(*networkPools.Resume) diff --git a/powerscale/provider/network_pool_datasource.go b/powerscale/provider/network_pool_datasource.go index 965fbec..83dfccf 100644 --- a/powerscale/provider/network_pool_datasource.go +++ b/powerscale/provider/network_pool_datasource.go @@ -26,8 +26,11 @@ import ( "terraform-provider-powerscale/powerscale/helper" "terraform-provider-powerscale/powerscale/models" + "github.com/hashicorp/terraform-plugin-framework-validators/setvalidator" + "github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator" "github.com/hashicorp/terraform-plugin-framework/datasource" "github.com/hashicorp/terraform-plugin-framework/datasource/schema" + "github.com/hashicorp/terraform-plugin-framework/schema/validator" "github.com/hashicorp/terraform-plugin-framework/types" "github.com/hashicorp/terraform-plugin-log/tflog" ) @@ -245,26 +248,41 @@ func (d *NetworkPoolDataSource) Schema(ctx context.Context, req datasource.Schem MarkdownDescription: "Filter network pools by names.", Optional: true, ElementType: types.StringType, + Validators: []validator.Set{ + setvalidator.SizeAtLeast(1), + }, }, "subnet": schema.StringAttribute{ Description: "If specified, only pools for this subnet will be returned.", MarkdownDescription: "If specified, only pools for this subnet will be returned.", Optional: true, + Validators: []validator.String{ + stringvalidator.LengthAtLeast(1), + }, }, "groupnet": schema.StringAttribute{ Description: "If specified, only pools for this groupnet will be returned.", MarkdownDescription: "If specified, only pools for this groupnet will be returned.", Optional: true, + Validators: []validator.String{ + stringvalidator.LengthAtLeast(1), + }, }, "access_zone": schema.StringAttribute{ Description: "If specified, only pools with this zone name will be returned.", MarkdownDescription: "If specified, only pools with this zone name will be returned.", Optional: true, + Validators: []validator.String{ + stringvalidator.LengthAtLeast(1), + }, }, "alloc_method": schema.StringAttribute{ Description: "If specified, only pools with this allocation type will be returned.", MarkdownDescription: "If specified, only pools with this allocation type will be returned.", Optional: true, + Validators: []validator.String{ + stringvalidator.LengthAtLeast(1), + }, }, }, }, diff --git a/powerscale/provider/network_rule_datasource.go b/powerscale/provider/network_rule_datasource.go index 4aedea6..85a9a47 100644 --- a/powerscale/provider/network_rule_datasource.go +++ b/powerscale/provider/network_rule_datasource.go @@ -25,8 +25,11 @@ import ( "terraform-provider-powerscale/powerscale/helper" "terraform-provider-powerscale/powerscale/models" + "github.com/hashicorp/terraform-plugin-framework-validators/setvalidator" + "github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator" "github.com/hashicorp/terraform-plugin-framework/datasource" "github.com/hashicorp/terraform-plugin-framework/datasource/schema" + "github.com/hashicorp/terraform-plugin-framework/schema/validator" "github.com/hashicorp/terraform-plugin-framework/types" "github.com/hashicorp/terraform-plugin-log/tflog" ) @@ -119,21 +122,33 @@ func (d *NetworkRuleDataSource) Schema(ctx context.Context, req datasource.Schem MarkdownDescription: "Filter network rules by names.", Optional: true, ElementType: types.StringType, + Validators: []validator.Set{ + setvalidator.SizeAtLeast(1), + }, }, "groupnet": schema.StringAttribute{ Description: "If specified, only rules for this groupnet will be returned.", MarkdownDescription: "If specified, only rules for this groupnet will be returned.", Optional: true, + Validators: []validator.String{ + stringvalidator.LengthAtLeast(1), + }, }, "subnet": schema.StringAttribute{ Description: "If specified, only rules for this subnet will be returned.", MarkdownDescription: "If specified, only rules for this subnet will be returned.", Optional: true, + Validators: []validator.String{ + stringvalidator.LengthAtLeast(1), + }, }, "pool": schema.StringAttribute{ Description: "If specified, only rules for this pool will be returned.", MarkdownDescription: "If specified, only rules for this pool will be returned.", Optional: true, + Validators: []validator.String{ + stringvalidator.LengthAtLeast(1), + }, }, }, },