- Notifications
You must be signed in to change notification settings - Fork22
add open_in option to coder_app#321
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
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""window" { | ||
agent_id=coder_agent.dev.id | ||
slug="window" | ||
share="owner" | ||
open_in="window" | ||
} | ||
resource"coder_app""slim-window" { | ||
agent_id=coder_agent.dev.id | ||
slug="slim-window" | ||
share="owner" | ||
open_in="slim-window" | ||
} | ||
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.window.open_in"=tostring(coder_app.window.open_in) | ||
"coder_app.slim-window.open_in"=tostring(coder_app.slim-window.open_in) | ||
"coder_app.defaulted.open_in"=tostring(coder_app.defaulted.open_in) | ||
} | ||
} | ||
variable"output_path" { | ||
type=string | ||
} | ||
resource"local_file""output" { | ||
filename=var.output_path | ||
content=jsonencode(local.output) | ||
} | ||
output"output" { | ||
value=local.output | ||
sensitive=true | ||
} | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -223,6 +223,28 @@ func appResource() *schema.Resource { | ||
ForceNew:true, | ||
Optional:true, | ||
}, | ||
"open_in": { | ||
Type:schema.TypeString, | ||
Description:"Determines where the app will be opened. Valid values are `\"tab\"`, `\"window\"`, and `\"slim-window\" (default)`. "+ | ||
"`\"tab\"` opens in a new tab in the same browser window. `\"window\"` opens a fresh browser window with navigation options. "+ | ||
defelmnq marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
"`\"slim-window\"` opens a new browser window without navigation controls.", | ||
ForceNew:true, | ||
Optional:true, | ||
Default:"slim-window", | ||
ValidateDiagFunc:func(valinterface{},c cty.Path) diag.Diagnostics { | ||
valStr,ok:=val.(string) | ||
if!ok { | ||
returndiag.Errorf("expected string, got %T",val) | ||
} | ||
switchvalStr { | ||
case"tab","window","slim-window": | ||
returnnil | ||
} | ||
returndiag.Errorf(`invalid "coder_app" open_in value, must be one of "tab", "window", "slim-window": %q`,valStr) | ||
}, | ||
}, | ||
}, | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -42,6 +42,7 @@ func TestApp(t *testing.T) { | ||
} | ||
order = 4 | ||
hidden = false | ||
open_in = "slim-window" | ||
} | ||
`, | ||
Check:func(state*terraform.State)error { | ||
@@ -64,6 +65,7 @@ func TestApp(t *testing.T) { | ||
"healthcheck.0.threshold", | ||
"order", | ||
"hidden", | ||
"open_in", | ||
} { | ||
value:=resource.Primary.Attributes[key] | ||
t.Logf("%q = %q",key,value) | ||
@@ -98,6 +100,7 @@ func TestApp(t *testing.T) { | ||
display_name = "Testing" | ||
url = "https://google.com" | ||
external = true | ||
open_in = "slim-window" | ||
} | ||
`, | ||
external:true, | ||
@@ -116,6 +119,7 @@ func TestApp(t *testing.T) { | ||
url = "https://google.com" | ||
external = true | ||
subdomain = true | ||
open_in = "slim-window" | ||
} | ||
`, | ||
expectError:regexp.MustCompile("conflicts with subdomain"), | ||
@@ -209,6 +213,7 @@ func TestApp(t *testing.T) { | ||
interval = 5 | ||
threshold = 6 | ||
} | ||
open_in = "slim-window" | ||
} | ||
`,sharingLine) | ||
@@ -241,13 +246,114 @@ func TestApp(t *testing.T) { | ||
} | ||
}) | ||
t.Run("OpenIn",func(t*testing.T) { | ||
t.Parallel() | ||
cases:= []struct { | ||
namestring | ||
valuestring | ||
expectValuestring | ||
expectError*regexp.Regexp | ||
}{ | ||
{ | ||
name:"default", | ||
value:"",// default | ||
expectValue:"slim-window", | ||
}, | ||
{ | ||
name:"InvalidValue", | ||
value:"nonsense", | ||
expectError:regexp.MustCompile(`invalid "coder_app" open_in value, must be one of "tab", "window", "slim-window": "nonsense"`), | ||
}, | ||
{ | ||
name:"ExplicitWindow", | ||
value:"window", | ||
expectValue:"window", | ||
}, | ||
{ | ||
name:"ExplicitSlimWindow", | ||
value:"slim-window", | ||
expectValue:"slim-window", | ||
}, | ||
{ | ||
name:"ExplicitTab", | ||
value:"tab", | ||
expectValue:"tab", | ||
}, | ||
} | ||
for_,c:=rangecases { | ||
c:=c | ||
t.Run(c.name,func(t*testing.T) { | ||
t.Parallel() | ||
config:=` | ||
provider "coder" { | ||
} | ||
resource "coder_agent" "dev" { | ||
os = "linux" | ||
arch = "amd64" | ||
} | ||
resource "coder_app" "code-server" { | ||
agent_id = coder_agent.dev.id | ||
slug = "code-server" | ||
display_name = "code-server" | ||
icon = "builtin:vim" | ||
url = "http://localhost:13337" | ||
healthcheck { | ||
url = "http://localhost:13337/healthz" | ||
interval = 5 | ||
threshold = 6 | ||
}` | ||
ifc.value!="" { | ||
config+=fmt.Sprintf(` | ||
open_in = %q | ||
`,c.value) | ||
} | ||
config+=` | ||
} | ||
` | ||
checkFn:=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.code-server"] | ||
require.NotNil(t,resource) | ||
// Read share and ensure it matches the expected | ||
// value. | ||
value:=resource.Primary.Attributes["open_in"] | ||
require.Equal(t,c.expectValue,value) | ||
returnnil | ||
} | ||
ifc.expectError!=nil { | ||
checkFn=nil | ||
} | ||
resource.Test(t, resource.TestCase{ | ||
ProviderFactories:coderFactory(), | ||
IsUnitTest:true, | ||
Steps: []resource.TestStep{{ | ||
Config:config, | ||
Check:checkFn, | ||
ExpectError:c.expectError, | ||
}}, | ||
}) | ||
}) | ||
} | ||
}) | ||
t.Run("Hidden",func(t*testing.T) { | ||
t.Parallel() | ||
cases:= []struct { | ||
namestring | ||
configstring | ||
hiddenbool | ||
openInstring | ||
}{{ | ||
name:"Is Hidden", | ||
config:` | ||
@@ -263,9 +369,11 @@ func TestApp(t *testing.T) { | ||
url = "https://google.com" | ||
external = true | ||
hidden = true | ||
open_in = "slim-window" | ||
} | ||
`, | ||
hidden:true, | ||
openIn:"slim-window", | ||
defelmnq marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
}, { | ||
name:"Is Not Hidden", | ||
config:` | ||
@@ -281,9 +389,11 @@ func TestApp(t *testing.T) { | ||
url = "https://google.com" | ||
external = true | ||
hidden = false | ||
open_in = "window" | ||
} | ||
`, | ||
hidden:false, | ||
openIn:"window", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. You may want to add this also to examples, see:https://github.com/coder/terraform-provider-coder/blob/main/examples/resources/coder_app/resource.tf | ||
}} | ||
for_,tc:=rangecases { | ||
tc:=tc | ||
@@ -300,6 +410,7 @@ func TestApp(t *testing.T) { | ||
resource:=state.Modules[0].Resources["coder_app.test"] | ||
require.NotNil(t,resource) | ||
require.Equal(t,strconv.FormatBool(tc.hidden),resource.Primary.Attributes["hidden"]) | ||
require.Equal(t,tc.openIn,resource.Primary.Attributes["open_in"]) | ||
returnnil | ||
}, | ||
ExpectError:nil, | ||
Uh oh!
There was an error while loading.Please reload this page.