@@ -117,7 +117,7 @@ variable "install_agentapi" {
117117variable "agentapi_version" {
118118 type = string
119119 description = " The version of AgentAPI to install."
120- default = " v0.2 .3"
120+ default = " v0.3 .3"
121121}
122122
123123variable "agentapi_port" {
@@ -126,6 +126,31 @@ variable "agentapi_port" {
126126 default = 3284
127127}
128128
129+ locals {
130+ # agentapi_subdomain_false_min_version_expr matches a semantic version >= v0.3.3.
131+ # Initial support was added in v0.3.1 but configuration via environment variable
132+ # was added in v0.3.3.
133+ # This is unfortunately a regex because there is no builtin way to compare semantic versions in Terraform.
134+ # See: https://regex101.com/r/oHPyRa/1
135+ agentapi_subdomain_false_min_version_expr = " ^v(0\\ .(3\\ .[3-9]|3.[1-9]\\ d+|[4-9]\\ .\\ d+|[1-9]\\ d+\\ .\\ d+)|[1-9]\\ d*\\ .\\ d+\\ .\\ d+)$"
136+ }
137+
138+ variable "agentapi_subdomain" {
139+ type = bool
140+ description = " Whether to use a subdomain for AgentAPI."
141+ default = true
142+ validation {
143+ condition = var. agentapi_subdomain || (
144+ # If version doesn't look like a valid semantic version, just allow it.
145+ # Note that boolean operators do not short-circuit in Terraform.
146+ can (regex (" ^v\\ d+\\ .\\ d+\\ .\\ d+$" , var. agentapi_version )) ?
147+ can (regex (local. agentapi_subdomain_false_min_version_expr , var. agentapi_version )) :
148+ true
149+ )
150+ error_message = " Running with subdomain = false is only supported by agentapi >= v0.3.3."
151+ }
152+ }
153+
129154variable "module_dir_name" {
130155 type = string
131156 description = " Name of the subdirectory in the home directory for module files."
@@ -140,7 +165,14 @@ locals {
140165 encoded_post_install_script = var. post_install_script != null ? base64encode (var. post_install_script ) : " "
141166 agentapi_start_script_b64 = base64encode (var. start_script )
142167 agentapi_wait_for_start_script_b64 = base64encode (file (" ${ path . module } /scripts/agentapi-wait-for-start.sh" ))
143- main_script = file (" ${ path . module } /scripts/main.sh" )
168+ // Chat base path is only set if not using a subdomain.
169+ // NOTE:
170+ // - Initial support for --chat-base-path was added in v0.3.1 but configuration
171+ // via environment variable AGENTAPI_CHAT_BASE_PATH was added in v0.3.3.
172+ // - As CODER_WORKSPACE_AGENT_NAME is a recent addition we use agent ID
173+ // for backward compatibility.
174+ agentapi_chat_base_path = var. agentapi_subdomain ? " " : " /@${ data . coder_workspace_owner . me . name } /${ data . coder_workspace . me . name } .${ var . agent_id } /apps/${ var . web_app_slug } /chat"
175+ main_script = file (" ${ path . module } /scripts/main.sh" )
144176}
145177
146178resource "coder_script" "agentapi" {
@@ -165,6 +197,7 @@ resource "coder_script" "agentapi" {
165197 ARG_WAIT_FOR_START_SCRIPT="$(echo -n '${ local . agentapi_wait_for_start_script_b64 } ' | base64 -d)" \
166198 ARG_POST_INSTALL_SCRIPT="$(echo -n '${ local . encoded_post_install_script } ' | base64 -d)" \
167199 ARG_AGENTAPI_PORT='${ var . agentapi_port } ' \
200+ ARG_AGENTAPI_CHAT_BASE_PATH='${ local . agentapi_chat_base_path } ' \
168201 /tmp/main.sh
169202 EOT
170203 run_on_start = true
@@ -178,7 +211,7 @@ resource "coder_app" "agentapi_web" {
178211 icon = var. web_app_icon
179212 order = var. web_app_order
180213 group = var. web_app_group
181- subdomain = true
214+ subdomain = var . agentapi_subdomain
182215 healthcheck {
183216 url = " http://localhost:${ var . agentapi_port } /status"
184217 interval = 3
0 commit comments