Skip to content

coder_parameter doesn't support monotonic for option values #11579

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

Closed
mattlqx opened this issue Jan 11, 2024 · 4 comments · Fixed by #12726
Closed

coder_parameter doesn't support monotonic for option values #11579

mattlqx opened this issue Jan 11, 2024 · 4 comments · Fixed by #12726
Assignees

Comments

@mattlqx
Copy link

mattlqx commented Jan 11, 2024

Would it be possible to support monotonic validation on parameters that use options that have numeric values?

I have a 3 volume size options on my template. Sizes can't be effectively reduced. It would be nice if the setting could be validated so that selecting a smaller one than current would fail validation. e.g.

data "coder_parameter" "home_volume_size" {
  name        = "Home Volume Size"
  description = <<-EOF
  How large should your home volume be?
  EOF
  default     = "300"
  mutable     = true
  order       = 3

  option {
    name  = "300 GB (Default)"
    value = "300"
  }

  option {
    name  = "600 GB"
    value = "600"
  }

  option {
    name  = "1 TB"
    value = "1000"
  }
}

I would like it to also support the block:

validation {
  monotonic = "increasing"
}
@cdr-bot cdr-bot bot added the feature label Jan 11, 2024
@matifali
Copy link
Member

matifali commented Jan 12, 2024

Hi @mattlqx do you have any issues while setting it. O think it should work of you also set the type = "number".
Or you need string values you can later use the tostring() function where you use this parameter.

@mtojek don't we support options for the type = "number"? I see that the type for both name and value is required to be string in the provider.

@mattlqx
Copy link
Author

mattlqx commented Jan 12, 2024

The problem seems to be actually that options don't support validation.

2024-01-12 20:47:07.520Z Error: Conflicting configuration arguments
2024-01-12 20:47:07.520Z on params.tf line 77, in data "coder_parameter" "home_volume_size":
2024-01-12 20:47:07.520Z   77: data "coder_parameter" "home_volume_size" {
2024-01-12 20:47:07.520Z 
2024-01-12 20:47:07.520Z "validation": conflicts with option

That's with the following attributes:

  default     = "300"
  mutable     = true
  type        = "number"

  option {
    name  = "300 GB (Default)"
    value = "300"
  }

  option {
    name  = "600 GB"
    value = "600"
  }

  option {
    name  = "1 TB"
    value = "1000"
  }

  validation {
    monotonic = "increasing"
  }

@matifali
Copy link
Member

We should definitely support monotonic type validation for options with type number.

cc: @coder/pms @mtojek

@mtojek
Copy link
Member

mtojek commented Jan 15, 2024

I second what Matt said about the problem.

Coder enables validation for number fields, but since there are options provided, it assumes that it does not need advanced validation. Hence there is a type conflict. It is aligned with the initial design of Coder parameters which assumed that parameter options are only strings.

This issue is kind of a whack-a-mole challenge. Fix all places, hopefully only in Coder, until it works correctly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants