Skip to content
Merged
Show file tree
Hide file tree
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
example
  • Loading branch information
mtojek committed May 23, 2024
commit 716d01e5d43344c5745b748b5d832cf27f8d4c39
1 change: 0 additions & 1 deletion examples/parameters-dynamic-options/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,5 @@ Update the template and push it using the following command:
./scripts/coder-dev.sh templates push examples-parameters-dynamic-options \
-d examples/parameters-dynamic-options \
--variables-file examples/parameters-dynamic-options/variables.yml \
--create \
-y
```
9 changes: 7 additions & 2 deletions examples/workspace-tags/README.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,26 @@
---
name: Sample Template with Workspace Tags
description: Review the sample template and introduce workspace tags to your template
description: Review the sample template and introduce dynamic workspace tags to your template
tags: [local, docker, workspace-tags]
icon: /icon/docker.png
---

# Overview

This Coder template presents use of [Workspace Tags](https://coder.com/docs/v2/latest/templates/workspace-tags) [Coder Parameters](https://coder.com/docs/v2/latest/templates/parameters).

# Use case

Template administrators can use static tags to control workspace provisioning, limiting it to specific provisioner groups. However, this restricts workspace users from choosing their preferred workspace nodes.

By using `coder_workspace_tags` and `coder_parameter`s, template administrators can allow dynamic tag selection, avoiding the need to push the same template multiple times with different tags.

## Development

Update the template and push it using the following command:

```
./scripts/coder-dev.sh templates push examples-workspace-tags \
-d examples/workspace-tags \
--create \
-y
```
51 changes: 51 additions & 0 deletions examples/workspace-tags/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,63 @@ terraform {
}
}

locals {
username = data.coder_workspace.me.owner
}

data "coder_provisioner" "me" {
}

data "coder_workspace" "me" {
}

data "coder_workspace_tags" "custom_workspace_tags" {
tags = {
"zone" = "developers"
"os" = data.coder_parameter.os_selector.value
"project_id" = "PROJECT_${data.coder_parameter.project_name.value}"
"cache" = data.coder_parameter.feature_cache_enabled.value == "true" ? "with-cache" : "no-cache"
}
}

data "coder_parameter" "os_selector" {
name = "os_selector"
display_name = "OS runtime"
default = "linux"

option {
name = "Linux"
value = "linux"
}
option {
name = "OSX"
value = "osx"
}
option {
name = "Windows"
value = "windows"
}

mutable = false
}
Copy link
Member

@matifali matifali May 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you explain if data.coder_parameter.os_selector represents the os of the workspace being provisioned? This example confuses me in understanding the purpose and benefits of using workspace_tags. If yes, then the code-server and the docker_container can only run on a Linux host. This feels incomplete on how a template can provide a workspace with three different OS using the new functionality and external-provisioners.

As this will also be published as an official example on https://registry.coder.com/templates, we should try to make the tags as practical as possible.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can remove the example altogether, too.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renamed the os_selector to runtime_selector, so it might be easier to comprehend that is about selecting either a free zone or an isolated, secure, air-gapped environment. I hope it makes it clear.

BTW I can modify it to depend on "foobars" too. My intention was to indicate the syntax rather providing use cases.

Copy link
Member

@matifali matifali May 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is better. But my opinion is that we should remove the example altogether if it is not usable out of the box. The docs are written well enough to serve the users who actually need to use this feature.


data "coder_parameter" "project_name" {
name = "project_name"
display_name = "Project name"
description = "Specify the project name."

mutable = false
}

data "coder_parameter" "feature_cache_enabled" {
name = "feature_cache_enabled"
display_name = "Enable cache?"
type = "bool"
default = false

mutable = false
}

resource "coder_agent" "main" {
arch = data.coder_provisioner.me.arch
os = "linux"
Expand Down