-
Notifications
You must be signed in to change notification settings - Fork 894
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
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
56b222f
chore: add optional coder_app to faq
sharkymark 3eec79a
applied Atif's suggestions
stirby f00f8c6
Merge branch 'main' into docs-faq-optional-coder-app
stirby 1919df7
Merge branch 'main' into docs-faq-optional-coder-app
stirby 0e732e3
make fmt again
stirby File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -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" | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
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 | ||||||||||
stirby marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||
|
||||||||||
```sh | ||||||||||
# install and code-server, VS Code in a browser | ||||||||||
stirby marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||
|
||||||||||
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 | ||||||||||
stirby marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||
|
||||||||||
```hcl | ||||||||||
# code-server | ||||||||||
resource "coder_app" "code-server" { | ||||||||||
count = data.coder_parameter.code_server.value ? 1 : 0 | ||||||||||
stirby marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||
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 | ||||||||||
} | ||||||||||
} | ||||||||||
``` |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.