diff --git a/docs/resources/app.md b/docs/resources/app.md index 698f52a5..cddc1fe8 100644 --- a/docs/resources/app.md +++ b/docs/resources/app.md @@ -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/"`. - `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. + +### 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. + diff --git a/docs/resources/metadata.md b/docs/resources/metadata.md index 16c8e6be..a4e7e59e 100644 --- a/docs/resources/metadata.md +++ b/docs/resources/metadata.md @@ -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 } } diff --git a/examples/resources/coder_app/resource.tf b/examples/resources/coder_app/resource.tf index d72a0047..6f4a34dd 100644 --- a/examples/resources/coder_app/resource.tf +++ b/examples/resources/coder_app/resource.tf @@ -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" { diff --git a/examples/resources/coder_metadata/resource.tf b/examples/resources/coder_metadata/resource.tf index 73222c8b..934928a1 100644 --- a/examples/resources/coder_metadata/resource.tf +++ b/examples/resources/coder_metadata/resource.tf @@ -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 } } diff --git a/internal/provider/provider.go b/internal/provider/provider.go index 2829ed50..9caf6bf6 100644 --- a/internal/provider/provider.go +++ b/internal/provider/provider.go @@ -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": { diff --git a/internal/provider/provider_test.go b/internal/provider/provider_test.go index 2e7acbbb..c9dc55e3 100644 --- a/internal/provider/provider_test.go +++ b/internal/provider/provider_test.go @@ -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 {