Skip to content

Commit 0ba49be

Browse files
committed
fixup! docs: better explain persistent resources
1 parent ea58254 commit 0ba49be

File tree

2 files changed

+16
-17
lines changed

2 files changed

+16
-17
lines changed

docs/manifest.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,8 @@
104104
"title": "Resource Persistence",
105105
"description": "Learn how resource persistence works in Coder",
106106
"path": "./templates/resource-persistence.md",
107-
"icon_path": "./images/icons/infinity.svg"
107+
"icon_path": "./images/icons/infinity.svg",
108+
"last_updated": "2022-10-23"
108109
},
109110
{
110111
"title": "Provider Authentication",

docs/templates/resource-persistence.md

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Resource Persistence
22

3-
Coder doesn't prescribe your workspace's level of ephemerality. In a
3+
Coder templates have full control over workspace ephemerality. In a
44
completely ephemeral workspace, there are zero resources in the On state. In
55
a completely persistent workspace, there is no difference between the Off and
66
On states.
@@ -9,13 +9,14 @@ Most workspaces fall somewhere in the middle, persisting user data
99
such as filesystem volumes, but deleting expensive, reproducible resources
1010
such as compute instances.
1111

12-
By default, all Coder resources are persistent, but there are practices all
13-
production templates **must** employ to prevent accidental deletion.
12+
By default, all Coder resources are persistent, but
13+
production templates **must** employ the practices laid out in this document
14+
to prevent accidental deletion.
1415

1516
## Disabling Persistence
1617

1718
The [`coder_workspace` data source](https://registry.terraform.io/providers/coder/coder/latest/docs/data-sources/workspace) exposes the `start_count = [0 | 1]` attribute that other
18-
resources use to become ephemeral.
19+
resources reference to become ephemeral.
1920

2021
For example:
2122

@@ -24,7 +25,7 @@ data "coder_workspace" "me" {
2425
}
2526
2627
resource "docker_container" "workspace" {
27-
# ephemeral resource (deleted when workspace is stopped, created when started)
28+
# When `start_count` is 0, `count` is 0, so no `docker_container` is created.
2829
count = data.coder_workspace.me.start_count # 0 (stopped), 1 (started)
2930
# ... other config
3031
}
@@ -39,16 +40,15 @@ data "coder_workspace" "me" {
3940
}
4041
4142
resource "docker_volume" "home_volume" {
42-
# Coder will recreate and wipe this volume if the owner changes their username.
4343
name = "coder-${data.coder_workspace.me.owner}-home"
4444
}
4545
```
4646

47-
Because we depend on `coder_workspace.me.owner`, if the owner changed their
48-
username, Terraform would recreate the volume (wiping the data) the next
49-
time the workspace restarted.
47+
Because we depend on `coder_workspace.me.owner`, if the owner changes their
48+
username, Terraform would recreate the volume (wiping its data!) the next
49+
time the workspace restarts.
5050

51-
Thus, persistent resource names must depend on immutable IDs such as:
51+
Therefore, persistent resource names must only depend on immutable IDs such as:
5252
* `coder_workspace.me.owner_id`
5353
* `coder_workspace.me.id`
5454

@@ -63,13 +63,11 @@ resource "docker_volume" "home_volume" {
6363
}
6464
```
6565

66-
## Bulletproofing
67-
Even if we depend exclusively static IDs, a change to the `name` format or other
68-
attributes would cause Terraform to rebuild the resource.
69-
70-
Bulletproof persistent resources by setting the [`ignore_changes = all` directive in the `lifecycle` block](https://developer.hashicorp.com/terraform/language/meta-arguments/lifecycle#ignore_changes). This
71-
setting prevents Terraform from recreating the resource under any circumstance.
66+
## 🛡 Bulletproofing
67+
Even if our persistent resource depends exclusively on static IDs, a change to
68+
the `name` format or other attributes would cause Terraform to rebuild the resource.
7269

70+
Prevent Terraform from recreating the resource under any circumstance by setting the [`ignore_changes = all` directive in the `lifecycle` block](https://developer.hashicorp.com/terraform/language/meta-arguments/lifecycle#ignore_changes).
7371

7472
```hcl
7573
data "coder_workspace" "me" {

0 commit comments

Comments
 (0)