Skip to content

feat: allow number options with monotonic validation #12726

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

Merged
merged 8 commits into from
Mar 27, 2024
Next Next commit
Minor refactorings, corrections
Signed-off-by: Danny Kopping <danny@coder.com>
  • Loading branch information
dannykopping committed Mar 22, 2024
commit 6952dfd14116b7462dda082ae252df2ce1131d9e
4 changes: 2 additions & 2 deletions codersdk/richparameters_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,13 +201,13 @@ func TestRichParameterValidation(t *testing.T) {

monotonicIncreasingNumberRichParameters := []codersdk.TemplateVersionParameter{
{Name: stringParameterName, Type: "string", Mutable: true},
{Name: numberParameterName, Type: "number", Mutable: true, ValidationMin: ptr.Ref(int32(3)), ValidationMax: ptr.Ref(int32(100)), ValidationMonotonic: "increasing"},
{Name: numberParameterName, Type: "number", Mutable: true, ValidationMin: ptr.Ref(int32(3)), ValidationMax: ptr.Ref(int32(100)), ValidationMonotonic: codersdk.MonotonicOrderIncreasing},
{Name: boolParameterName, Type: "bool", Mutable: true},
}

monotonicDecreasingNumberRichParameters := []codersdk.TemplateVersionParameter{
{Name: stringParameterName, Type: "string", Mutable: true},
{Name: numberParameterName, Type: "number", Mutable: true, ValidationMin: ptr.Ref(int32(3)), ValidationMax: ptr.Ref(int32(100)), ValidationMonotonic: "decreasing"},
{Name: numberParameterName, Type: "number", Mutable: true, ValidationMin: ptr.Ref(int32(3)), ValidationMax: ptr.Ref(int32(100)), ValidationMonotonic: codersdk.MonotonicOrderDecreasing},
{Name: boolParameterName, Type: "bool", Mutable: true},
}

Expand Down
5 changes: 3 additions & 2 deletions codersdk/templateversions.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"net/http"
"time"

"github.com/coder/terraform-provider-coder/provider"
"github.com/google/uuid"
)

Expand Down Expand Up @@ -47,8 +48,8 @@ type TemplateVersionExternalAuth struct {
type ValidationMonotonicOrder string

const (
MonotonicOrderIncreasing ValidationMonotonicOrder = "increasing"
MonotonicOrderDecreasing ValidationMonotonicOrder = "decreasing"
MonotonicOrderIncreasing ValidationMonotonicOrder = provider.ValidationMonotonicIncreasing
MonotonicOrderDecreasing ValidationMonotonicOrder = provider.ValidationMonotonicDecreasing
)

// TemplateVersionParameter represents a parameter for a template version.
Expand Down
2 changes: 1 addition & 1 deletion docs/templates/parameters.md
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ monotonic numbers, and regular expressions.
You can limit a `number` parameter to `min` and `max` boundaries.

You can also specify its monotonicity as `increasing` or `decreasing` to verify
the current and new values. Use the `monotonic` aatribute for resources that
the current and new values. Use the `monotonic` attribute for resources that
can't be shrunk or grown without implications, like disk volume size.

```hcl
Expand Down