|
| 1 | +terraform { |
| 2 | + required_providers { |
| 3 | + coder = { |
| 4 | + source = "coder/coder" |
| 5 | + version = "2.5.3" |
| 6 | + } |
| 7 | + } |
| 8 | +} |
| 9 | + |
| 10 | +# This example shows new form types and conditionality using dynamic parameters. |
| 11 | +# When starting from scratch, retain the providers block above. |
| 12 | +# |
| 13 | +# In the playground, you can get started with: |
| 14 | +# - snippets for parameter types |
| 15 | +# - example forms for advanced use |
| 16 | +# - documentation for how and when to enable Dynamic Parameters. |
| 17 | +# |
| 18 | +# You can edit user data in the "users" tab, and share your form via URL. |
| 19 | +# Enjoy Dynamic Parameters! |
| 20 | + |
| 21 | +locals { |
| 22 | + ides = [ |
| 23 | + { |
| 24 | + name = "VSCode", |
| 25 | + value = "vscode", |
| 26 | + icon = "/icon/code.svg" |
| 27 | + }, |
| 28 | + { |
| 29 | + name = "Jetbrains IntelliJ", |
| 30 | + value = "intellij", |
| 31 | + icon = "/icon/intellij.svg" |
| 32 | + }, |
| 33 | + { |
| 34 | + name = "Cursor", |
| 35 | + value = "cursor", |
| 36 | + icon = "/icon/cursor.svg" |
| 37 | + }, |
| 38 | + ] |
| 39 | + |
| 40 | + username = data.coder_workspace_owner.me.name |
| 41 | + is_admin = contains(data.coder_workspace_owner.me.groups, "admin") |
| 42 | +} |
| 43 | + |
| 44 | +data "coder_workspace_owner" "me" {} |
| 45 | + |
| 46 | +data "coder_parameter" "dropdown_picker" { |
| 47 | + name = "dropdown_picker" |
| 48 | + display_name = "Pick your next parameter!" |
| 49 | + description = "Hello ${username}, pick your next parameter using this `dropdown` parameter." |
| 50 | + form_type = "dropdown" |
| 51 | + mutable = true |
| 52 | + |
| 53 | + option { |
| 54 | + value = "ide_picker" |
| 55 | + name = "IDE multi-select" |
| 56 | + } |
| 57 | + |
| 58 | + option { |
| 59 | + value = "text_area" |
| 60 | + name = "Large text entry" |
| 61 | + } |
| 62 | + |
| 63 | + option { |
| 64 | + value = "cpu_slider" |
| 65 | + name = "CPU slider" |
| 66 | + } |
| 67 | +} |
| 68 | + |
| 69 | +data "coder_parameter" "ide_picker" { |
| 70 | + count = try(data.coder_parameter.dropdown_picker.value, "") == "ide_picker" ? 1 : 0 |
| 71 | + |
| 72 | + name = "ide_picker" |
| 73 | + display_name = "Pick your IDEs!" |
| 74 | + description = "This is created using the `form_type = 'multi-select'` option." |
| 75 | + |
| 76 | + type = "list(string)" |
| 77 | + form_type = "multi-select" |
| 78 | + order = 2 |
| 79 | + mutable = true |
| 80 | + |
| 81 | + dynamic "option" { |
| 82 | + for_each = local.ides |
| 83 | + content { |
| 84 | + name = option.value.name |
| 85 | + value = option.value.value |
| 86 | + description = option.value.description |
| 87 | + icon = option.value.icon |
| 88 | + } |
| 89 | + } |
| 90 | +} |
| 91 | + |
| 92 | +data "coder_parameter" "text_area" { |
| 93 | + count = try(data.coder_parameter.dropdown_picker.value, "") == "text_area" ? 1 : 0 |
| 94 | + |
| 95 | + name = "text_area" |
| 96 | + display_name = "Enter a large AI prompt or script!" |
| 97 | + description = "This is created using the `form_type = 'textarea'` option." |
| 98 | + |
| 99 | + type = "string" |
| 100 | + form_type = "textarea" |
| 101 | + order = 2 |
| 102 | + mutable = true |
| 103 | + |
| 104 | + styling = jsonencode({ |
| 105 | + placeholder = <<-EOT |
| 106 | + This is a large text entry, try it out! |
| 107 | + |
| 108 | + Including support for multi-line text entry. |
| 109 | + EOT |
| 110 | + }) |
| 111 | +} |
| 112 | + |
| 113 | +data "coder_parameter" "cpu_slider" { |
| 114 | + count = try(data.coder_parameter.dropdown_picker.value, "") == "cpu_slider" ? 1 : 0 |
| 115 | + name = "cpu_slider" |
| 116 | + display_name = "CPU Cores Slider" |
| 117 | + description = "This is created using the `form_type = 'slider'` option." |
| 118 | + |
| 119 | + type = "number" |
| 120 | + form_type = "slider" |
| 121 | + order = 2 |
| 122 | + default = 4 |
| 123 | + mutable = true |
| 124 | + |
| 125 | + validation { |
| 126 | + min = 2 |
| 127 | + max = 8 |
| 128 | + } |
| 129 | +} |
| 130 | + |
| 131 | +data "coder_parameter" "admin_only" { |
| 132 | + count = local.is_admin ? 1 : 0 |
| 133 | + |
| 134 | + name = "admin_only" |
| 135 | + display_name = "Use imaginary experimental features?" |
| 136 | + description = "This option is only available to those in the 'admin' group. You can hide it by changing your user data. \n\n _This does not actually enable experimental features._" |
| 137 | + |
| 138 | + type = "bool" |
| 139 | + form_type = "checkbox" |
| 140 | + default = false |
| 141 | + |
| 142 | + order = 5 |
| 143 | +} |
0 commit comments