Parameter validation

We are trying to use parameter validation with a "coder_param" that has no default value. We use the cli tool to push the template in our gitlab ci. Unfortunately this seems to be impossible as the cli runs terraform plan which fails due to an empty parameter. Has anybody found a solution to this? Am I missing something obvious?
10 Replies
Codercord
Codercord2w ago
<#1328695129455853568>
Category
Help needed
Product
Coder (v2)
Platform
Linux
Logs
Please post any relevant logs/error messages.
Phorcys
Phorcys2w ago
hey @jozef, could you send your template over and describe what you're trying to achieve with an empty coder_parameter?
jozef
jozefOP2w ago
essentially, I have a git repo param that I do not want to have a default for as it is mandatory for the template, and setting a default means that the param is shown as optional in the control plane UI. I want to have validation to ensure that users use an https git repo URI rather than an SSH git repo URI. I'll see if I can send over the template, just need to check it for company related things
jozef
jozefOP2w ago
Hopefully this explains things a bit
Phorcys
Phorcys2w ago
oh okay I got it! yeah so I've never managed to get regexes working myself for URLs, it should be possible but I think Terraform uses a weird regex engine yeah, it uses RE2 i'll look into it in a bit, what error are you running into?
jozef
jozefOP2w ago
We use the coder cli tool to push templates from gitlab ci and here the tool always runs terraform plan, at this point the param is empty therefore plan fails and the template is not pushed. As I type this though, it occurs to me that I shuld be able to pass a var to the pipeline in order to fill this during the plan phase Sadly, it seems that this is simply not doable, at least from my testing I haven't figured it out
Phorcys
Phorcys2w ago
yeah i've struggled with this in the past as well @Atif do you have an idea?
Phorcys
Phorcys2w ago
maybe instead of using the coder_parameter's validation you could use Custom Conditions
Custom Conditions - Configuration Language | Terraform | HashiCorp Developer
Custom Conditions - Configuration Language | Terraform | HashiCorp ...
Check custom requirements for variables, outputs, data sources, and resources and provide better error messages in context.
jozef
jozefOP3d ago
But how would I tie that to the UI? doesn't seem feasible
Phorcys
Phorcys3d ago
you are right, it would likely fail afterwards

Did you find this page helpful?