Skip to content

Commit 5c603db

Browse files
committed
copy edit
1 parent 1c6aee4 commit 5c603db

File tree

1 file changed

+126
-103
lines changed

1 file changed

+126
-103
lines changed
Lines changed: 126 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,29 @@
11
# Prebuilt workspaces
22

3-
## Overview
3+
Prebuilt workspaces (Prebuilds) allow template administrators to improve the developer experience by reducing workspace
4+
creation time with an automatically maintained pool of ready-to-use workspaces for specific parameter presets.
45

5-
Prebuilt workspaces let you pre-provision and maintain a pool of ready-to-use workspaces.
6-
Instead of creating a new workspace when a developer requests one, if a workspace matches a preset defined in the
7-
template parameters, Coder assigns an existing instance, reducing setup time significantly.
6+
The template administrator configures a template to be available with prebuilt workspaces, and then when a developer creates
7+
a new workspace with matching parameters, Coder assigns them an existing prebuilt instance.
8+
Prebuilt workspaces significantly reduce wait times, especially for templates with complex provisioning or lengthy startup procedures.
9+
10+
Prebuilt workspaces are:
11+
12+
- Created and maintained automatically by Coder to match your specified preset configurations.
13+
- Claimed transparently when developers request matching workspaces.
14+
- Monitored and replaced automatically to maintain your desired pool size.
815

916
## Prerequisites
1017

11-
- Premium license
12-
- Use `coder/coder` Terraform provider `>= 2.3.0-pre2` in your template (**TODO: update with latest version**)
13-
- Enable the `workspace-prebuilds` [experiment](../../../reference/cli/server.md#--experiments)
18+
- [**Premium license**](../../licensing/index.md)
19+
- **Template administrator privileges**: User must have permissions to create or modify templates.
20+
- **Compatible Terraform provider**: Use `coder/coder` Terraform provider `>= 2.3.0-pre2`. (**TODO: update with latest version**)
21+
- **Feature flag**: Enable the `workspace-prebuilds` [experiment](../../../reference/cli/server.md#--experiments).
1422

15-
## Configuration
23+
## Enable Prebuilds for template presets
1624

17-
1. In your Terraform template, add a `prebuilds` block within a `coder_workspace_preset` block:
25+
In your template, add a `prebuilds` block within a `coder_workspace_preset` block to identify how many prebuilt
26+
instances your Coder deployment should maintain:
1827

1928
```hcl
2029
data "coder_workspace_preset" "goland" {
@@ -25,120 +34,120 @@ template parameters, Coder assigns an existing instance, reducing setup time sig
2534
memory = 16
2635
}
2736
prebuilds {
28-
instances = 3
37+
instances = 3 // Number of prebuilt workspaces to maintain
2938
}
3039
}
3140
```
3241

33-
1. Publish and import the template.
34-
1. Coder automatically provisions another prebuilt workspace through an internal reconciliation loop
35-
(similar to Kubernetes) to maintain the number of specified `instances`.
42+
After you create or update the template, Coder automatically provisions and maintains prebuilt workspaces through an
43+
internal reconciliation loop (similar to Kubernetes) to maintain the number of specified `instances`.
3644

37-
## Workspace ownership
45+
Prebuilt workspaces are displayed in the list of workspaces on the Coder dashboard with the owner set to `prebuilds`.
3846

39-
After a prebuilt workspace is created, it is owned by the unprivileged pseudo-user `prebuilds`, which belongs to the
40-
`Everyone` group.
41-
Coder uses the `prebuilds` user to identify unclaimed prebuilt workspaces.
42-
You can add the `prebuilds` user to additional groups if you need to.
47+
## Prebuild lifecycle
4348

44-
## View prebuilt workspaces
49+
Prebuilt workspaces follow a specific lifecycle from creation through eligibility to claiming.
4550

46-
You can view prebuilt workspaces in the **Workspaces** view in the Coder dashboard:
51+
Expand each item in this list for more information about the stage:
4752

48-
![A prebuilt workspace in the dashboard](../../../images/admin/templates/extend-templates/prebuilt/prebuilt-workspaces.png)
53+
1. <details><summary>Prebuilds provisioning and initial state</summary>
54+
55+
After you configure a preset with Prebuilds and publish the template:
56+
57+
1. Coder automatically creates prebuilt workspaces up to the specified `instances` count.
58+
1. Each new prebuild is initially owned by an unprivileged system pseudo-user named `prebuilds`.
59+
- The `prebuilds` user belongs to the `Everyone` group (you can add it to additional groups if needed).
60+
1. Each Prebuild receives a randomly generated name for identification.
4961

50-
## Claiming
62+
</details>
5163

52-
A prebuilt workspace is automatically and transparently assigned to a user when a:
64+
1. <details><summary>Eligibility process</summary>
5365

54-
- User creates a new workspace via the API or the Coder web UI.
55-
- User selected a preset which has been configured for prebuilds.
56-
- Prebuilt workspace is in an eligible state.
66+
Before a prebuilt workspace is available to users:
5767

58-
The ownership of the prebuilt workspace will change to the requesting user, and this is referred to as a "claim".
68+
1. The workspace is provisioned like a regular workspace.
69+
1. The workspace reaches `running` state.
70+
1. The agent connects and reports `ready` status.
71+
1. All bootstrap procedures and startup scripts complete successfully.
72+
1. The workspace is marked as `eligible` to be claimed.
5973

60-
## Eligibility
74+
Prebuilds that fail during provisioning are retried with an exponential backoff to prevent resource waste.
6175

62-
When a prebuilt workspace is running, and its agent has completed all of its bootstrap procedures and executed its
63-
startup scripts, the workspace will be marked eligible to be claimed.
76+
</details>
6477

65-
## Relationship to workspace presets
78+
1. <details><summary>Claiming process</summary>
6679

67-
[Workspace presets](./parameters.md#workspace-presets-beta) allow you to configure commonly used combinations of
68-
parameters into a single option, which makes it easier for developers to pick one that fits their needs.
80+
When a developer requests a new workspace, the claiming process occurs:
6981

70-
Prebuilt workspaces need to have a preset defined to match the base configuration of a workspace, i.e. the preset
71-
needs to define all the required parameters needed to build a workspace. These parameters are necessary in order to
72-
build workspaces in the background.
82+
1. Developer selects a template and preset that has Prebuilds configured.
83+
1. If an eligible prebuilt workspace exists, it's automatically assigned to the user.
84+
1. Ownership transfers from the `prebuilds` user to the requesting user.
85+
1. The workspace name changes to the user's requested name.
86+
1. The process is transparent to the developer - they simply see a workspace ready faster than normal.
7387

74-
Parameters which are not required or not part of a preset can still be used with prebuilt workspaces.
75-
The preset defines the minimum required set of parameters, and these are immutable.
88+
This ownership transfer happens automatically without any special action required by the user.
7689

77-
## Update a prebuilt workspace
90+
</details>
7891

79-
Prebuilt workspaces are not automatically updated after they are created.
92+
You can view available prebuilt workspaces in the **Workspaces** view in the Coder dashboard:
8093

81-
When a template version changes, all prebuilt workspaces relating to an inactive template version are destroyed.
82-
New prebuilt workspaces will be provisioned for the active template version.
94+
![A prebuilt workspace in the dashboard](../../../images/admin/templates/extend-templates/prebuilt/prebuilt-workspaces.png)
8395

84-
You may want to invalidate a prebuilt workspace when your template version does not change but a referenced dependency does,
85-
which is necessary for running an up-to-date workspace. For example, if
86-
an [AMI](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/AMIs.html) which is referenced by your template is updated,
87-
you can simply delete the prebuilt workspaces, and they will be recreated with the latest AMI.
96+
### Template updates and prebuilt lifecycle
8897

89-
_In future releases, we will allow operators to invalidate their prebuilt workspaces programmatically._
98+
Prebuilt workspaces have specific behavior when templates are updated:
9099

91-
## Quotas
100+
1. When a template version changes, Prebuilds for old versions are automatically deleted.
101+
1. New Prebuilds are created for the active template version.
102+
1. Prebuilds aren't automatically updated after creation.
103+
1. If dependencies change (e.g., an [AMI](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/AMIs.html) update) without a template version change, you can:
104+
- Delete the existing Prebuilds manually.
105+
- Coder will automatically create new prebuilt workspaces with the updated dependencies.
92106

93-
Prebuilt workspaces can be used in conjunction with [Resource Quotas](../../users/quotas.md). Given
94-
that all unclaimed prebuilt workspaces are [owned](#workspace-ownership) by the `prebuilds` user, you may configure a quota for
95-
any group which this user appears in.
107+
The system always maintains the desired number of prebuilt workspaces for the active template version.
96108

97-
Once the quota is exceeded, prebuilt workspaces will fail provisioning like regular workspaces would.
109+
### Relationship to workspace presets
98110

99-
## Current Limitations
111+
Prebuilt workspaces are tightly integrated with [workspace presets](./parameters.md#workspace-presets-beta):
100112

101-
- Organizations
113+
1. Each Prebuild is associated with a specific template preset.
114+
1. The preset must define all required parameters needed to build the workspace.
115+
1. Parameters that are not defined in the preset can still be customized by users when they claim a workspace.
116+
1. The preset parameters define the base configuration and are immutable after they're claimed.
117+
1. Prebuilds help presets deliver even faster workspace creation.
102118

103-
Prebuilt workspaces can only be utilized by the default organization.
119+
_Note: In future releases, we will allow operators to invalidate their prebuilt workspaces programmatically._
104120

105-
[coder/internal#364](https://github.com/coder/internal/issues/364)
121+
## Administration and troubleshooting
106122

107-
- Autoscaling
123+
### Managing resource quotas
108124

109-
Prebuilt workspaces remain running until they are claimed.
110-
We do not currently have an autoscaling mechanism to reduce the number of instances after working hours.
125+
Prebuilt workspaces can be used in conjunction with [resource quotas](../../users/quotas.md).
126+
Because unclaimed prebuilt workspaces are owned by the `prebuilds` user, you can:
111127

112-
[coder/internal#312](https://github.com/coder/internal/issues/312)
128+
1. Configure quotas for any group that includes this user.
129+
1. Set appropriate limits to balance Prebuild availability with resource constraints.
130+
1. Monitor quota utilization through Coder's dashboard.
113131

114-
## Gotchas
132+
If a quota is exceeded, the prebuilt workspace will fail provisioning the same way other workspaces do.
115133

116-
### Resource Replacement
134+
### Template configuration best practices
117135

118-
When a prebuilt workspace is created, it is initially [owned](#workspace-ownership) by the `prebuilds` user and a random name
119-
is generated for it.
120-
When `terraform apply` runs, it will provide these values during provisioning in the
121-
[`coder_workspace`](https://registry.terraform.io/providers/coder/coder/latest/docs/data-sources/workspace) and
122-
[`coder_workspace_owner`](https://registry.terraform.io/providers/coder/coder/latest/docs/data-sources/workspace_owner)
123-
datasources.
136+
#### Preventing resource replacement
124137

125-
Once a prebuilt workspace is claimed, the ownership of that workspace changes to the requesting user and
126-
`terraform apply` is run again, now with updated values for the aforementioned datasources.
138+
When a prebuilt workspace is claimed, Terraform runs again with new values for the workspace owner and name.
127139

128-
If your template has used these datasources in immutable fields (i.e. the
129-
[`user_data`](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/instance#user_data-1) field in
130-
an `aws_instance` resource), Terraform will interpret these changes as _drift_ and will therefore destroy and recreate
131-
the resource.
140+
This can cause issues:
132141

133-
This is obviously undesirable because the prebuilt workspace will now have to provision _again_, while the user waits,
134-
eliminating the value of the prior pre-provisioning.
142+
1. The workspace is initially created with values from the `prebuilds` user and a random name.
143+
1. After claiming, the workspace owner and name change, which Terraform sees as configuration drift.
144+
1. If these values are used in immutable fields, Terraform will destroy and recreate the resource, eliminating the benefit of prebuilds.
135145

136-
Should this occur when a prebuilt workspace is claimed, all Template Admins will receive a notification which will
137-
link them to the build logs to investigate which resource was being replaced.
146+
For example, when these values are used in immutable fields like the AWS instance `user_data`, you'll see resource replacement during claiming:
138147

139148
![Resource replacement notification](../../../images/admin/templates/extend-templates/prebuilt/replacement-notification.png)
140149

141-
To avoid this problem, you will need to add a `lifecycle` block to your resource:
150+
To prevent this, add a `lifecycle` block with `ignore_changes`:
142151

143152
```hcl
144153
resource "docker_container" "workspace" {
@@ -152,14 +161,7 @@ resource "docker_container" "workspace" {
152161
}
153162
```
154163

155-
In the above example, the `docker_container` would be created with a `name` attribute which includes references to the
156-
initial owner (i.e. `prebuilds`), and will never change - even when the values of `data.coder_workspace_owner.me.name`
157-
and `data.coder_workspace.me.name` change in the above example. `name` is immutable like `user_data` above.
158-
159-
You can read more about `ignore_changes`in the [Terraform documentation](https://developer.hashicorp.com/terraform/language/meta-arguments/lifecycle#ignore_changes).
160-
161-
Should certain mutable attributes be required to change, you can use a more targeted approach by providing a list of
162-
attributes to `ignore_changes`:
164+
For more targeted control, specify which attributes to ignore:
163165

164166
```hcl
165167
resource "docker_container" "workspace" {
@@ -173,23 +175,44 @@ resource "docker_container" "workspace" {
173175
}
174176
```
175177

176-
## Troubleshooting
178+
Learn more about `ignore_changes` in the [Terraform documentation](https://developer.hashicorp.com/terraform/language/meta-arguments/lifecycle#ignore_changes).
179+
180+
### Current limitations
181+
182+
The prebuilt workspaces feature has these current limitations:
183+
184+
- **Organizations**
185+
186+
Prebuilt workspaces can only be used with the default organization.
187+
188+
[coder/internal#364](https://github.com/coder/internal/issues/364)
189+
190+
- **Autoscaling**
191+
192+
Prebuilt workspaces remain running until claimed. There's no automated mechanism to reduce instances during off-hours.
193+
194+
[coder/internal#312](https://github.com/coder/internal/issues/312)
195+
196+
### Monitoring and observability
197+
198+
#### Available metrics
199+
200+
Coder provides several metrics to monitor your prebuilt workspaces:
201+
202+
- `coderd_prebuilt_workspaces_created_total` (counter): Total number of prebuilt workspaces created to meet the desired instance count.
203+
- `coderd_prebuilt_workspaces_failed_total` (counter): Total number of prebuilt workspaces that failed to build.
204+
- `coderd_prebuilt_workspaces_claimed_total` (counter): Total number of prebuilt workspaces claimed by users.
205+
- `coderd_prebuilt_workspaces_desired` (gauge): Target number of prebuilt workspaces that should be available.
206+
- `coderd_prebuilt_workspaces_running` (gauge): Current number of prebuilt workspaces in running state.
207+
- `coderd_prebuilt_workspaces_eligible` (gauge): Current number of prebuilt workspaces eligible to be claimed.
177208

178-
### Metrics
209+
#### Logs
179210

180-
- `coderd_prebuilt_workspaces_created_total` (counter): Total number of prebuilt workspaces that have been created to
181-
meet the desired instance count of each template preset
182-
- `coderd_prebuilt_workspaces_failed_total` (counter): Total number of prebuilt workspaces that failed to build
183-
- `coderd_prebuilt_workspaces_claimed_total` (counter): Total number of prebuilt workspaces which were claimed by users.
184-
Claiming refers to creating a workspace with a preset selected for which eligible prebuilt workspaces are available
185-
and one is reassigned to a user
186-
- `coderd_prebuilt_workspaces_desired` (gauge): Target number of prebuilt workspaces that should be available for each
187-
template preset
188-
- `coderd_prebuilt_workspaces_running` (gauge): Current number of prebuilt workspaces that are in a running state. These
189-
workspaces have started successfully but may not yet be claimable by users (see `coderd_prebuilt_workspaces_eligible`)
190-
- `coderd_prebuilt_workspaces_eligible` (gauge): Current number of prebuilt workspaces that are eligible to be claimed
191-
by users. These are workspaces that have completed their build process with their agent reporting 'ready' status
211+
Search for `coderd.prebuilds:` in your logs to track the reconciliation loop's behavior.
192212

193-
### Logs
213+
These logs provide information about:
194214

195-
Search for `coderd.prebuilds:` to gain insight into the behavior of the reconciliation loop.
215+
1. Creation and deletion attempts for prebuilds.
216+
1. Backoff events after failed builds.
217+
1. Eligibility state changes.
218+
1. Claiming operations.

0 commit comments

Comments
 (0)