Skip to content

Commit

Permalink
feat: add healthcheck parameters to coder_app (#52)
Browse files Browse the repository at this point in the history
  • Loading branch information
f0ssel authored Sep 22, 2022
1 parent 9619533 commit 4d7165a
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 22 deletions.
25 changes: 20 additions & 5 deletions docs/resources/app.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,16 @@ EOF
}
resource "coder_app" "code-server" {
agent_id = coder_agent.dev.id
name = "VS Code"
icon = data.coder_workspace.me.access_url + "/icons/vscode.svg"
url = "http://localhost:13337"
relative_path = true
agent_id = coder_agent.dev.id
name = "VS Code"
icon = data.coder_workspace.me.access_url + "/icons/vscode.svg"
url = "http://localhost:13337"
relative_path = true
healthcheck {
url = "http://localhost:13337/healthz"
interval = 5
threshold = 6
}
}
resource "coder_app" "vim" {
Expand Down Expand Up @@ -58,6 +63,7 @@ resource "coder_app" "intellij" {
### Optional

- `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.
- `healthcheck` (Block Set) HTTP health checking to determine the application readiness. (see [below for nested schema](#nestedblock--healthcheck))
- `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>"`.
- `name` (String) A display name to identify the app.
- `relative_path` (Boolean) Specifies whether the URL will be accessed via a relative path or wildcard. Use if wildcard routing is unavailable.
Expand All @@ -67,4 +73,13 @@ resource "coder_app" "intellij" {

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

<a id="nestedblock--healthcheck"></a>
### Nested Schema for `healthcheck`

Required:

- `interval` (Number) Duration in seconds to wait between healthcheck requests.
- `threshold` (Number) Number of consecutive heathcheck failures before returning an unhealthy status.
- `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.


12 changes: 6 additions & 6 deletions docs/resources/metadata.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,25 @@ resource "kubernetes_pod" "dev" {
}
resource "tls_private_key" "example_key_pair" {
algorithm = "ECDSA"
algorithm = "ECDSA"
ecdsa_curve = "P256"
}
resource "coder_metadata" "pod_info" {
count = data.coder_workspace.me.start_count
count = data.coder_workspace.me.start_count
resource_id = kubernetes_pod.dev[0].id
item {
key = "description"
key = "description"
value = "This description will show up in the Coder dashboard."
}
item {
key = "pod_uid"
key = "pod_uid"
value = kubernetes_pod.dev[0].uid
}
item {
key = "public_key"
key = "public_key"
value = tls_private_key.example_key_pair.public_key_openssh
# The value of this item will be hidden from view by default
# The value of this item will be hidden from view by default
sensitive = true
}
}
Expand Down
15 changes: 10 additions & 5 deletions examples/resources/coder_app/resource.tf
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,16 @@ EOF
}

resource "coder_app" "code-server" {
agent_id = coder_agent.dev.id
name = "VS Code"
icon = data.coder_workspace.me.access_url + "/icons/vscode.svg"
url = "http://localhost:13337"
relative_path = true
agent_id = coder_agent.dev.id
name = "VS Code"
icon = data.coder_workspace.me.access_url + "/icons/vscode.svg"
url = "http://localhost:13337"
relative_path = true
healthcheck {
url = "http://localhost:13337/healthz"
interval = 5
threshold = 6
}
}

resource "coder_app" "vim" {
Expand Down
12 changes: 6 additions & 6 deletions examples/resources/coder_metadata/resource.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,25 @@ resource "kubernetes_pod" "dev" {
}

resource "tls_private_key" "example_key_pair" {
algorithm = "ECDSA"
algorithm = "ECDSA"
ecdsa_curve = "P256"
}

resource "coder_metadata" "pod_info" {
count = data.coder_workspace.me.start_count
count = data.coder_workspace.me.start_count
resource_id = kubernetes_pod.dev[0].id
item {
key = "description"
key = "description"
value = "This description will show up in the Coder dashboard."
}
item {
key = "pod_uid"
key = "pod_uid"
value = kubernetes_pod.dev[0].uid
}
item {
key = "public_key"
key = "public_key"
value = tls_private_key.example_key_pair.public_key_openssh
# The value of this item will be hidden from view by default
# The value of this item will be hidden from view by default
sensitive = true
}
}
29 changes: 29 additions & 0 deletions internal/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,35 @@ func New() *schema.Provider {
Optional: true,
ConflictsWith: []string{"command"},
},
"healthcheck": {
Type: schema.TypeSet,
Description: "HTTP health checking to determine the application readiness.",
ForceNew: true,
Optional: true,
ConflictsWith: []string{"command"},
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"url": {
Type: schema.TypeString,
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.",
ForceNew: true,
Required: true,
},
"interval": {
Type: schema.TypeInt,
Description: "Duration in seconds to wait between healthcheck requests.",
ForceNew: true,
Required: true,
},
"threshold": {
Type: schema.TypeInt,
Description: "Number of consecutive heathcheck failures before returning an unhealthy status.",
ForceNew: true,
Required: true,
},
},
},
},
},
},
"coder_metadata": {
Expand Down
5 changes: 5 additions & 0 deletions internal/provider/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,11 @@ func TestApp(t *testing.T) {
icon = "builtin:vim"
relative_path = true
url = "http://localhost:13337"
healthcheck {
url = "http://localhost:13337/healthz"
interval = 5
threshold = 6
}
}
`,
Check: func(state *terraform.State) error {
Expand Down

0 comments on commit 4d7165a

Please sign in to comment.