diff --git a/.changelog/5.txt b/.changelog/5.txt new file mode 100644 index 0000000..b966ea7 --- /dev/null +++ b/.changelog/5.txt @@ -0,0 +1,3 @@ +```release-note:feature +Added `SizeAtLeast()`, `SizeAtMost()` and `SizeBetween` validation functions to `setvalidator` package +``` \ No newline at end of file diff --git a/setvalidator/size_at_least.go b/setvalidator/size_at_least.go index e9a12cd..c3d99e3 100644 --- a/setvalidator/size_at_least.go +++ b/setvalidator/size_at_least.go @@ -44,6 +44,13 @@ func (v sizeAtLeastValidator) Validate(ctx context.Context, req tfsdk.ValidateAt } } +// SizeAtLeast returns an AttributeValidator which ensures that any configured +// attribute value: +// +// - Is a Set. +// - Contains at least min elements. +// +// Null (unconfigured) and unknown (known after apply) values are skipped. func SizeAtLeast(min int) tfsdk.AttributeValidator { return sizeAtLeastValidator{ min: min, diff --git a/setvalidator/size_at_most.go b/setvalidator/size_at_most.go index 41d6321..8fe1cc9 100644 --- a/setvalidator/size_at_most.go +++ b/setvalidator/size_at_most.go @@ -44,6 +44,13 @@ func (v sizeAtMostValidator) Validate(ctx context.Context, req tfsdk.ValidateAtt } } +// SizeAtMost returns an AttributeValidator which ensures that any configured +// attribute value: +// +// - Is a Set. +// - Contains at most max elements. +// +// Null (unconfigured) and unknown (known after apply) values are skipped. func SizeAtMost(max int) tfsdk.AttributeValidator { return sizeAtMostValidator{ max: max, diff --git a/setvalidator/size_between.go b/setvalidator/size_between.go index fc726ac..894d327 100644 --- a/setvalidator/size_between.go +++ b/setvalidator/size_between.go @@ -46,6 +46,13 @@ func (v sizeBetweenValidator) Validate(ctx context.Context, req tfsdk.ValidateAt } } +// SizeBetween returns an AttributeValidator which ensures that any configured +// attribute value: +// +// - Is a Set. +// - Contains at least min elements and at most max elements. +// +// Null (unconfigured) and unknown (known after apply) values are skipped. func SizeBetween(min, max int) tfsdk.AttributeValidator { return sizeBetweenValidator{ min: min,