@@ -39,28 +39,22 @@ variable "folder" {
39
39
}
40
40
41
41
variable "default" {
42
- default = " "
43
- type = string
44
- description = " Default IDE"
45
- }
46
-
47
- variable "defaults" {
48
42
default = []
49
43
type = list (string )
50
- description = " List of default IDEs to be added to the Workspace page. Conflicts with the default variable. "
44
+ description = " List of default IDEs to be added to the Workspace page."
51
45
# check if the list is unique
52
46
validation {
53
- condition = length (var. defaults ) == length (toset (var. defaults ))
54
- error_message = " The defaults must not contain duplicates."
47
+ condition = length (var. default ) == length (toset (var. default ))
48
+ error_message = " The default must not contain duplicates."
55
49
}
56
- # check if defaults are valid jetbrains_ides
50
+ # check if default are valid jetbrains_ides
57
51
validation {
58
52
condition = (
59
53
alltrue ([
60
- for code in var . defaults : contains ([" IU" , " PS" , " WS" , " PY" , " CL" , " GO" , " RM" , " RD" ], code)
54
+ for code in var . default : contains ([" IU" , " PS" , " WS" , " PY" , " CL" , " GO" , " RM" , " RD" ], code)
61
55
])
62
56
)
63
- error_message = " The defaults must be a list of valid product codes. Valid product codes are ${ join (" ," , [" IU" , " PS" , " WS" , " PY" , " CL" , " GO" , " RM" , " RD" ])} ."
57
+ error_message = " The default must be a list of valid product codes. Valid product codes are ${ join (" ," , [" IU" , " PS" , " WS" , " PY" , " CL" , " GO" , " RM" , " RD" ])} ."
64
58
}
65
59
}
66
60
@@ -144,7 +138,7 @@ variable "jetbrains_ide_versions" {
144
138
145
139
variable "jetbrains_ides" {
146
140
type = list (string )
147
- description = " The list of IDE product codes to be shown to the user. Does not apply when defaults are used ."
141
+ description = " The list of IDE product codes to be shown to the user. Does not apply when there are multiple defaults ."
148
142
default = [" IU" , " PS" , " WS" , " PY" , " CL" , " GO" , " RM" , " RD" ]
149
143
validation {
150
144
condition = (
@@ -259,24 +253,42 @@ locals {
259
253
}
260
254
}
261
255
262
- icon = local. jetbrains_ides [try (data. coder_parameter . jetbrains_ide [0 ]. value , var. defaults [0 ])]. icon
263
- json_data = var. latest ? jsondecode (data. http . jetbrains_ide_versions [try (data. coder_parameter . jetbrains_ide [0 ]. value , var. defaults [0 ])]. response_body ) : {}
264
- key = var. latest ? keys (local. json_data )[0 ] : " "
265
- display_name = local. jetbrains_ides [try (data. coder_parameter . jetbrains_ide [0 ]. value , var. defaults [0 ])]. name
266
- identifier = try (data. coder_parameter . jetbrains_ide [0 ]. value , var. defaults [0 ])
267
- download_link = var. latest ? local. json_data [local . key ][0 ]. downloads . linux . link : local. jetbrains_ides [try (data. coder_parameter . jetbrains_ide [0 ]. value , var. defaults [0 ])]. download_link
268
- build_number = var. latest ? local. json_data [local . key ][0 ]. build : local. jetbrains_ides [try (data. coder_parameter . jetbrains_ide [0 ]. value , var. defaults [0 ])]. build_number
269
- version = var. latest ? local. json_data [local . key ][0 ]. version : var. jetbrains_ide_versions [try (data. coder_parameter . jetbrains_ide [0 ]. value , var. defaults [0 ])]. version
256
+ identifier = try ([data . coder_parameter . jetbrains_ide [0 ]. value ], var. default )
257
+ list_json_data = var. latest ? [
258
+ for ide in local . identifier : jsondecode (data. http . jetbrains_ide_versions [ide ]. response_body )
259
+ ] : []
260
+ list_key = var. latest ? [
261
+ for j in local . list_json_data : keys (j)[0 ]
262
+ ] : []
263
+ download_links = length (local. list_key ) > 0 ? [
264
+ for i , j in local . list_json_data : j [local . list_key [i ]][0 ]. downloads . linux . link
265
+ ] : [
266
+ for ide in local . identifier : local . jetbrains_ides [ide ]. download_link
267
+ ]
268
+ build_numbers = length (local. list_key ) > 0 ? [
269
+ for i , j in local . list_json_data : j [local . list_key [i ]][0 ]. build
270
+ ] : [
271
+ for ide in local . identifier : local . jetbrains_ides [ide ]. build_number
272
+ ]
273
+ versions = length (local. list_key ) > 0 ? [
274
+ for i , j in local . list_json_data : j [local . list_key [i ]][0 ]. version
275
+ ] : [
276
+ for ide in local . identifier : local . jetbrains_ides [ide ]. version
277
+ ]
278
+ display_names = [for key in keys (coder_app. gateway ) : coder_app . gateway [key ]. display_name ]
279
+ icons = [for key in keys (coder_app. gateway ) : coder_app . gateway [key ]. icon ]
280
+ urls = [for key in keys (coder_app. gateway ) : coder_app . gateway [key ]. url ]
270
281
}
271
282
272
283
data "coder_parameter" "jetbrains_ide" {
273
- count = length (var. defaults ) > 0 ? 0 : 1
284
+ # remove the coder_parameter if there are multiple default
285
+ count = length (var. default ) > 1 ? 0 : 1
274
286
type = " string"
275
287
name = " jetbrains_ide"
276
288
display_name = " JetBrains IDE"
277
289
icon = " /icon/gateway.svg"
278
290
mutable = true
279
- default = var. default == " " ? var. jetbrains_ides [0 ] : var. default
291
+ default = length ( var. default ) > 0 ? var. default [0 ] : var. jetbrains_ides [ 0 ]
280
292
order = var. coder_parameter_order
281
293
282
294
dynamic "option" {
@@ -293,7 +305,7 @@ data "coder_workspace" "me" {}
293
305
data "coder_workspace_owner" "me" {}
294
306
295
307
resource "coder_app" "gateway" {
296
- for_each = length (var. defaults ) > 0 ? toset (var. defaults ) : toset ([data . coder_parameter . jetbrains_ide [0 ]. value ])
308
+ for_each = length (var. default ) > 1 ? toset (var. default ) : toset ([data . coder_parameter . jetbrains_ide [0 ]. value ])
297
309
agent_id = var. agent_id
298
310
slug = var. slug
299
311
display_name = local. jetbrains_ides [each . value ]. name
@@ -328,31 +340,31 @@ output "identifier" {
328
340
}
329
341
330
342
output "display_name" {
331
- value = local . display_name
343
+ value = [ for key in keys (coder_app . gateway ) : coder_app . gateway [ key ] . display_name ]
332
344
description = " The display name of the JetBrains IDE."
333
345
}
334
346
335
347
output "icon" {
336
- value = local . icon
348
+ value = [ for key in keys (coder_app . gateway ) : coder_app . gateway [ key ] . icon ]
337
349
description = " The icon of the JetBrains IDE."
338
350
}
339
351
340
352
output "download_link" {
341
- value = local. download_link
353
+ value = local. download_links
342
354
description = " The download link of the JetBrains IDE."
343
355
}
344
356
345
357
output "build_number" {
346
- value = local. build_number
358
+ value = local. build_numbers
347
359
description = " The build number of the JetBrains IDE."
348
360
}
349
361
350
362
output "version" {
351
- value = local. version
363
+ value = local. versions
352
364
description = " The version of the JetBrains IDE."
353
365
}
354
366
355
367
output "url" {
356
368
value = [for key in keys (coder_app. gateway ) : coder_app . gateway [key ]. url ]
357
- description = " The URLs to connect to the JetBrains IDEs ."
369
+ description = " The URL to connect to the JetBrains IDE ."
358
370
}
0 commit comments