Skip to content

Commit d0769d8

Browse files
committed
added secret parameters
1 parent 0423ea0 commit d0769d8

File tree

1 file changed

+108
-7
lines changed

1 file changed

+108
-7
lines changed

docs/admin/templates/extending-templates/dynamic-parameters.md

Lines changed: 108 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -104,13 +104,13 @@ The "Options" column in the table below indicates whether the form type requires
104104

105105
### New Form Types
106106

107-
The following examples show some basic usage of the sing the [`form_type`](https://registry.terraform.io/providers/coder/coder/latest/docs/data-sources/parameter#form_type-1) attribute explained above.
107+
The following examples show some basic usage of the [`form_type`](https://registry.terraform.io/providers/coder/coder/latest/docs/data-sources/parameter#form_type-1) attribute explained above. These are used to change the input style of form controls in the create workspace form.
108108

109109
<div class="tabs">
110110

111111
### Dropdowns
112112

113-
All single-select parameters with options may now use the `form_type=\"dropdown\"` attribute for better organization.
113+
Single-select parameters with options may now use the `form_type=\"dropdown\"` attribute for better organization.
114114

115115
[Try dropdown lists on the Parameter Playground](https://playground.coder.app/parameters/kgNBpjnz7x)
116116

@@ -284,6 +284,30 @@ data "coder_parameter" "cpu_cores" {
284284
}
285285
```
286286

287+
<!-- ### Secrets
288+
289+
Sliders can be used for configuration on a linear scale, like resource allocation. The `validation` block is used to clamp the minimum and maximum values for the parameter.
290+
291+
[Try secret parameters on the Parameters Playground](https://playground.coder.app/parameters/wmiP7FM3Za).
292+
293+
```terraform
294+
data "coder_parameter" "private_api_key" {
295+
name = "private_api_key"
296+
display_name = "Your super secret API key"
297+
type = "string"
298+
299+
form_type = "input" # | "textarea"
300+
301+
# Will render as "**********"
302+
default = "privatekey"
303+
304+
styling = jsonencode({
305+
maskInput = true
306+
})
307+
}
308+
``` -->
309+
310+
287311
</div>
288312

289313
### Conditional Parameters
@@ -315,7 +339,6 @@ data "coder_parameter" "show_cpu_cores" {
315339
order = 1
316340
}
317341
318-
319342
data "coder_parameter" "cpu_cores" {
320343
# Only show this parameter if the previous box is selected.
321344
count = data.coder_parameter.show_cpu_cores.value ? 1 : 0
@@ -337,9 +360,20 @@ data "coder_parameter" "cpu_cores" {
337360

338361
For a given parameter, we can influence which option is selected by default based on the selection of another. This allows us to suggest an option dynamically without strict enforcement.
339362

340-
[Try dynamic defaults in the Parameter Playground](https://playground.coder.app/parameters/Ilko59tf89).
363+
[Try dynamic defaults in the Parameter Playground](https://playground.coder.app/parameters/DEi-Bi6DVe).
341364

342365
```terraform
366+
locals {
367+
ides = [
368+
"VS Code",
369+
"IntelliJ", "GoLand",
370+
"WebStorm", "PyCharm",
371+
"Databricks", "Jupyter Notebook",
372+
]
373+
mlkit_ides = jsonencode(["Databricks", "PyCharm"])
374+
core_ides = jsonencode(["VS Code", "GoLand"])
375+
}
376+
343377
data "coder_parameter" "git_repo" {
344378
name = "git_repo"
345379
display_name = "Git repo"
@@ -374,7 +408,7 @@ data "coder_parameter" "ide_selector" {
374408
display_name = "Select IDEs"
375409
form_type = "multi-select"
376410
type = "list(string)"
377-
default = try(data.coder_parameter.git_repo.value, "") == "coder/mlkit" ? jsonencode(["Databricks", "PyCharm"]) : jsonencode(["VS Code", "GoLand"])
411+
default = try(data.coder_parameter.git_repo.value, "") == "coder/mlkit" ? local.mlkit_ides : local.core_ides
378412
379413
380414
dynamic "option" {
@@ -393,7 +427,6 @@ Parameters' validation block can also leverage inputs from other parameters.
393427

394428
[Try dynamic validation in the Parameter Playground](https://playground.coder.app/parameters/sdbzXxagJ4).
395429

396-
397430
```terraform
398431
data "coder_parameter" "git_repo" {
399432
name = "git_repo"
@@ -441,8 +474,76 @@ data "coder_parameter" "cpu_cores" {
441474

442475
## Daisy Chaining
443476

444-
```
477+
You can daisy-chain the conditionals shown here to create a dynamically expanding form. Note that parameters must be indexed when using the `count` attribute.
478+
479+
```terraform
480+
481+
data "coder_parameter" "git_repo" {
482+
name = "git_repo"
483+
display_name = "Git repo"
484+
description = "Select a git repo to work on."
485+
order = 1
486+
mutable = true
487+
type = "string"
488+
form_type = "dropdown"
489+
490+
option {
491+
# A Go-heavy repository
492+
name = "coder/coder"
493+
value = "coder/coder"
494+
}
495+
496+
option {
497+
# A python-heavy repository
498+
name = "coder/mlkit"
499+
value = "coder/mlkit"
500+
}
501+
}
502+
503+
data "coder_parameter" "ide_selector" {
504+
# Conditionally expose this parameter
505+
count = try(data.coder_parameter.git_repo.value, "") != "" ? 1 : 0
506+
507+
name = "ide_selector"
508+
description = "Choose any IDEs for your workspace."
509+
order = 2
510+
mutable = true
511+
512+
display_name = "Select IDEs"
513+
form_type = "multi-select"
514+
type = "list(string)"
515+
default = try(data.coder_parameter.git_repo.value, "") == "coder/mlkit" ? local.mlkit_ides : local.core_ides
516+
517+
518+
dynamic "option" {
519+
for_each = local.ides
520+
content {
521+
name = option.value
522+
value = option.value
523+
}
524+
}
525+
}
526+
527+
data "coder_parameter" "region" {
528+
# Only show this parameter if any IDEs are selected.
529+
count = try(data.coder_parameter.ide_selector.value,) ? 1 : 0
530+
531+
name = "region"
532+
display_name = "Select a Region"
533+
type = "number"
534+
form_type = "slider"
535+
order = 2
445536
537+
# Dynamically set default
538+
default = try(data.coder_parameter.git_repo.value, "") == "coder/mlkit" ? 12 : 6
539+
540+
validation {
541+
min = 1
542+
543+
# Dynamically set max validation
544+
max = try(data.coder_parameter.git_repo.value, "") == "coder/mlkit" ? 16 : 8
545+
}
546+
}
446547
447548
```
448549

0 commit comments

Comments
 (0)