@@ -404,6 +404,64 @@ 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
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. Add a `coder_parameter` with type `bool` to ask the user if they want the
413
+ code-server IDE
414
+
415
+ ` ` ` hcl
416
+ data "coder_parameter" "code_server" {
417
+ name = "Do you want code-server in your workspace?"
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 depending on the value of the added `coder_parameter`
429
+
430
+ ` ` ` sh
431
+ # install and start 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
441
+ [`count`](https://developer.hashicorp.com/terraform/language/meta-arguments/count)
442
+ in the `coder_app` resource so it will only create the resource if the
443
+ ` coder_parameter` is `true`
444
+
445
+ ` ` ` hcl
446
+ # code-server
447
+ resource "coder_app" "code-server" {
448
+ count = data.coder_parameter.code_server.value ? 1 : 0
449
+ agent_id = coder_agent.coder.id
450
+ slug = "code-server"
451
+ display_name = "code-server"
452
+ icon = "/icon/code.svg"
453
+ url = "http://localhost:13337?folder=/home/coder"
454
+ subdomain = false
455
+ share = "owner"
456
+
457
+ healthcheck {
458
+ url = "http://localhost:13337/healthz"
459
+ interval = 3
460
+ threshold = 10
461
+ }
462
+ }
463
+ ` ` `
464
+
407
465
# # Why am I getting this "remote host doesn't meet VS Code Server's prerequisites" error when opening up VSCode remote in a Linux environment?
408
466
409
467

0 commit comments