@@ -121,6 +121,18 @@ variable "auto_install_extensions" {
121121 default = false
122122}
123123
124+ variable "subdomain" {
125+ type = bool
126+ description = <<- EOT
127+ Determines whether the app will be accessed via it's own subdomain or whether it will be accessed via a path on Coder.
128+ If wildcards have not been setup by the administrator then apps with "subdomain" set to true will not be accessible.
129+ EOT
130+ default = true
131+ }
132+
133+ data "coder_workspace_owner" "me" {}
134+ data "coder_workspace" "me" {}
135+
124136resource "coder_script" "vscode-web" {
125137 agent_id = var. agent_id
126138 display_name = " VS Code Web"
@@ -138,6 +150,7 @@ resource "coder_script" "vscode-web" {
138150 EXTENSIONS_DIR : var.extensions_dir,
139151 FOLDER : var.folder,
140152 AUTO_INSTALL_EXTENSIONS : var.auto_install_extensions,
153+ SERVER_BASE_PATH : local.server_base_path,
141154 })
142155 run_on_start = true
143156
@@ -158,15 +171,21 @@ resource "coder_app" "vscode-web" {
158171 agent_id = var. agent_id
159172 slug = var. slug
160173 display_name = var. display_name
161- url = var . folder == " " ? " http://localhost: ${ var . port } " : " http://localhost: ${ var . port } ?folder= ${ var . folder } "
174+ url = local . url
162175 icon = " /icon/code.svg"
163- subdomain = true
176+ subdomain = var . subdomain
164177 share = var. share
165178 order = var. order
166179
167180 healthcheck {
168- url = " http://localhost: ${ var . port } /healthz "
181+ url = local . healthcheck_url
169182 interval = 5
170183 threshold = 6
171184 }
172185}
186+
187+ locals {
188+ server_base_path = var. subdomain ? " " : format (" /@%s/%s/apps/%s/" , data. coder_workspace_owner . me . name , data. coder_workspace . me . name , var. slug )
189+ url = var. folder == " " ? " http://localhost:${ var . port } ${ local . server_base_path } " : " http://localhost:${ var . port } ${ local . server_base_path } ?folder=${ var . folder } "
190+ healthcheck_url = var. subdomain ? " http://localhost:${ var . port } /healthz" : " http://localhost:${ var . port } ${ local . server_base_path } /healthz"
191+ }
0 commit comments