Skip to content

chore: add optional coder_app to faq #11351

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jan 11, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
applied Atif's suggestions
  • Loading branch information
stirby committed Jan 11, 2024
commit 3eec79a14b28f5e34414d5bfbe2eacdfb6d01b0c
18 changes: 10 additions & 8 deletions docs/faqs.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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..."
Expand All @@ -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"
Expand Down