diff --git a/docs/resources/app.md b/docs/resources/app.md index 95f09028..3659b6e3 100644 --- a/docs/resources/app.md +++ b/docs/resources/app.md @@ -69,6 +69,7 @@ resource "coder_app" "intellij" { - `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. - `display_name` (String) A display name to identify the app. Defaults to the slug. +- `external` (Boolean) Specifies whether "url" is opened on the client machine instead of proxied through the workspace. - `healthcheck` (Block Set, Max: 1) 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, Deprecated) A display name to identify the app. diff --git a/docs/resources/metadata.md b/docs/resources/metadata.md index 0c6d068d..e509808e 100644 --- a/docs/resources/metadata.md +++ b/docs/resources/metadata.md @@ -29,7 +29,7 @@ resource "coder_metadata" "pod_info" { count = data.coder_workspace.me.start_count resource_id = kubernetes_pod.dev[0].id # (Enterprise-only) this resource consumes 200 quota units - cost = 200 + daily_cost = 200 item { key = "description" value = "This description will show up in the Coder dashboard." diff --git a/provider/app.go b/provider/app.go index af8b98d0..ec2ab371 100644 --- a/provider/app.go +++ b/provider/app.go @@ -156,6 +156,15 @@ func appResource() *schema.Resource { Optional: true, ConflictsWith: []string{"command"}, }, + "external": { + Type: schema.TypeBool, + Description: "Specifies whether \"url\" is opened on the client machine " + + "instead of proxied through the workspace.", + Default: false, + ForceNew: true, + Optional: true, + ConflictsWith: []string{"healthcheck", "command", "subdomain", "share"}, + }, "healthcheck": { Type: schema.TypeSet, Description: "HTTP health checking to determine the application readiness.", diff --git a/provider/app_test.go b/provider/app_test.go index 25bb7c17..3d4f44bb 100644 --- a/provider/app_test.go +++ b/provider/app_test.go @@ -3,6 +3,7 @@ package provider_test import ( "fmt" "regexp" + "strconv" "testing" "github.com/coder/terraform-provider-coder/provider" @@ -75,6 +76,76 @@ func TestApp(t *testing.T) { }) }) + t.Run("External", func(t *testing.T) { + t.Parallel() + + cases := []struct { + name string + config string + external bool + expectError *regexp.Regexp + }{{ + name: "Valid", + config: ` + provider "coder" {} + resource "coder_agent" "dev" { + os = "linux" + arch = "amd64" + } + resource "coder_app" "test" { + agent_id = coder_agent.dev.id + slug = "test" + display_name = "Testing" + url = "https://google.com" + external = true + } + `, + external: true, + }, { + name: "ConflictsWithSubdomain", + config: ` + provider "coder" {} + resource "coder_agent" "dev" { + os = "linux" + arch = "amd64" + } + resource "coder_app" "test" { + agent_id = coder_agent.dev.id + slug = "test" + display_name = "Testing" + url = "https://google.com" + external = true + subdomain = true + } + `, + expectError: regexp.MustCompile("conflicts with subdomain"), + }} + for _, tc := range cases { + tc := tc + t.Run(tc.name, func(t *testing.T) { + t.Parallel() + resource.Test(t, resource.TestCase{ + Providers: map[string]*schema.Provider{ + "coder": provider.New(), + }, + IsUnitTest: true, + Steps: []resource.TestStep{{ + Config: tc.config, + Check: func(state *terraform.State) error { + require.Len(t, state.Modules, 1) + require.Len(t, state.Modules[0].Resources, 2) + resource := state.Modules[0].Resources["coder_app.test"] + require.NotNil(t, resource) + require.Equal(t, strconv.FormatBool(tc.external), resource.Primary.Attributes["external"]) + return nil + }, + ExpectError: tc.expectError, + }}, + }) + }) + } + }) + t.Run("SharingLevel", func(t *testing.T) { t.Parallel()