Skip to content
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

Parameter validation applied during template build #144

Open
ffais opened this issue Jul 19, 2023 · 2 comments
Open

Parameter validation applied during template build #144

ffais opened this issue Jul 19, 2023 · 2 comments

Comments

@ffais
Copy link

ffais commented Jul 19, 2023

Hi there,

Terraform Version

Terraform 1.5.2

Affected Resource(s)

  • coder_parameter

Terraform Configuration Files

data "coder_parameter" "admin_password" {
  name         = "admin_password"
  display_name = "Admin Password"
  description  = "Choose a password for admin account must be at least 8 letters long, must contain at least one number and one letter"
  type         = "string"
  icon         = "/emojis/1f510.png"
  mutable      = false
  validation {
    regex = "[a-z][0-9][a-z0-9]{6,}|[a-z]{2}[0-9][a-z0-9]{5,}|[a-z]{3}[0-9][a-z0-9]{4,}|[a-z]{5}[0-9][a-z0-9]{3,}|[a-z]{6}[0-9][a-z0-9]{2,}|[a-z]{7,}[0-9][a-z0-9]*|[0-9][a-z][a-z0-9]{6,}|[0-9]{2}[a-z][a-z0-9]{5,}|[0-9]{3}[a-z][a-z0-9]{4,}|[0-9]{5}[a-z][a-z0-9]{3,}|[0-9]{6}[a-z][a-z0-9]{2,}|[0-9]{7,}[a-z][a-z0-9]*"
    error = "Invalid password: must be at least 8 letters long, must contain at least one number and one letter"
  }
}

Debug Output

Initializing provider plugins...
- Finding coder/coder versions matching "~> 0.11.0"...
- Finding hashicorp/kubernetes versions matching "~> 2.18"...
- Installing hashicorp/kubernetes v2.22.0...
- Installed hashicorp/kubernetes v2.22.0 (signed by HashiCorp)
- Installing coder/coder v0.11.1...
- Installed coder/coder v0.11.1 (signed by a HashiCorp partner, key ID 93C75807601AA0EC)
Partner and community providers are signed by their developers.
If you'd like to know more about provider signing, you can read about it here:
https://www.terraform.io/docs/cli/plugins/signing.html
Terraform has created a lock file .terraform.lock.hcl to record the provider
selections it made above. Include this file in your version control repository
so that Terraform can guarantee to make the same selections by default when
you run "terraform init" in the future.
Terraform has been successfully initialized!
You may now begin working with Terraform. Try running "terraform plan" to see
any changes that are required for your infrastructure. All Terraform commands
should now work.
If you ever set or change modules or backend configuration for Terraform,
rerun this command to reinitialize your working directory. If you forget, other
commands will detect it and remind you to do so if necessary.
Terraform 1.5.2
data.coder_workspace.me: Refreshing...
data.coder_parameter.admin_password: Refreshing...
data.coder_workspace.me: Refresh complete after 0s [id=3edada7d-297c-4b04-93fb-63081f75dae9]
coder_agent.dremio: Plan to create
coder_app.dremio: Plan to create
kubernetes_persistent_volume_claim.dremio-data: Plan to create
kubernetes_service.dremio-service: Plan to create
coder_metadata.dremio[0]: Plan to create
Plan: 5 to add, 0 to change, 0 to destroy.
Error: Invalid password: must be at least 8 letters long, must contain at least one number and one letter (value "" does not match "[a-z][0-9][a-z0-9]{6,}|[a-z]{2}[0-9][a-z0-9]{5,}|[a-z]{3}[0-9][a-z0-9]{4,}|[a-z]{5}[0-9][a-z0-9]{3,}|[a-z]{6}[0-9][a-z0-9]{2,}|[a-z]{7,}[0-9][a-z0-9]*|[0-9][a-z][a-z0-9]{6,}|[0-9]{2}[a-z][a-z0-9]{5,}|[0-9]{3}[a-z][a-z0-9]{4,}|[0-9]{5}[a-z][a-z0-9]{3,}|[0-9]{6}[a-z][a-z0-9]{2,}|[0-9]{7,}[a-z][a-z0-9]*")
on main.tf line 67, in data "coder_parameter" "admin_password":
  67: data "coder_parameter" "admin_password" {

Expected Behavior

Coder parameter should be validated in the workspace creation phase

Actual Behavior

Coder parameter are validated during the template build phase

Steps to Reproduce

Please list the steps required to reproduce the issue, for example:

  1. add a parameter to a coder template with a validation property and without dafault values.
@matifali
Copy link
Member

@ffais A workaround can be to set a default value that passes validation. You may not wish to have a default value, but it may solve your problem.

@JensHeise
Copy link

Hi there,
we hit this issue too in a slightly different context.

We request a piece of information from our users via a mutable coder_parameter which needs to pass validation.
It can't be known at template compile time and there is no logical default to be set.
For now as workaround we set the default to "" and add a |^$ to the regex in order for the empty string to pass validation.

We would also like to see a "official" solution to this.
Thanks!

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

No branches or pull requests

3 participants