Skip to content

feat: add healthcheck parameters to coder_app #52

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Sep 22, 2022
Merged
Changes from all commits
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
25 changes: 20 additions & 5 deletions docs/resources/app.md
Original file line number Diff line number Diff line change
@@ -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" {
@@ -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.
@@ -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
@@ -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
}
}
15 changes: 10 additions & 5 deletions examples/resources/coder_app/resource.tf
Original file line number Diff line number Diff line change
@@ -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" {
12 changes: 6 additions & 6 deletions examples/resources/coder_metadata/resource.tf
Original file line number Diff line number Diff line change
@@ -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
@@ -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,
},
Comment on lines +390 to +401
Copy link
Member

Choose a reason for hiding this comment

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

One minor nit before merge, should we make these optional instead with reasonable defaults?

Also Kubernetes calls this period instead of interval. I'm impartial, just wanted to toss the idea up.

},
},
},
},
},
"coder_metadata": {
5 changes: 5 additions & 0 deletions internal/provider/provider_test.go
Original file line number Diff line number Diff line change
@@ -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 {