Skip to content

Commit

Permalink
added validation for network pool/rule ds (#262)
Browse files Browse the repository at this point in the history
Co-authored-by: Akash Shendge <60608990+shenda1@users.noreply.github.com>
  • Loading branch information
Krishnan-Priyanshu and shenda1 authored Nov 21, 2024
1 parent cd5bba7 commit 91e3957
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
3 changes: 3 additions & 0 deletions powerscale/helper/network_pool_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
18 changes: 18 additions & 0 deletions powerscale/provider/network_pool_datasource.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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),
},
},
},
},
Expand Down
15 changes: 15 additions & 0 deletions powerscale/provider/network_rule_datasource.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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),
},
},
},
},
Expand Down

0 comments on commit 91e3957

Please sign in to comment.