@@ -403,3 +403,59 @@ colima start --arch x86_64 --cpu 4 --memory 8 --disk 10
403
403
Colima will show the path to the docker socket so I have a
404
404
[Coder template](./docker-code-server/main.tf) that prompts the Coder admin to
405
405
enter the docker socket as a Terraform variable.
406
+
407
+ # # How to make a `coder_app` optional?
408
+
409
+ An example use case is the user should decide if they want a browser-based IDE
410
+ like code-server when creating the workspace.
411
+
412
+ 1. Create a `coder_parameter` as a `bool` to ask the user if they want the
413
+ code-server IDE
414
+
415
+ ` ` ` hcl
416
+ data "coder_parameter" "code_server" {
417
+ name = "code-server (optional)"
418
+ description = "Use VS Code in a browser"
419
+ type = "bool"
420
+ default = false
421
+ mutable = true
422
+ icon = "/icon/code.svg"
423
+ order = 6
424
+ }
425
+ ` ` `
426
+
427
+ 2. Add conditional logic to the `startup_script` to install and start
428
+ code-server if the `bool` is true
429
+
430
+ ` ` ` sh
431
+ # install and code-server, VS Code in a browser
432
+
433
+ if [ ${data.coder_parameter.code_server.value} = true ]; then
434
+ echo "🧑🏼💻 Downloading and installing the latest code-server IDE..."
435
+ curl -fsSL https://code-server.dev/install.sh | sh
436
+ code-server --auth none --port 13337 >/dev/null 2>&1 &
437
+ fi
438
+ ` ` `
439
+
440
+ 3. Add a Terraform meta-argument `count` in the `coder_app` resource so it will
441
+ only create the resource if the `coder_parameter` is true
442
+
443
+ ` ` ` hcl
444
+ # code-server
445
+ resource "coder_app" "code-server" {
446
+ count = data.coder_parameter.code_server.value ? 1 : 0
447
+ agent_id = coder_agent.coder.id
448
+ slug = "code-server"
449
+ display_name = "code-server"
450
+ icon = "/icon/code.svg"
451
+ url = "http://localhost:13337?folder=/home/coder"
452
+ subdomain = false
453
+ share = "owner"
454
+
455
+ healthcheck {
456
+ url = "http://localhost:13337/healthz"
457
+ interval = 3
458
+ threshold = 10
459
+ }
460
+ }
461
+ ` ` `
0 commit comments