-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpostgres.tf
155 lines (148 loc) · 3.32 KB
/
postgres.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
resource "docker_service" "postgres" {
name = "postgres_db"
labels {
label = "com.docker.stack.namespace"
value = local.stack_namespaces.postgres
}
task_spec {
container_spec {
labels {
label = "com.docker.stack.namespace"
value = local.stack_namespaces.postgres
}
image = "postgres:16"
args = [
"-c",
"max_connections=500",
# "log_statement=all",
]
env = {
POSTGRES_DB = var.default_user,
POSTGRES_USER = var.default_user,
POSTGRES_PASSWORD = var.postgres_password,
}
mounts {
target = "/var/lib/postgresql/data"
source = docker_volume.postgres_data.id
type = "volume"
}
}
networks_advanced {
name = docker_network.postgres.id
}
placement {
constraints = [
"node.labels.db == true"
]
}
}
lifecycle {
ignore_changes = [
task_spec[0].container_spec[0].image,
]
}
}
resource "docker_service" "postgres_exporter" {
name = "postgres_exporter"
labels {
label = "com.docker.stack.namespace"
value = local.stack_namespaces.postgres
}
labels {
label = "prometheus-job"
value = "postgres"
}
labels {
label = "prometheus-job-port"
value = "9187"
}
task_spec {
container_spec {
labels {
label = "com.docker.stack.namespace"
value = local.stack_namespaces.postgres
}
image = "quay.io/prometheuscommunity/postgres-exporter:latest"
env = {
DATA_SOURCE_URI = "postgres_db/postgres?sslmode=disable",
DATA_SOURCE_USER = var.default_user,
DATA_SOURCE_PASS = var.default_user,
}
}
networks_advanced {
name = docker_network.postgres.id
}
networks_advanced {
name = docker_network.prometheus.id
}
placement {
constraints = [
"node.labels.db == true"
]
}
}
lifecycle {
ignore_changes = [
task_spec[0].container_spec[0].image,
]
}
}
resource "docker_service" "pgadmin" {
name = "pga_app"
labels {
label = "com.docker.stack.namespace"
value = local.stack_namespaces.pgadmin
}
labels {
label = "traefik.enable"
value = "true"
}
labels {
label = "traefik.http.routers.pgadmin.entrypoints"
value = "websecure"
}
labels {
label = "traefik.http.services.pgadmin.loadbalancer.server.port"
value = "80"
}
task_spec {
container_spec {
labels {
label = "com.docker.stack.namespace"
value = local.stack_namespaces.pgadmin
}
image = "dpage/pgadmin4:latest"
env = {
PGADMIN_DEFAULT_EMAIL = var.default_email,
PGADMIN_DEFAULT_PASSWORD = var.default_pgadmin_password,
}
mounts {
target = "/var/lib/pgadmin"
source = docker_volume.pgadmin_data.id
type = "volume"
}
}
networks_advanced {
name = docker_network.postgres.id
}
networks_advanced {
name = docker_network.traefik.id
}
placement {
constraints = [
"node.labels.manager == true"
]
}
}
lifecycle {
ignore_changes = [
task_spec[0].container_spec[0].image,
]
}
}
resource "docker_volume" "postgres_data" {
name = "postgres_data"
}
resource "docker_volume" "pgadmin_data" {
name = "pgadmin_data"
}