@@ -23,16 +23,36 @@ variable "subdomain" {
23
23
default = true
24
24
}
25
25
26
+ variable "config" {
27
+ type = any
28
+ description = " A map of pgAdmin configuration settings."
29
+ default = {
30
+ DEFAULT_EMAIL
= " [email protected] "
31
+ DEFAULT_PASSWORD = " coderPASSWORD"
32
+ SERVER_MODE = false
33
+ MASTER_PASSWORD_REQUIRED = false
34
+ LISTEN_ADDRESS = " 127.0.0.1"
35
+ }
36
+ }
37
+
26
38
data "coder_workspace" "me" {}
39
+ data "coder_workspace_owner" "me" {}
27
40
28
41
resource "coder_app" "pgadmin" {
29
42
count = data. coder_workspace . me . start_count
30
43
agent_id = var. agent_id
31
44
display_name = " pgAdmin"
32
45
slug = " pgadmin"
33
46
icon = " /icon/postgres.svg"
34
- url = var. subdomain ? " https://pgadmin-${ data . coder_workspace . me . id } .${ data . coder_workspace . me . access_url } " : " http://localhost:${ var . port } "
47
+ url = local. url
48
+ subdomain = var. subdomain
35
49
share = " owner"
50
+
51
+ healthcheck {
52
+ url = local. healthcheck_url
53
+ interval = 5
54
+ threshold = 6
55
+ }
36
56
}
37
57
38
58
resource "coder_script" "pgadmin" {
@@ -41,7 +61,48 @@ resource "coder_script" "pgadmin" {
41
61
icon = " /icon/postgres.svg"
42
62
run_on_start = true
43
63
script = templatefile (" ${ path . module } /run.sh" , {
44
- PORT = var.port,
45
- LOG_PATH = " /tmp/pgadmin.log"
64
+ PORT = var.port,
65
+ LOG_PATH = " /tmp/pgadmin.log" ,
66
+ SERVER_BASE_PATH = local.server_base_path,
67
+ CONFIG = local.config_content,
68
+ PGADMIN_DATA_DIR = local.pgadmin_data_dir,
69
+ PGADMIN_LOG_DIR = local.pgadmin_log_dir,
70
+ PGADMIN_VENV_DIR = local.pgadmin_venv_dir
46
71
})
72
+ }
73
+
74
+ locals {
75
+ server_base_path = var. subdomain ? " " : format (" /@%s/%s/apps/%s" , data. coder_workspace_owner . me . name , data. coder_workspace . me . name , " pgadmin" )
76
+ url = " http://localhost:${ var . port } ${ local . server_base_path } "
77
+ healthcheck_url = " http://localhost:${ var . port } ${ local . server_base_path } /"
78
+
79
+ # pgAdmin data directories (user-local paths)
80
+ pgadmin_data_dir = " $HOME/.pgadmin"
81
+ pgadmin_log_dir = " $HOME/.pgadmin/logs"
82
+ pgadmin_venv_dir = " $HOME/.pgadmin/venv"
83
+
84
+ base_config = merge (var. config , {
85
+ LISTEN_PORT = var.port
86
+ # Override paths for user installation
87
+ DATA_DIR = local.pgadmin_data_dir
88
+ LOG_FILE = " ${ local . pgadmin_log_dir } /pgadmin4.log"
89
+ SQLITE_PATH = " ${ local . pgadmin_data_dir } /pgadmin4.db"
90
+ SESSION_DB_PATH = " ${ local . pgadmin_data_dir } /sessions"
91
+ STORAGE_DIR = " ${ local . pgadmin_data_dir } /storage"
92
+ # Disable initial setup prompts for automated deployment
93
+ SETUP_AUTH = false
94
+ })
95
+
96
+ config_with_path = var. subdomain ? local. base_config : merge (local. base_config , {
97
+ APPLICATION_ROOT = local.server_base_path
98
+ })
99
+
100
+ config_content = join (" \n " , [
101
+ for key , value in local . config_with_path :
102
+ format (" %s = %s" , key,
103
+ can (regex (" ^(true|false)$" , tostring (value))) ? (value ? " True" : " False" ) :
104
+ can (tonumber (value)) ? tostring (value) :
105
+ format (" '%s'" , tostring (value))
106
+ )
107
+ ])
47
108
}
0 commit comments