@@ -6,6 +6,10 @@ terraform {
66 source = " coder/coder"
77 version = " >= 0.17"
88 }
9+ http = {
10+ source = " hashicorp/http"
11+ version = " >= 3.0"
12+ }
913 }
1014}
1115
@@ -46,6 +50,22 @@ variable "coder_parameter_order" {
4650 default = null
4751}
4852
53+ variable "latest" {
54+ type = bool
55+ description = " Whether to fetch the latest version of the IDE."
56+ default = false
57+ }
58+
59+ variable "channel" {
60+ type = string
61+ description = " JetBrains IDE release channel. Valid values are release and eap."
62+ default = " release"
63+ validation {
64+ condition = can (regex (" ^(release|eap)$" , var. channel ))
65+ error_message = " The channel must be either release or eap."
66+ }
67+ }
68+
4969variable "jetbrains_ide_versions" {
5070 type = map (object ({
5171 build_number = string
@@ -120,6 +140,11 @@ variable "jetbrains_ides" {
120140 }
121141}
122142
143+ data "http" "jetbrains_ide_versions" {
144+ for_each = var. latest ? toset (var. jetbrains_ides ) : toset ([])
145+ url = " https://data.services.jetbrains.com/products/releases?code=${ each . key } &latest=true&type=${ var . channel } "
146+ }
147+
123148locals {
124149 jetbrains_ides = {
125150 " GO" = {
@@ -128,57 +153,74 @@ locals {
128153 identifier = " GO" ,
129154 build_number = var.jetbrains_ide_versions[" GO" ].build_number,
130155 download_link = " https://download.jetbrains.com/go/goland-${ var . jetbrains_ide_versions [" GO" ]. version } .tar.gz"
156+ version = var.jetbrains_ide_versions[" GO" ].version
131157 },
132158 " WS" = {
133159 icon = " /icon/webstorm.svg" ,
134160 name = " WebStorm" ,
135161 identifier = " WS" ,
136162 build_number = var.jetbrains_ide_versions[" WS" ].build_number,
137163 download_link = " https://download.jetbrains.com/webstorm/WebStorm-${ var . jetbrains_ide_versions [" WS" ]. version } .tar.gz"
164+ version = var.jetbrains_ide_versions[" WS" ].version
138165 },
139166 " IU" = {
140167 icon = " /icon/intellij.svg" ,
141168 name = " IntelliJ IDEA Ultimate" ,
142169 identifier = " IU" ,
143170 build_number = var.jetbrains_ide_versions[" IU" ].build_number,
144171 download_link = " https://download.jetbrains.com/idea/ideaIU-${ var . jetbrains_ide_versions [" IU" ]. version } .tar.gz"
172+ version = var.jetbrains_ide_versions[" IU" ].version
145173 },
146174 " PY" = {
147175 icon = " /icon/pycharm.svg" ,
148176 name = " PyCharm Professional" ,
149177 identifier = " PY" ,
150178 build_number = var.jetbrains_ide_versions[" PY" ].build_number,
151179 download_link = " https://download.jetbrains.com/python/pycharm-professional-${ var . jetbrains_ide_versions [" PY" ]. version } .tar.gz"
180+ version = var.jetbrains_ide_versions[" PY" ].version
152181 },
153182 " CL" = {
154183 icon = " /icon/clion.svg" ,
155184 name = " CLion" ,
156185 identifier = " CL" ,
157186 build_number = var.jetbrains_ide_versions[" CL" ].build_number,
158187 download_link = " https://download.jetbrains.com/cpp/CLion-${ var . jetbrains_ide_versions [" CL" ]. version } .tar.gz"
188+ version = var.jetbrains_ide_versions[" CL" ].version
159189 },
160190 " PS" = {
161191 icon = " /icon/phpstorm.svg" ,
162192 name = " PhpStorm" ,
163193 identifier = " PS" ,
164194 build_number = var.jetbrains_ide_versions[" PS" ].build_number,
165195 download_link = " https://download.jetbrains.com/webide/PhpStorm-${ var . jetbrains_ide_versions [" PS" ]. version } .tar.gz"
196+ version = var.jetbrains_ide_versions[" PS" ].version
166197 },
167198 " RM" = {
168199 icon = " /icon/rubymine.svg" ,
169200 name = " RubyMine" ,
170201 identifier = " RM" ,
171202 build_number = var.jetbrains_ide_versions[" RM" ].build_number,
172203 download_link = " https://download.jetbrains.com/ruby/RubyMine-${ var . jetbrains_ide_versions [" RM" ]. version } .tar.gz"
204+ version = var.jetbrains_ide_versions[" RM" ].version
173205 }
174206 " RD" = {
175207 icon = " /icon/rider.svg" ,
176208 name = " Rider" ,
177209 identifier = " RD" ,
178210 build_number = var.jetbrains_ide_versions[" RD" ].build_number,
179211 download_link = " https://download.jetbrains.com/rider/JetBrains.Rider-${ var . jetbrains_ide_versions [" RD" ]. version } .tar.gz"
212+ version = var.jetbrains_ide_versions[" RD" ].version
180213 }
181214 }
215+
216+ icon = try (lookup (local. jetbrains_ides , data. coder_parameter . jetbrains_ide . value ). icon , " /icon/gateway.svg" )
217+ json_data = var. latest ? jsondecode (data. http . jetbrains_ide_versions [data . coder_parameter . jetbrains_ide . value ]. response_body ) : {}
218+ key = var. latest ? keys (local. json_data )[0 ] : " "
219+ display_name = local. jetbrains_ides [data . coder_parameter . jetbrains_ide . value ]. name
220+ identifier = data. coder_parameter . jetbrains_ide . value
221+ download_link = var. latest ? local. json_data [local . key ][0 ]. downloads . linux . link : local. jetbrains_ides [data . coder_parameter . jetbrains_ide . value ]. download_link
222+ build_number = var. latest ? local. json_data [local . key ][0 ]. build : local. jetbrains_ides [data . coder_parameter . jetbrains_ide . value ]. build_number
223+ version = var. latest ? local. json_data [local . key ][0 ]. version : var. jetbrains_ide_versions [data . coder_parameter . jetbrains_ide . value ]. version
182224}
183225
184226data "coder_parameter" "jetbrains_ide" {
@@ -193,9 +235,9 @@ data "coder_parameter" "jetbrains_ide" {
193235 dynamic "option" {
194236 for_each = var. jetbrains_ides
195237 content {
196- icon = lookup ( local. jetbrains_ides , option. value ) . icon
197- name = lookup ( local. jetbrains_ides , option. value ) . name
198- value = lookup (local . jetbrains_ides , option. value ) . identifier
238+ icon = local. jetbrains_ides [ option . value ] . icon
239+ name = local. jetbrains_ides [ option . value ] . name
240+ value = option. value
199241 }
200242 }
201243}
@@ -205,8 +247,8 @@ data "coder_workspace" "me" {}
205247resource "coder_app" "gateway" {
206248 agent_id = var. agent_id
207249 slug = " gateway"
208- display_name = try (lookup (local . jetbrains_ides , data. coder_parameter . jetbrains_ide . value ). name , " JetBrains IDE" )
209- icon = try (lookup (local . jetbrains_ides , data. coder_parameter . jetbrains_ide . value ). icon , " /icon/gateway.svg" )
250+ display_name = try (lookup (data . coder_parameter . jetbrains_ide . option , data. coder_parameter . jetbrains_ide . value ). name , " JetBrains IDE" )
251+ icon = try (lookup (data . coder_parameter . jetbrains_ide . option , data. coder_parameter . jetbrains_ide . value ). icon , " /icon/gateway.svg" )
210252 external = true
211253 order = var. order
212254 url = join (" " , [
@@ -221,36 +263,36 @@ resource "coder_app" "gateway" {
221263 " &token=" ,
222264 " $SESSION_TOKEN" ,
223265 " &ide_product_code=" ,
224- local . jetbrains_ides [ data . coder_parameter . jetbrains_ide . value ] . identifier ,
266+ data . coder_parameter . jetbrains_ide . value ,
225267 " &ide_build_number=" ,
226- local . jetbrains_ides [ data . coder_parameter . jetbrains_ide . value ] . build_number ,
268+ local . build_number ,
227269 " &ide_download_link=" ,
228- local . jetbrains_ides [ data . coder_parameter . jetbrains_ide . value ] . download_link
270+ local . download_link ,
229271 ])
230272}
231273
232274output "identifier" {
233- value = data . coder_parameter . jetbrains_ide . value
275+ value = local . identifier
234276}
235277
236- output "name " {
237- value = coder_app . gateway . display_name
278+ output "display_name " {
279+ value = local . display_name
238280}
239281
240282output "icon" {
241- value = coder_app . gateway . icon
283+ value = local . icon
242284}
243285
244286output "download_link" {
245- value = lookup ( local. jetbrains_ides , data . coder_parameter . jetbrains_ide . value ) . download_link
287+ value = local. download_link
246288}
247289
248290output "build_number" {
249- value = lookup ( local. jetbrains_ides , data . coder_parameter . jetbrains_ide . value ) . build_number
291+ value = local. build_number
250292}
251293
252294output "version" {
253- value = var . jetbrains_ide_versions [ data . coder_parameter . jetbrains_ide . value ] . version
295+ value = local . version
254296}
255297
256298output "url" {
0 commit comments