@@ -22,6 +22,10 @@ variable "agent_name" {
22
22
variable "folder" {
23
23
type = string
24
24
description = " The directory to open in the IDE. e.g. /home/coder/project"
25
+ validation {
26
+ condition = can (regex (" ^(?:/[^/]+)+$" , var. folder ))
27
+ error_message = " The folder must be a full path and must not start with a ~."
28
+ }
25
29
}
26
30
27
31
variable "default" {
@@ -30,10 +34,6 @@ variable "default" {
30
34
description = " Default IDE"
31
35
}
32
36
33
- locals {
34
- supported_ides = [" IU" , " PS" , " WS" , " PY" , " CL" , " GO" , " RM" ]
35
- }
36
-
37
37
variable "jetbrains_ide_versions" {
38
38
type = map (object ({
39
39
build_number = string
@@ -69,29 +69,28 @@ variable "jetbrains_ide_versions" {
69
69
build_number = " 232.10203.15"
70
70
version = " 2023.2.4"
71
71
}
72
-
73
72
}
74
73
validation {
75
74
condition = (
76
75
alltrue ([
77
- for code in var . jetbrains_ide_versions : contains (local . supported_ides , code)
76
+ for code in keys ( var. jetbrains_ide_versions ) : contains ([ " IU " , " PS " , " WS " , " PY " , " CL " , " GO " , " RM " ] , code)
78
77
])
79
78
)
80
- error_message = " The jetbrains_ide_versions must contain a map of valid product codes. Valid product codes are ${ join (" ," , local . supported_ides )} ."
79
+ error_message = " The jetbrains_ide_versions must contain a map of valid product codes. Valid product codes are ${ join (" ," , [ " IU " , " PS " , " WS " , " PY " , " CL " , " GO " , " RM " ] )} ."
81
80
}
82
81
}
83
82
84
83
variable "jetbrains_ides" {
85
84
type = list (string )
86
85
description = " The list of IDE product codes."
87
- default = local . supported_ides
86
+ default = [ " IU " , " PS " , " WS " , " PY " , " CL " , " GO " , " RM " ]
88
87
validation {
89
88
condition = (
90
89
alltrue ([
91
- for code in var . jetbrains_ides : contains (local . supported_ides , code)
90
+ for code in var . jetbrains_ides : contains ([ " IU " , " PS " , " WS " , " PY " , " CL " , " GO " , " RM " ] , code)
92
91
])
93
92
)
94
- error_message = " The jetbrains_ides must be a list of valid product codes. Valid product codes are ${ join (" ," , local . supported_ides )} ."
93
+ error_message = " The jetbrains_ides must be a list of valid product codes. Valid product codes are ${ join (" ," , [ " IU " , " PS " , " WS " , " PY " , " CL " , " GO " , " RM " ] )} ."
95
94
}
96
95
# check if the list is empty
97
96
validation {
@@ -108,58 +107,71 @@ variable "jetbrains_ides" {
108
107
locals {
109
108
jetbrains_ides = {
110
109
" GO" = {
111
- icon = " /icon/goland.svg" ,
112
- name = " GoLand" ,
113
- value = jsonencode ([" GO" , var . jetbrains_ide_versions [" GO" ]. build_number , " https://download.jetbrains.com/go/goland-${ var . jetbrains_ide_versions [" GO" ]. version } .tar.gz" ])
110
+ icon = " /icon/goland.svg" ,
111
+ name = " GoLand" ,
112
+ identifier = " GO" ,
113
+ build_number = var.jetbrains_ide_versions[" GO" ].build_number,
114
+ download_link = " https://download.jetbrains.com/go/goland-${ var . jetbrains_ide_versions [" GO" ]. version } .tar.gz"
114
115
},
115
116
" WS" = {
116
- icon = " /icon/webstorm.svg" ,
117
- name = " WebStorm" ,
118
- value = jsonencode ([" WS" , var . jetbrains_ide_versions [" WS" ]. build_number , " https://download.jetbrains.com/webstorm/WebStorm-${ var . jetbrains_ide_versions [" WS" ]. version } .tar.gz" ])
117
+ icon = " /icon/webstorm.svg" ,
118
+ name = " WebStorm" ,
119
+ identifier = " WS" ,
120
+ build_number = var.jetbrains_ide_versions[" WS" ].build_number,
121
+ download_link = " https://download.jetbrains.com/webstorm/WebStorm-${ var . jetbrains_ide_versions [" WS" ]. version } .tar.gz"
119
122
},
120
123
" IU" = {
121
- icon = " /icon/intellij.svg" ,
122
- name = " IntelliJ IDEA Ultimate" ,
123
- value = jsonencode ([" IU" , var . jetbrains_ide_versions [" IU" ]. build_number , " https://download.jetbrains.com/idea/ideaIU-${ var . jetbrains_ide_versions [" IU" ]. version } .tar.gz" ])
124
+ icon = " /icon/intellij.svg" ,
125
+ name = " IntelliJ IDEA Ultimate" ,
126
+ identifier = " IU" ,
127
+ build_number = var.jetbrains_ide_versions[" IU" ].build_number,
128
+ download_link = " https://download.jetbrains.com/idea/ideaIU-${ var . jetbrains_ide_versions [" IU" ]. version } .tar.gz"
124
129
},
125
130
" PY" = {
126
- icon = " /icon/pycharm.svg" ,
127
- name = " PyCharm Professional" ,
128
- value = jsonencode ([" PY" , var . jetbrains_ide_versions [" PY" ]. build_number , " https://download.jetbrains.com/python/pycharm-professional-${ var . jetbrains_ide_versions [" PY" ]. version } .tar.gz" ])
131
+ icon = " /icon/pycharm.svg" ,
132
+ name = " PyCharm Professional" ,
133
+ identifier = " PY" ,
134
+ build_number = var.jetbrains_ide_versions[" PY" ].build_number,
135
+ download_link = " https://download.jetbrains.com/python/pycharm-professional-${ var . jetbrains_ide_versions [" PY" ]. version } .tar.gz"
129
136
},
130
137
" CL" = {
131
- icon = " /icon/clion.svg" ,
132
- name = " CLion" ,
133
- value = jsonencode ([" CL" , var . jetbrains_ide_versions [" CL" ]. build_number , " https://download.jetbrains.com/cpp/CLion-${ var . jetbrains_ide_versions [" CL" ]. version } .tar.gz" ])
138
+ icon = " /icon/clion.svg" ,
139
+ name = " CLion" ,
140
+ identifier = " CL" ,
141
+ build_number = var.jetbrains_ide_versions[" CL" ].build_number,
142
+ download_link = " https://download.jetbrains.com/cpp/CLion-${ var . jetbrains_ide_versions [" CL" ]. version } .tar.gz"
134
143
},
135
144
" PS" = {
136
- icon = " /icon/phpstorm.svg" ,
137
- name = " PhpStorm" ,
138
- value = jsonencode ([" PS" , var . jetbrains_ide_versions [" PS" ]. build_number , " https://download.jetbrains.com/webide/PhpStorm-${ var . jetbrains_ide_versions [" PS" ]. version } .tar.gz" ])
145
+ icon = " /icon/phpstorm.svg" ,
146
+ name = " PhpStorm" ,
147
+ identifier = " PS" ,
148
+ build_number = var.jetbrains_ide_versions[" PS" ].build_number,
149
+ download_link = " https://download.jetbrains.com/webide/PhpStorm-${ var . jetbrains_ide_versions [" PS" ]. version } .tar.gz"
139
150
},
140
151
" RM" = {
141
- icon = " /icon/rubymine.svg" ,
142
- name = " RubyMine" ,
143
- value = jsonencode ([" RM" , var . jetbrains_ide_versions [" RM" ]. build_number , " https://download.jetbrains.com/ruby/RubyMine-${ var . jetbrains_ide_versions [" RM" ]. version } .tar.gz" ])
152
+ icon = " /icon/rubymine.svg" ,
153
+ name = " RubyMine" ,
154
+ identifier = " RM" ,
155
+ build_number = var.jetbrains_ide_versions[" RM" ].build_number,
156
+ download_link = " https://download.jetbrains.com/ruby/RubyMine-${ var . jetbrains_ide_versions [" RM" ]. version } .tar.gz"
144
157
}
145
158
}
146
159
}
147
160
148
161
data "coder_parameter" "jetbrains_ide" {
149
- type = " list( string) "
162
+ type = " string"
150
163
name = " jetbrains_ide"
151
164
display_name = " JetBrains IDE"
152
165
icon = " /icon/gateway.svg"
153
166
mutable = true
154
- # check if default is in the jet_brains_ides list and if it is not empty or null otherwise set it to null
155
- default = var. default != null && var. default != " " && contains (var. jetbrains_ides , var. default ) ? local. jetbrains_ides [var . default ]. value : local. jetbrains_ides [var . jetbrains_ides [0 ]]. value
167
+ default = var. default == " " ? var. jetbrains_ides [0 ] : var. default
156
168
157
169
dynamic "option" {
158
- for_each = { for key , value in local . jetbrains_ides : key => value if contains ( var. jetbrains_ides , key) }
170
+ for_each = var. jetbrains_ides
159
171
content {
160
- icon = option. value . icon
161
- name = option. value . name
162
- value = option. value . value
172
+ icon = lookup (local . jetbrains_ides , option. value ) . icon
173
+ name = lookup (local . jetbrains_ides , option. value ) . name
174
+ value = lookup (local . jetbrains_ides , option. value ) . identifier
163
175
}
164
176
}
165
177
}
@@ -168,9 +180,9 @@ data "coder_workspace" "me" {}
168
180
169
181
resource "coder_app" "gateway" {
170
182
agent_id = var. agent_id
171
- display_name = data. coder_parameter . jetbrains_ide . option [index (data. coder_parameter . jetbrains_ide . option . * . value , data. coder_parameter . jetbrains_ide . value )]. name
172
183
slug = " gateway"
173
- icon = data. coder_parameter . jetbrains_ide . option [index (data. coder_parameter . jetbrains_ide . option . * . value , data. coder_parameter . jetbrains_ide . value )]. icon
184
+ display_name = try (lookup (local. jetbrains_ides , data. coder_parameter . jetbrains_ide . value ). name , " JetBrains IDE" )
185
+ icon = try (lookup (local. jetbrains_ides , data. coder_parameter . jetbrains_ide . value ). icon , " /icon/gateway.svg" )
174
186
external = true
175
187
url = join (" " , [
176
188
" jetbrains-gateway://connect#type=coder&workspace=" ,
@@ -184,14 +196,38 @@ resource "coder_app" "gateway" {
184
196
" &token=" ,
185
197
" $SESSION_TOKEN" ,
186
198
" &ide_product_code=" ,
187
- jsondecode ( data. coder_parameter . jetbrains_ide . value )[ 0 ] ,
199
+ local . jetbrains_ides [ data . coder_parameter . jetbrains_ide . value ] . identifier ,
188
200
" &ide_build_number=" ,
189
- jsondecode ( data. coder_parameter . jetbrains_ide . value )[ 1 ] ,
201
+ local . jetbrains_ides [ data . coder_parameter . jetbrains_ide . value ] . build_number ,
190
202
" &ide_download_link=" ,
191
- jsondecode ( data. coder_parameter . jetbrains_ide . value )[ 2 ],
203
+ local . jetbrains_ides [ data . coder_parameter . jetbrains_ide . value ] . download_link
192
204
])
193
205
}
194
206
195
- output "jetbrains_ides " {
207
+ output "identifier " {
196
208
value = data. coder_parameter . jetbrains_ide . value
197
209
}
210
+
211
+ output "name" {
212
+ value = coder_app. gateway . display_name
213
+ }
214
+
215
+ output "icon" {
216
+ value = coder_app. gateway . icon
217
+ }
218
+
219
+ output "download_link" {
220
+ value = lookup (local. jetbrains_ides , data. coder_parameter . jetbrains_ide . value ). download_link
221
+ }
222
+
223
+ output "build_number" {
224
+ value = lookup (local. jetbrains_ides , data. coder_parameter . jetbrains_ide . value ). build_number
225
+ }
226
+
227
+ output "version" {
228
+ value = var. jetbrains_ide_versions [data . coder_parameter . jetbrains_ide . value ]. version
229
+ }
230
+
231
+ output "url" {
232
+ value = coder_app. gateway . url
233
+ }
0 commit comments