Skip to content

backport(feat): add 'hidden' field to 'coder_app' provider (#276) #284

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 1 commit into from
Sep 6, 2024
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
1 change: 1 addition & 0 deletions docs/resources/app.md
Original file line number Diff line number Diff line change
@@ -63,6 +63,7 @@ resource "coder_app" "vim" {
- `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))
- `hidden` (Boolean) Determines if the app is visible in the UI.
- `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/icon. Use a built-in icon with `"${data.coder_workspace.me.access_url}/icon/<path>"`.
- `name` (String, **Deprecated**: `name` on apps is deprecated, use `display_name` instead) A display name to identify the app.
- `order` (Number) The order determines the position of app in the UI presentation. The lowest order is shown first and apps with equal order are sorted by name (ascending order).
62 changes: 62 additions & 0 deletions integration/coder-app-hidden/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
terraform {
required_providers {
coder = {
source = "coder/coder"
}
local = {
source = "hashicorp/local"
}
}
}

data "coder_workspace" "me" {}

resource "coder_agent" "dev" {
os = "linux"
arch = "amd64"
dir = "/workspace"
}

resource "coder_app" "hidden" {
agent_id = coder_agent.dev.id
slug = "hidden"
share = "owner"
hidden = true
}

resource "coder_app" "visible" {
agent_id = coder_agent.dev.id
slug = "visible"
share = "owner"
hidden = false
}

resource "coder_app" "defaulted" {
agent_id = coder_agent.dev.id
slug = "defaulted"
share = "owner"
}

locals {
# NOTE: these must all be strings in the output
output = {
"coder_app.hidden.hidden" = tostring(coder_app.hidden.hidden)
"coder_app.visible.hidden" = tostring(coder_app.visible.hidden)
"coder_app.defaulted.hidden" = tostring(coder_app.defaulted.hidden)
}
}

variable "output_path" {
type = string
}

resource "local_file" "output" {
filename = var.output_path
content = jsonencode(local.output)
}

output "output" {
value = local.output
sensitive = true
}

9 changes: 9 additions & 0 deletions integration/integration_test.go
Original file line number Diff line number Diff line change
@@ -126,6 +126,15 @@ func TestIntegration(t *testing.T) {
"workspace_owner.ssh_public_key": `(?s)^ssh-ed25519.+$`,
},
},
{
name: "coder-app-hidden",
minVersion: "v0.0.0",
expectedOutput: map[string]string{
"coder_app.hidden.hidden": "true",
"coder_app.visible.hidden": "false",
"coder_app.defaulted.hidden": "false",
},
},
} {
tt := tt
t.Run(tt.name, func(t *testing.T) {
38 changes: 37 additions & 1 deletion provider/app.go
Original file line number Diff line number Diff line change
@@ -30,7 +30,36 @@ func appResource() *schema.Resource {
Description: "Use this resource to define shortcuts to access applications in a workspace.",
CreateContext: func(c context.Context, resourceData *schema.ResourceData, i interface{}) diag.Diagnostics {
resourceData.SetId(uuid.NewString())
return nil

diags := diag.Diagnostics{}

hiddenData := resourceData.Get("hidden")
if hidden, ok := hiddenData.(bool); !ok {
return diag.Errorf("hidden should be a bool")
} else if hidden {
if _, ok := resourceData.GetOk("display_name"); ok {
diags = append(diags, diag.Diagnostic{
Severity: diag.Warning,
Summary: "`display_name` set when app is hidden",
})
}

if _, ok := resourceData.GetOk("icon"); ok {
diags = append(diags, diag.Diagnostic{
Severity: diag.Warning,
Summary: "`icon` set when app is hidden",
})
}

if _, ok := resourceData.GetOk("order"); ok {
diags = append(diags, diag.Diagnostic{
Severity: diag.Warning,
Summary: "`order` set when app is hidden",
})
}
}

return diags
},
ReadContext: func(c context.Context, resourceData *schema.ResourceData, i interface{}) diag.Diagnostics {
return nil
@@ -204,6 +233,13 @@ func appResource() *schema.Resource {
ForceNew: true,
Optional: true,
},
"hidden": {
Type: schema.TypeBool,
Description: "Determines if the app is visible in the UI.",
Default: false,
ForceNew: true,
Optional: true,
},
},
}
}
73 changes: 73 additions & 0 deletions provider/app_test.go
Original file line number Diff line number Diff line change
@@ -45,6 +45,7 @@ func TestApp(t *testing.T) {
threshold = 6
}
order = 4
hidden = false
}
`,
Check: func(state *terraform.State) error {
@@ -66,6 +67,7 @@ func TestApp(t *testing.T) {
"healthcheck.0.interval",
"healthcheck.0.threshold",
"order",
"hidden",
} {
value := resource.Primary.Attributes[key]
t.Logf("%q = %q", key, value)
@@ -246,4 +248,75 @@ func TestApp(t *testing.T) {
})
}
})

t.Run("Hidden", func(t *testing.T) {
t.Parallel()

cases := []struct {
name string
config string
hidden bool
}{{
name: "Is Hidden",
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
hidden = true
}
`,
hidden: true,
}, {
name: "Is Not Hidden",
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
hidden = false
}
`,
hidden: false,
}}
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.hidden), resource.Primary.Attributes["hidden"])
return nil
},
ExpectError: nil,
}},
})
})
}
})

}