-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlocals.tf
88 lines (75 loc) · 2.17 KB
/
locals.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
locals {
network_id = var.network_params.network_id
project = var.network_params.project
postfix = var.network_params.postfix
volume_exchange = var.volume_exchange
host = "mysql-${var.network_params.postfix}"
port = "3306"
user = "${var.network_params.project}${var.network_params.postfix}"
password = random_string.password.result
root_password = random_string.root_password.result
database = "${var.network_params.project}${var.network_params.postfix}"
}
locals {
env = [
"MYSQL_ROOT_PASSWORD=${local.root_password}",
"MYSQL_DATABASE=${local.database}",
"MYSQL_USER=${local.user}",
"MYSQL_PASSWORD=${local.password}",
]
init_exporter_sql = join("\n",[
"GRANT PROCESS, REPLICATION CLIENT, SELECT ON *.* TO '${local.user}'@'%';"
])
init_sql = join("\n", [for d in var.databases :
"CREATE DATABASE IF NOT EXISTS ${d};\nGRANT ALL PRIVILEGES ON ${d}.* TO '${local.user}'@'%';\n"
])
command = [
"mysqld",
"--character-set-server=utf8mb4",
"--secure_file_priv=/exchange",
"--collation-server=utf8mb4_unicode_ci",
// "--default-authentication-plugin=mysql_native_password",
"--sql_mode=${var.sql_mode}"
]
upload = [{
content = join("\n", concat([ local.init_sql, "\n", local.init_exporter_sql ]))
file = "/docker-entrypoint-initdb.d/init.sql"
}]
mounted_exchange = {
source = local.volume_exchange
target = "/exchange"
}
mounts = var.disabled > 0 || var.mounted == "" ? [] : [
{
source = var.mounted
target = "/var/lib/mysql"
}
]
volumes = var.disabled > 0 || local.mounts != [] ? [] : [{
container_path = "/var/lib/mysql"
volume_name = docker_volume.storage[0].name
}]
ports = var.open_ports ? [{
internal = 3306
external = 3306
}] : []
credentials = {for d in var.databases:
d => {
database = d
host = local.host
port = local.port
user = local.user
password = local.password
}
}
labels = concat(var.network_params.labels, [
{
label = "host",
value = local.host
},
{
label = "role"
value = "mysql"
}
])
}