Skip to content

Commit 4d7165a

Browse files
authored
feat: add healthcheck parameters to coder_app (#52)
1 parent 9619533 commit 4d7165a

File tree

6 files changed

+76
-22
lines changed

6 files changed

+76
-22
lines changed

Diff for: docs/resources/app.md

+20-5
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,16 @@ EOF
2626
}
2727
2828
resource "coder_app" "code-server" {
29-
agent_id = coder_agent.dev.id
30-
name = "VS Code"
31-
icon = data.coder_workspace.me.access_url + "/icons/vscode.svg"
32-
url = "http://localhost:13337"
33-
relative_path = true
29+
agent_id = coder_agent.dev.id
30+
name = "VS Code"
31+
icon = data.coder_workspace.me.access_url + "/icons/vscode.svg"
32+
url = "http://localhost:13337"
33+
relative_path = true
34+
healthcheck {
35+
url = "http://localhost:13337/healthz"
36+
interval = 5
37+
threshold = 6
38+
}
3439
}
3540
3641
resource "coder_app" "vim" {
@@ -58,6 +63,7 @@ resource "coder_app" "intellij" {
5863
### Optional
5964

6065
- `command` (String) A command to run in a terminal opening this app. In the web, this will open in a new tab. In the CLI, this will SSH and execute the command. Either "command" or "url" may be specified, but not both.
66+
- `healthcheck` (Block Set) HTTP health checking to determine the application readiness. (see [below for nested schema](#nestedblock--healthcheck))
6167
- `icon` (String) A URL to an icon that will display in the dashboard. View built-in icons here: https://github.com/coder/coder/tree/main/site/static/icons. Use a built-in icon with `data.coder_workspace.me.access_url + "/icons/<path>"`.
6268
- `name` (String) A display name to identify the app.
6369
- `relative_path` (Boolean) Specifies whether the URL will be accessed via a relative path or wildcard. Use if wildcard routing is unavailable.
@@ -67,4 +73,13 @@ resource "coder_app" "intellij" {
6773

6874
- `id` (String) The ID of this resource.
6975

76+
<a id="nestedblock--healthcheck"></a>
77+
### Nested Schema for `healthcheck`
78+
79+
Required:
80+
81+
- `interval` (Number) Duration in seconds to wait between healthcheck requests.
82+
- `threshold` (Number) Number of consecutive heathcheck failures before returning an unhealthy status.
83+
- `url` (String) HTTP address used determine the application readiness. A successful health check is a HTTP response code less than 500 returned before healthcheck.interval seconds.
84+
7085

Diff for: docs/resources/metadata.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -21,25 +21,25 @@ resource "kubernetes_pod" "dev" {
2121
}
2222
2323
resource "tls_private_key" "example_key_pair" {
24-
algorithm = "ECDSA"
24+
algorithm = "ECDSA"
2525
ecdsa_curve = "P256"
2626
}
2727
2828
resource "coder_metadata" "pod_info" {
29-
count = data.coder_workspace.me.start_count
29+
count = data.coder_workspace.me.start_count
3030
resource_id = kubernetes_pod.dev[0].id
3131
item {
32-
key = "description"
32+
key = "description"
3333
value = "This description will show up in the Coder dashboard."
3434
}
3535
item {
36-
key = "pod_uid"
36+
key = "pod_uid"
3737
value = kubernetes_pod.dev[0].uid
3838
}
3939
item {
40-
key = "public_key"
40+
key = "public_key"
4141
value = tls_private_key.example_key_pair.public_key_openssh
42-
# The value of this item will be hidden from view by default
42+
# The value of this item will be hidden from view by default
4343
sensitive = true
4444
}
4545
}

Diff for: examples/resources/coder_app/resource.tf

+10-5
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,16 @@ EOF
1111
}
1212

1313
resource "coder_app" "code-server" {
14-
agent_id = coder_agent.dev.id
15-
name = "VS Code"
16-
icon = data.coder_workspace.me.access_url + "/icons/vscode.svg"
17-
url = "http://localhost:13337"
18-
relative_path = true
14+
agent_id = coder_agent.dev.id
15+
name = "VS Code"
16+
icon = data.coder_workspace.me.access_url + "/icons/vscode.svg"
17+
url = "http://localhost:13337"
18+
relative_path = true
19+
healthcheck {
20+
url = "http://localhost:13337/healthz"
21+
interval = 5
22+
threshold = 6
23+
}
1924
}
2025

2126
resource "coder_app" "vim" {

Diff for: examples/resources/coder_metadata/resource.tf

+6-6
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,25 @@ resource "kubernetes_pod" "dev" {
66
}
77

88
resource "tls_private_key" "example_key_pair" {
9-
algorithm = "ECDSA"
9+
algorithm = "ECDSA"
1010
ecdsa_curve = "P256"
1111
}
1212

1313
resource "coder_metadata" "pod_info" {
14-
count = data.coder_workspace.me.start_count
14+
count = data.coder_workspace.me.start_count
1515
resource_id = kubernetes_pod.dev[0].id
1616
item {
17-
key = "description"
17+
key = "description"
1818
value = "This description will show up in the Coder dashboard."
1919
}
2020
item {
21-
key = "pod_uid"
21+
key = "pod_uid"
2222
value = kubernetes_pod.dev[0].uid
2323
}
2424
item {
25-
key = "public_key"
25+
key = "public_key"
2626
value = tls_private_key.example_key_pair.public_key_openssh
27-
# The value of this item will be hidden from view by default
27+
# The value of this item will be hidden from view by default
2828
sensitive = true
2929
}
3030
}

Diff for: internal/provider/provider.go

+29
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,35 @@ func New() *schema.Provider {
373373
Optional: true,
374374
ConflictsWith: []string{"command"},
375375
},
376+
"healthcheck": {
377+
Type: schema.TypeSet,
378+
Description: "HTTP health checking to determine the application readiness.",
379+
ForceNew: true,
380+
Optional: true,
381+
ConflictsWith: []string{"command"},
382+
Elem: &schema.Resource{
383+
Schema: map[string]*schema.Schema{
384+
"url": {
385+
Type: schema.TypeString,
386+
Description: "HTTP address used determine the application readiness. A successful health check is a HTTP response code less than 500 returned before healthcheck.interval seconds.",
387+
ForceNew: true,
388+
Required: true,
389+
},
390+
"interval": {
391+
Type: schema.TypeInt,
392+
Description: "Duration in seconds to wait between healthcheck requests.",
393+
ForceNew: true,
394+
Required: true,
395+
},
396+
"threshold": {
397+
Type: schema.TypeInt,
398+
Description: "Number of consecutive heathcheck failures before returning an unhealthy status.",
399+
ForceNew: true,
400+
Required: true,
401+
},
402+
},
403+
},
404+
},
376405
},
377406
},
378407
"coder_metadata": {

Diff for: internal/provider/provider_test.go

+5
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,11 @@ func TestApp(t *testing.T) {
221221
icon = "builtin:vim"
222222
relative_path = true
223223
url = "http://localhost:13337"
224+
healthcheck {
225+
url = "http://localhost:13337/healthz"
226+
interval = 5
227+
threshold = 6
228+
}
224229
}
225230
`,
226231
Check: func(state *terraform.State) error {

0 commit comments

Comments
 (0)