From 56b222fd9ad2e7d6a277017a0cfebb6d616deddd Mon Sep 17 00:00:00 2001 From: Mark Milligan Date: Fri, 29 Dec 2023 19:39:22 +0000 Subject: [PATCH 1/3] chore: add optional coder_app to faq --- docs/faqs.md | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/docs/faqs.md b/docs/faqs.md index 000109ecf06a1..bd53c40c14903 100644 --- a/docs/faqs.md +++ b/docs/faqs.md @@ -403,3 +403,59 @@ colima start --arch x86_64 --cpu 4 --memory 8 --disk 10 Colima will show the path to the docker socket so I have a [Coder template](./docker-code-server/main.tf) that prompts the Coder admin to enter the docker socket as a Terraform variable. + +## How to make a `coder_app` optional? + +An example use case is the user should decide if they want a browser-based IDE +like code-server when creating the workspace. + +1. Create a `coder_parameter` as a `bool` to ask the user if they want the + code-server IDE + +```hcl +data "coder_parameter" "code_server" { + name = "code-server (optional)" + description = "Use VS Code in a browser" + type = "bool" + default = false + mutable = true + icon = "/icon/code.svg" + order = 6 +} +``` + +2. Add conditional logic to the `startup_script` to install and start + code-server if the `bool` is true + +```sh +# install and code-server, VS Code in a browser + +if [ ${data.coder_parameter.code_server.value} = true ]; then + echo "🧑🏼‍💻 Downloading and installing the latest code-server IDE..." + curl -fsSL https://code-server.dev/install.sh | sh + code-server --auth none --port 13337 >/dev/null 2>&1 & +fi +``` + +3. Add a Terraform meta-argument `count` in the `coder_app` resource so it will + only create the resource if the `coder_parameter` is true + +```hcl +# code-server +resource "coder_app" "code-server" { + count = data.coder_parameter.code_server.value ? 1 : 0 + agent_id = coder_agent.coder.id + slug = "code-server" + display_name = "code-server" + icon = "/icon/code.svg" + url = "http://localhost:13337?folder=/home/coder" + subdomain = false + share = "owner" + + healthcheck { + url = "http://localhost:13337/healthz" + interval = 3 + threshold = 10 + } +} +``` From 3eec79a14b28f5e34414d5bfbe2eacdfb6d01b0c Mon Sep 17 00:00:00 2001 From: kirby Date: Thu, 11 Jan 2024 17:27:01 +0000 Subject: [PATCH 2/3] applied Atif's suggestions --- docs/faqs.md | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/docs/faqs.md b/docs/faqs.md index bd53c40c14903..77ed78a7b7ebf 100644 --- a/docs/faqs.md +++ b/docs/faqs.md @@ -409,13 +409,13 @@ enter the docker socket as a Terraform variable. An example use case is the user should decide if they want a browser-based IDE like code-server when creating the workspace. -1. Create a `coder_parameter` as a `bool` to ask the user if they want the +1. Add a `coder_parameter` with type `bool` to ask the user if they want the code-server IDE ```hcl data "coder_parameter" "code_server" { - name = "code-server (optional)" - description = "Use VS Code in a browser" + name = "Do you want code-server in your workspace?" + description = "Use VS Code in a browser." type = "bool" default = false mutable = true @@ -425,10 +425,10 @@ data "coder_parameter" "code_server" { ``` 2. Add conditional logic to the `startup_script` to install and start - code-server if the `bool` is true + code-server depending on the value of the added `coder_parameter` ```sh -# install and code-server, VS Code in a browser +# install and start code-server, VS Code in a browser if [ ${data.coder_parameter.code_server.value} = true ]; then echo "🧑🏼‍💻 Downloading and installing the latest code-server IDE..." @@ -437,13 +437,15 @@ if [ ${data.coder_parameter.code_server.value} = true ]; then fi ``` -3. Add a Terraform meta-argument `count` in the `coder_app` resource so it will - only create the resource if the `coder_parameter` is true +3. Add a Terraform meta-argument + [`count`](https://developer.hashicorp.com/terraform/language/meta-arguments/count) + in the `coder_app` resource so it will only create the resource if the + `coder_parameter` is `true` ```hcl # code-server resource "coder_app" "code-server" { - count = data.coder_parameter.code_server.value ? 1 : 0 + count = data.coder_parameter.code_server.value ? 1 : 0 agent_id = coder_agent.coder.id slug = "code-server" display_name = "code-server" From 0e732e3c76b1c392b5474b72b1e3a2b2f9023025 Mon Sep 17 00:00:00 2001 From: kirby Date: Thu, 11 Jan 2024 17:35:07 +0000 Subject: [PATCH 3/3] make fmt again --- docs/faqs.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/docs/faqs.md b/docs/faqs.md index 1a5033bbc0476..5f4f687b496c6 100644 --- a/docs/faqs.md +++ b/docs/faqs.md @@ -404,7 +404,6 @@ Colima will show the path to the docker socket so I have a [Coder template](./docker-code-server/main.tf) that prompts the Coder admin to enter the docker socket as a Terraform variable. - ## How to make a `coder_app` optional? An example use case is the user should decide if they want a browser-based IDE @@ -473,4 +472,3 @@ instance, Alpine is not supported at all. If so, you need to find a container image or supported OS for the VS Code Server. For more information on OS prerequisites for Linux, please look at the VSCode docs. https://code.visualstudio.com/docs/remote/linux#_local-linux-prerequisites -