-
Notifications
You must be signed in to change notification settings - Fork 0
/
mysql.tf
63 lines (48 loc) · 1.64 KB
/
mysql.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
# SQL instance
resource "google_sql_database_instance" "mysql" {
# The -## is because you cannot use the same name of
# a deleted database until one week after its deletion
name = "bookstack-00"
database_version = "MYSQL_8_0"
region = var.gcp.region
depends_on = [google_service_networking_connection.private_vpc_connection]
settings {
tier = "db-f1-micro"
ip_configuration {
ipv4_enabled = false
private_network = data.google_compute_network.default.id
}
}
}
# Private connection for SQL instance
resource "google_compute_global_address" "private_ip_address" {
name = "bookstack-sql-private-ip-address"
purpose = "VPC_PEERING"
address_type = "INTERNAL"
prefix_length = 16
network = data.google_compute_network.default.self_link
}
resource "google_service_networking_connection" "private_vpc_connection" {
network = data.google_compute_network.default.name
service = "servicenetworking.googleapis.com"
reserved_peering_ranges = [google_compute_global_address.private_ip_address.name]
}
# Database
resource "google_sql_database" "database" {
name = var.database
instance = google_sql_database_instance.mysql.name
}
# SQL User
resource "google_sql_user" "bookstack" {
instance = google_sql_database_instance.mysql.name
name = random_string.bookstack_sql_user_name.result
password = random_password.bookstack_sql_user_password.result
}
resource "random_string" "bookstack_sql_user_name" {
length = 12
special = false
}
resource "random_password" "bookstack_sql_user_password" {
length = 16
special = true
}